From 9f449a916cd286787a88329b366ad345fbdb59fa Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Mon, 21 Sep 2020 23:31:36 -0400 Subject: [PATCH 01/10] Credentials Class Idea --- .gitignore | 1 + credentials.py | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 credentials.py diff --git a/.gitignore b/.gitignore index 133f351..b7d5289 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ tts/ __pycache__/ +credentials/ diff --git a/credentials.py b/credentials.py new file mode 100644 index 0000000..7fbdc41 --- /dev/null +++ b/credentials.py @@ -0,0 +1,84 @@ +import os + +class Credentials_Module(): + def __init__(self): + super().__init__() + self.Twitch_Credentials_List:list + self.Discord_Credentials_List:list + self.DB_Credentials_List:list + + credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers + Credential.Twitch_Credential: load_Twitch_Credential, + Credential.Discord_Credential: load_Discord_Credential, + Credential.DB_Credential: load_DB_Credential + } + + def load_credentials(self): + credentialPath = self.get_credentials_dir() + fileList:list = [] + for file in fileList: + fileName = "" + if fileName.lower().find("twitch") != -1: + credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential) + output = credential_loading_function(fileName) + if fileName.lower().find("discord") != -1: + credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential) + output = credential_loading_function(fileName) + if fileName.lower().find("db") != -1: + credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential) + output = credential_loading_function(fileName) + + #Based on similar function in tts.py + def get_credentials_dir(self): + dir = os.path.join(os.getcwd(), "credentials") # this is platform-agnostic + if not os.path.exists(dir): + os.mkdir(dir) + return dir + + def load_Twitch_Credential(self, fileName:str): + pass + + def load_Discord_Credential(self, fileName:str): + pass + + def load_DB_Credential(self, fileName:str): + pass + + +class Credential(Enum): + Twitch_Credential = 1 + Discord_Credential = 2 + DB_Credential = 3 + +class Twitch_Credential(): + #Username = Twitch Username + #Helix ID = https://dev.twitch.tv/console/apps + #Oauth = https://twitchapps.com/tmi/ + #V5 Client ID = https://twitchtokengenerator.com/ + def __init__(self): + super().__init__() + username = "" + helix = "" + oauth = "oauth:" + v5_Client = "" + +class Discord_Credential(): + #Discord Credentials explanations here. + def __init__(self): + super().__init__() + username = "" + +class DB_Credential(): + #engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" + def __init__(self): + super().__init__() + self.username = "" + self.password = "" + self.ipAddress = "" + self.port = "" + self.databaseName = "" + self.engine_url = "" + + def create_engine_url(self): + new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName + self.engine_url = new_engine_url From c2113116cd0776d9fae87a40b63683d97e9b1c50 Mon Sep 17 00:00:00 2001 From: dtookey Date: Tue, 22 Sep 2020 01:38:35 -0400 Subject: [PATCH 02/10] implemented quick and easy way for storing credentials in json files. Most of the stuff in here is template ideas, season them to taste for yourself added .idea to .gitignore --- .gitignore | 2 +- .../credential_template_discord.json | 6 + .../credential_template_twitch.json | 6 + credentials.py | 146 +++++++++++------- tests/test_twitch_script_class.py | 2 +- 5 files changed, 101 insertions(+), 61 deletions(-) create mode 100644 credential_templates/credential_template_discord.json create mode 100644 credential_templates/credential_template_twitch.json diff --git a/.gitignore b/.gitignore index b7d5289..4e8cfbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ - tts/ __pycache__/ credentials/ +.idea/ diff --git a/credential_templates/credential_template_discord.json b/credential_templates/credential_template_discord.json new file mode 100644 index 0000000..68038f9 --- /dev/null +++ b/credential_templates/credential_template_discord.json @@ -0,0 +1,6 @@ +{ + "username": "discord", + "helix": "secret discord", + "oauth": "token discord", + "v5_client": "I have no idea here" +} \ No newline at end of file diff --git a/credential_templates/credential_template_twitch.json b/credential_templates/credential_template_twitch.json new file mode 100644 index 0000000..5f5b4a1 --- /dev/null +++ b/credential_templates/credential_template_twitch.json @@ -0,0 +1,6 @@ +{ + "username": "something", + "helix": "secret", + "oauth": "token", + "v5_client": "I have no idea here" +} \ No newline at end of file diff --git a/credentials.py b/credentials.py index 7fbdc41..612994a 100644 --- a/credentials.py +++ b/credentials.py @@ -1,48 +1,6 @@ +import json import os - -class Credentials_Module(): - def __init__(self): - super().__init__() - self.Twitch_Credentials_List:list - self.Discord_Credentials_List:list - self.DB_Credentials_List:list - - credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers - Credential.Twitch_Credential: load_Twitch_Credential, - Credential.Discord_Credential: load_Discord_Credential, - Credential.DB_Credential: load_DB_Credential - } - - def load_credentials(self): - credentialPath = self.get_credentials_dir() - fileList:list = [] - for file in fileList: - fileName = "" - if fileName.lower().find("twitch") != -1: - credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential) - output = credential_loading_function(fileName) - if fileName.lower().find("discord") != -1: - credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential) - output = credential_loading_function(fileName) - if fileName.lower().find("db") != -1: - credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential) - output = credential_loading_function(fileName) - - #Based on similar function in tts.py - def get_credentials_dir(self): - dir = os.path.join(os.getcwd(), "credentials") # this is platform-agnostic - if not os.path.exists(dir): - os.mkdir(dir) - return dir - - def load_Twitch_Credential(self, fileName:str): - pass - - def load_Discord_Credential(self, fileName:str): - pass - - def load_DB_Credential(self, fileName:str): - pass +from enum import Enum class Credential(Enum): @@ -50,26 +8,32 @@ class Credential(Enum): Discord_Credential = 2 DB_Credential = 3 + class Twitch_Credential(): - #Username = Twitch Username - #Helix ID = https://dev.twitch.tv/console/apps - #Oauth = https://twitchapps.com/tmi/ - #V5 Client ID = https://twitchtokengenerator.com/ - def __init__(self): - super().__init__() - username = "" - helix = "" - oauth = "oauth:" - v5_Client = "" + # Username = Twitch Username + # Helix ID = https://dev.twitch.tv/console/apps + # Oauth = https://twitchapps.com/tmi/ + # V5 Client ID = https://twitchtokengenerator.com/ + def __init__(self, username, helix, oauth, v5_client): + # super().__init__() + self.username = username + self.helix = helix + self.oauth = oauth + self.v5_client = v5_client + class Discord_Credential(): - #Discord Credentials explanations here. - def __init__(self): - super().__init__() - username = "" + # Discord Credentials explanations here. + def __init__(self, username, helix, oauth, v5_client): + # super().__init__() + # all of this is completely made up, i just wanted to make sure your file name switch worked right + self.username = username + self.helix = helix + self.oauth = oauth + self.v5_client = v5_client class DB_Credential(): - #engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" + # engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" def __init__(self): super().__init__() self.username = "" @@ -82,3 +46,67 @@ class DB_Credential(): def create_engine_url(self): new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName self.engine_url = new_engine_url + + +class Credentials_Module(): + def __init__(self): + super().__init__() + self.Twitch_Credentials_List: list + self.Discord_Credentials_List: list + self.DB_Credentials_List: list + + def load_credentials(self): + fileList = self.list_credential_files() + for file in fileList: + if file.lower().find("twitch") != -1: + credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential) + output = credential_loading_function(self, file) + if file.lower().find("discord") != -1: + credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential) + output = credential_loading_function(self, file) + if file.lower().find("db") != -1: + credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential) + output = credential_loading_function(self, file) + + def list_credential_files(self): + credentialPath = self.get_credentials_dir() + fileList: list = [] + for dirName, subdirList, fileList in os.walk(credentialPath): + break + return fileList + + # Based on similar function in tts.py + def get_credentials_dir(self): + dir = os.path.join(os.getcwd(), "credentials") # this is platform-agnostic + if not os.path.exists(dir): + os.mkdir(dir) + return dir + + def load_Twitch_Credential(self, fileName: str): + file_path = os.path.join(self.get_credentials_dir(), fileName) + f = open(file_path) + raw_json = json.loads(f.read()) + tobj = Twitch_Credential(**raw_json) + return tobj + + def load_Discord_Credential(self, fileName: str): + file_path = os.path.join(self.get_credentials_dir(), fileName) + f = open(file_path) + raw_json = json.loads(f.read()) + tobj = Discord_Credential(**raw_json) + return tobj + + def load_DB_Credential(self, fileName: str): + return None + + credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers + Credential.Twitch_Credential: load_Twitch_Credential, + Credential.Discord_Credential: load_Discord_Credential, + Credential.DB_Credential: load_DB_Credential + + } + + +if __name__ == '__main__': + creds = Credentials_Module() + creds.load_credentials() diff --git a/tests/test_twitch_script_class.py b/tests/test_twitch_script_class.py index 63a6f52..76b6121 100644 --- a/tests/test_twitch_script_class.py +++ b/tests/test_twitch_script_class.py @@ -4,7 +4,7 @@ import twitch testValidUrls = ['https://shady.ru', 'http://stolencards.zn', 'https://i.imgur.com/FL6slHd.jpg'] -testInvalidUrls = ['this is just a sentence. With a period', 'gotta have some other stuff', 'bad punctuation.does not produces false positives'] +testInvalidUrls = ['this is just a sentence. With a period', 'gotta have some other stuff', 'bad punctuation. does produces false positives'] class TwitchBotTest(unittest.TestCase): From 7d0520b0b0de37e5d1d7d902bdbfe6ff350fbf52 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 22 Sep 2020 18:20:56 -0400 Subject: [PATCH 03/10] Added the DB Credential Template --- README.md | 12 ++++++++---- credential_templates/credential_template_db.json | 3 +++ credential_templates/credential_template_twitch.json | 4 ++-- credentials.py | 6 +++++- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 credential_templates/credential_template_db.json diff --git a/README.md b/README.md index cd51c6b..e45dfc0 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,19 @@ A chatbot to help with live stream production/effects. +___ + # Credentials Setup: -## For Twitch Credentials in twitch_cred.py +Create a json based on the templates and put them into the credentials folder. + +## For Twitch Credentials Username = `TwitchUsername` -Helix ID = `https://dev.twitch.tv/console/apps` +Helix Client ID = `https://dev.twitch.tv/console/apps` Oauth = `https://twitchapps.com/tmi/` V5 Client ID = `https://twitchtokengenerator.com/` -## For Database Credentials in db_cred.py -engine = `"mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"` +## For Database Credentials +Engine = `"mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"` diff --git a/credential_templates/credential_template_db.json b/credential_templates/credential_template_db.json new file mode 100644 index 0000000..f94408c --- /dev/null +++ b/credential_templates/credential_template_db.json @@ -0,0 +1,3 @@ +{ + "engine": "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" +} \ No newline at end of file diff --git a/credential_templates/credential_template_twitch.json b/credential_templates/credential_template_twitch.json index 5f5b4a1..c889bf2 100644 --- a/credential_templates/credential_template_twitch.json +++ b/credential_templates/credential_template_twitch.json @@ -1,6 +1,6 @@ { "username": "something", - "helix": "secret", + "helix": "Helix Client ID", "oauth": "token", - "v5_client": "I have no idea here" + "v5_client": "Client ID" } \ No newline at end of file diff --git a/credentials.py b/credentials.py index 612994a..566a6a7 100644 --- a/credentials.py +++ b/credentials.py @@ -97,7 +97,11 @@ class Credentials_Module(): return tobj def load_DB_Credential(self, fileName: str): - return None + file_path = os.path.join(self.get_credentials_dir(), fileName) + f = open(file_path) + raw_json = json.loads(f.read()) + tobj = DB_Credential(**raw_json) + return tobj credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers Credential.Twitch_Credential: load_Twitch_Credential, From d773d8b8da60b139236a50ba38a3797978f6bddc Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 22 Sep 2020 18:26:04 -0400 Subject: [PATCH 04/10] Modified load_credentials() Made the load_credentials function add credentials to the credential lists. --- credentials.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/credentials.py b/credentials.py index 566a6a7..b323128 100644 --- a/credentials.py +++ b/credentials.py @@ -61,12 +61,18 @@ class Credentials_Module(): if file.lower().find("twitch") != -1: credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential) output = credential_loading_function(self, file) + if output is not None: + self.Twitch_Credentials_List.append(output) if file.lower().find("discord") != -1: credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential) output = credential_loading_function(self, file) + if output is not None: + self.Discord_Credentials_List.append(output) if file.lower().find("db") != -1: credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential) output = credential_loading_function(self, file) + if output is not None: + self.DB_Credentials_List.append(output) def list_credential_files(self): credentialPath = self.get_credentials_dir() From 85909ecad91839060c76c52b41d419c0328dcead Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 23 Sep 2020 01:48:03 -0400 Subject: [PATCH 05/10] Twitch Script Credentials Integration Updated the template for database credentials. Added the credentials module to the twitch script. Modified the main.py to join my channel if it detects a specific credential. --- .../credential_template_db.json | 5 +++ credentials.py | 31 +++++++++---------- main.py | 23 +++++++++++--- twitch_script_class.py | 14 ++++++--- 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/credential_templates/credential_template_db.json b/credential_templates/credential_template_db.json index f94408c..3e25cc8 100644 --- a/credential_templates/credential_template_db.json +++ b/credential_templates/credential_template_db.json @@ -1,3 +1,8 @@ { + "username": "", + "password": "", + "ipAddress": "", + "port": "", + "databaseName": "", "engine": "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" } \ No newline at end of file diff --git a/credentials.py b/credentials.py index b323128..9e7017e 100644 --- a/credentials.py +++ b/credentials.py @@ -34,14 +34,14 @@ class Discord_Credential(): class DB_Credential(): # engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" - def __init__(self): - super().__init__() - self.username = "" - self.password = "" - self.ipAddress = "" - self.port = "" - self.databaseName = "" - self.engine_url = "" + def __init__(self, username, password, ipAddress, port, databaseName, engine_url): + #super().__init__() + self.username = username + self.password = password + self.ipAddress = ipAddress + self.port = port + self.databaseName = databaseName + self.engine_url = engine_url def create_engine_url(self): new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName @@ -51,9 +51,9 @@ class DB_Credential(): class Credentials_Module(): def __init__(self): super().__init__() - self.Twitch_Credentials_List: list - self.Discord_Credentials_List: list - self.DB_Credentials_List: list + self.Twitch_Credentials_List: list = [] + self.Discord_Credentials_List: list = [] + self.DB_Credentials_List: list = [] def load_credentials(self): fileList = self.list_credential_files() @@ -61,18 +61,15 @@ class Credentials_Module(): if file.lower().find("twitch") != -1: credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential) output = credential_loading_function(self, file) - if output is not None: - self.Twitch_Credentials_List.append(output) + self.Twitch_Credentials_List.append(output) if file.lower().find("discord") != -1: credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential) output = credential_loading_function(self, file) - if output is not None: - self.Discord_Credentials_List.append(output) + self.Discord_Credentials_List.append(output) if file.lower().find("db") != -1: credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential) output = credential_loading_function(self, file) - if output is not None: - self.DB_Credentials_List.append(output) + self.DB_Credentials_List.append(output) def list_credential_files(self): credentialPath = self.get_credentials_dir() diff --git a/main.py b/main.py index 173bb9f..43dc7b4 100644 --- a/main.py +++ b/main.py @@ -8,16 +8,31 @@ import twitch_script_class import utilities_script as utility -twitch_chat: twitch_script_class.Twitch_Module +import credentials +twitch_chat: twitch_script_class.Twitch_Module +credentials_manager: credentials.Credentials_Module def main(): - print("Connecting to Channels...") - global twitch_chat + global credentials_manager + print("Loading credentials...") + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + twitch_chat = twitch_script_class.Twitch_Module() - twitch_chat.join_channel("thecuriousnerd") + mainCert: credentials.Twitch_Credential + if credentials_manager.Twitch_Credentials_List is not None: + for cert in credentials_manager.Twitch_Credentials_List: + if cert.username == "praxis_bot": + print("Twitch Certificate Found: " + cert.username) + mainCert = cert + twitch_chat.twitchCredential = cert + twitch_chat.join_channel(None, "thecuriousnerd") + + #print("Connecting to Channels...") + #twitch_chat.join_channel(cert, "thecuriousnerd") # twitch_chat.send_message("activated") diff --git a/twitch_script_class.py b/twitch_script_class.py index fe6cd5f..b6ffbca 100644 --- a/twitch_script_class.py +++ b/twitch_script_class.py @@ -9,10 +9,12 @@ import db import tts import twitch_cred as twitch_credentials +import credentials class Twitch_Module(): def __init__(self): super().__init__() + self.twitchCredential: credentials.Twitch_Credential self.chat: twitch.Chat self.tts_enabled: bool = False self.tts_whitelist_enabled: bool = False @@ -22,14 +24,16 @@ class Twitch_Module(): self._urlMatcher = re.compile( "(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))") - def join_channel(self, channel_name): + def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str): channel_name = "#" + channel_name + if credential is None: + credential = self.twitchCredential self.chat = twitch.Chat( - channel=channel_name, - nickname=twitch_credentials.username, - oauth=twitch_credentials.oauth, - helix=twitch.Helix(twitch_credentials.helix, use_cache=True) + channel = channel_name, + nickname = credential.username, + oauth = credential.oauth, + helix = twitch.Helix(credential.helix, use_cache=True) ) self.chat.subscribe(self.twitch_chat) From 928ec6e9359f3b072e86a1eaef738cebaf0b4c2e Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 23 Sep 2020 02:35:00 -0400 Subject: [PATCH 06/10] Cleaning up code Renamed the Twitch Script Got rid of unneeded files. --- db_cred.py | 1 - main.py | 6 +++--- twitch_cred.py | 12 ------------ twitch_script_class.py => twitch_script.py | 3 +-- 4 files changed, 4 insertions(+), 18 deletions(-) delete mode 100644 db_cred.py delete mode 100644 twitch_cred.py rename twitch_script_class.py => twitch_script.py (99%) diff --git a/db_cred.py b/db_cred.py deleted file mode 100644 index 13fc233..0000000 --- a/db_cred.py +++ /dev/null @@ -1 +0,0 @@ -engine_url = "mysql+mysqlconnector://" diff --git a/main.py b/main.py index 43dc7b4..c7f2b1e 100644 --- a/main.py +++ b/main.py @@ -4,13 +4,13 @@ import sys import time -import twitch_script_class +import twitch_script import utilities_script as utility import credentials -twitch_chat: twitch_script_class.Twitch_Module +twitch_chat: twitch_script.Twitch_Module credentials_manager: credentials.Credentials_Module def main(): @@ -20,7 +20,7 @@ def main(): credentials_manager = credentials.Credentials_Module() credentials_manager.load_credentials() - twitch_chat = twitch_script_class.Twitch_Module() + twitch_chat = twitch_script.Twitch_Module() mainCert: credentials.Twitch_Credential if credentials_manager.Twitch_Credentials_List is not None: diff --git a/twitch_cred.py b/twitch_cred.py deleted file mode 100644 index e5dd8d4..0000000 --- a/twitch_cred.py +++ /dev/null @@ -1,12 +0,0 @@ -# So I'm a little conflicted here. My nit-picky self says that this should be a class you have to instantiate rather -# than static variables... I'll leave this alone for now, but you may wish to refactor this in future - -username = "" -helix = "" -oauth = "oauth:" -v5_Client = "" - -#Username = Twitch Username -#Helix ID https://dev.twitch.tv/console/apps -#Oauth https://twitchapps.com/tmi/ -#V5 Client ID https://twitchtokengenerator.com/ diff --git a/twitch_script_class.py b/twitch_script.py similarity index 99% rename from twitch_script_class.py rename to twitch_script.py index b6ffbca..a25189b 100644 --- a/twitch_script_class.py +++ b/twitch_script.py @@ -5,9 +5,8 @@ import twitch import twitch.chat import config as config -import db +#import db import tts -import twitch_cred as twitch_credentials import credentials From dd4b42803b7c102adbfe0a1f98704c728f14a232 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 23 Sep 2020 02:45:24 -0400 Subject: [PATCH 07/10] Added seasoning onto main() Added some extra spice to main() for later usage. --- main.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index c7f2b1e..62e4179 100644 --- a/main.py +++ b/main.py @@ -22,18 +22,18 @@ def main(): twitch_chat = twitch_script.Twitch_Module() - mainCert: credentials.Twitch_Credential if credentials_manager.Twitch_Credentials_List is not None: for cert in credentials_manager.Twitch_Credentials_List: if cert.username == "praxis_bot": - print("Twitch Certificate Found: " + cert.username) + print("Twitch Certificate Found: {" + cert.username + "}") mainCert = cert - twitch_chat.twitchCredential = cert + + print("Loading Credential: {" + cert.username + "} into Twitch_Module") + twitch_chat.twitchCredential = mainCert + print("Connecting to Channel: " + "thecuriousnerd") twitch_chat.join_channel(None, "thecuriousnerd") - #print("Connecting to Channels...") - #twitch_chat.join_channel(cert, "thecuriousnerd") - # twitch_chat.send_message("activated") + #twitch_chat.send_message("activated") if __name__ == "__main__": From ff4c21a74715177615c0ff078868804bd8767f8b Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 23 Sep 2020 03:03:18 -0400 Subject: [PATCH 08/10] Updated Readme --- README.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e45dfc0..9406164 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,15 @@ -A chatbot to help with live stream production/effects. +A chatbot to help with live stream production and effects. ___ -# Credentials Setup: +# Credentials: -Create a json based on the templates and put them into the credentials folder. +## Credentials Setup: -## For Twitch Credentials +Create a json based on the templates and put them into the `/credentials/` folder. +Refer to the `/credential_templates/` folder for examples. + +### For Twitch Credentials Username = `TwitchUsername` Helix Client ID = `https://dev.twitch.tv/console/apps` @@ -15,5 +18,12 @@ Oauth = `https://twitchapps.com/tmi/` V5 Client ID = `https://twitchtokengenerator.com/` -## For Database Credentials +### For Database Credentials Engine = `"mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"` + +## Credential Usage: + +Place json credentials in the `/credentials/` folder. +To load them, run `load_credentials()` from `Credentials_Module` in the `credentials.py` script. + +___ \ No newline at end of file From ada9d2ecb86e3f6f4612bfbe59caf45086617336 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 23 Sep 2020 15:01:15 -0400 Subject: [PATCH 09/10] Added DB Module to the Twitch Module Expanded main() a little to add DB_Module to the Twitch_Module. Added a db_manager to the Twitch_Module class. Added the nickname string to the db credential. --- .../credential_template_db.json | 1 + credentials.py | 7 ++++++- db.py | 20 +++++++++++++++---- main.py | 15 +++++++++++--- twitch_script.py | 6 +++++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/credential_templates/credential_template_db.json b/credential_templates/credential_template_db.json index 3e25cc8..5500814 100644 --- a/credential_templates/credential_template_db.json +++ b/credential_templates/credential_template_db.json @@ -1,4 +1,5 @@ { + "nickname": "AnythingYouWant", "username": "", "password": "", "ipAddress": "", diff --git a/credentials.py b/credentials.py index 9e7017e..07b28c7 100644 --- a/credentials.py +++ b/credentials.py @@ -34,8 +34,9 @@ class Discord_Credential(): class DB_Credential(): # engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" - def __init__(self, username, password, ipAddress, port, databaseName, engine_url): + def __init__(self, nickname, username, password, ipAddress, port, databaseName, engine_url): #super().__init__() + self.nickname = nickname self.username = username self.password = password self.ipAddress = ipAddress @@ -46,6 +47,7 @@ class DB_Credential(): def create_engine_url(self): new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName self.engine_url = new_engine_url + return new_engine_url class Credentials_Module(): @@ -106,6 +108,9 @@ class Credentials_Module(): tobj = DB_Credential(**raw_json) return tobj + def find_Credential(self): + pass + credentialLoadingFunctions = { # this is a mapping of the Credential enum to function pointers Credential.Twitch_Credential: load_Twitch_Credential, Credential.Discord_Credential: load_Discord_Credential, diff --git a/db.py b/db.py index 253afb1..f4fe217 100644 --- a/db.py +++ b/db.py @@ -1,4 +1,6 @@ -import db_cred as db_credentials +import credentials + +import config as config import pandas as pd from sqlalchemy import create_engine @@ -7,12 +9,22 @@ from sqlalchemy import create_engine class db_module(): def __init__(self): super().__init__() + self.dbCredential: credentials.DB_Credential self.currentWorkingDB: str self.engine = None - def setup_engine(self): - self.engine = create_engine(db_credentials.engine_url) - print("Engine Created") + def setup_engine(self, credential: credentials.DB_Credential): + createEngine = True + if credential is None: + if self.dbCredential is None: + createEngine = False + else: + credential = self.dbCredential + + if createEngine: + self.engine = create_engine(credential.engine_url) + self.currentWorkingDB = credential.databaseName + print("Engine Created") def create_table(self, tableName: str = ""): pass diff --git a/main.py b/main.py index 62e4179..bda265c 100644 --- a/main.py +++ b/main.py @@ -22,18 +22,27 @@ def main(): twitch_chat = twitch_script.Twitch_Module() + dbCert: credentials.DB_Credential + if credentials_manager.DB_Credentials_List is not None: + for cert in credentials_manager.DB_Credentials_List: + if cert.nickname == "praxis_bot": + print("DB Certificate Found: {" + cert.nickname + "}") + dbCert = cert + + twitchCert: credentials.Twitch_Credential if credentials_manager.Twitch_Credentials_List is not None: for cert in credentials_manager.Twitch_Credentials_List: if cert.username == "praxis_bot": print("Twitch Certificate Found: {" + cert.username + "}") - mainCert = cert + twitchCert = cert + twitch_chat.db_manager.setup_engine(dbCert) print("Loading Credential: {" + cert.username + "} into Twitch_Module") - twitch_chat.twitchCredential = mainCert + twitch_chat.twitchCredential = twitchCert print("Connecting to Channel: " + "thecuriousnerd") twitch_chat.join_channel(None, "thecuriousnerd") - #twitch_chat.send_message("activated") + # twitch_chat.send_message("activated") if __name__ == "__main__": diff --git a/twitch_script.py b/twitch_script.py index a25189b..ccc5156 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -5,7 +5,7 @@ import twitch import twitch.chat import config as config -#import db +import db import tts import credentials @@ -14,7 +14,11 @@ class Twitch_Module(): def __init__(self): super().__init__() self.twitchCredential: credentials.Twitch_Credential + self.dbCredential: credentials.DB_Credential + + self.db_manager: db.db_module = db.db_module() self.chat: twitch.Chat + self.tts_enabled: bool = False self.tts_whitelist_enabled: bool = False self.links_allowed: bool = True From 8b90dc4ac77697c6795d492fcf116e762c4a7239 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 23 Sep 2020 15:13:24 -0400 Subject: [PATCH 10/10] Fixed gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 4e8cfbb..0b9935e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ + tts/ __pycache__/ credentials/ -.idea/ +.idea/ \ No newline at end of file