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)