Compare commits

...

4 Commits

Author SHA1 Message Date
99b303958a Merge pull request 'Implementation of credentials in the twitch script' (#3) from credentials-class-for-twitch-script into credentials-class-idea
Reviewed-on: #3
2020-09-23 06:51:47 +00:00
Alex Orid
dd4b42803b Added seasoning onto main()
Added some extra spice to main() for later usage.
2020-09-23 02:45:24 -04:00
Alex Orid
928ec6e935 Cleaning up code
Renamed the Twitch Script

Got rid of unneeded files.
2020-09-23 02:35:00 -04:00
Alex Orid
85909ecad9 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.
2020-09-23 01:48:03 -04:00
6 changed files with 51 additions and 44 deletions

View File

@ -1,3 +1,8 @@
{ {
"username": "",
"password": "",
"ipAddress": "",
"port": "",
"databaseName": "",
"engine": "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" "engine": "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"
} }

View File

@ -34,14 +34,14 @@ class Discord_Credential():
class DB_Credential(): class DB_Credential():
# engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" # engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"
def __init__(self): def __init__(self, username, password, ipAddress, port, databaseName, engine_url):
super().__init__() #super().__init__()
self.username = "" self.username = username
self.password = "" self.password = password
self.ipAddress = "" self.ipAddress = ipAddress
self.port = "" self.port = port
self.databaseName = "" self.databaseName = databaseName
self.engine_url = "" self.engine_url = engine_url
def create_engine_url(self): def create_engine_url(self):
new_engine_url = "mysql+mysqlconnector://" + self.username + ":" + self.password + "@" + self.ipAddress + ":" + self.port + "/" + self.databaseName 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(): class Credentials_Module():
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.Twitch_Credentials_List: list self.Twitch_Credentials_List: list = []
self.Discord_Credentials_List: list self.Discord_Credentials_List: list = []
self.DB_Credentials_List: list self.DB_Credentials_List: list = []
def load_credentials(self): def load_credentials(self):
fileList = self.list_credential_files() fileList = self.list_credential_files()
@ -61,18 +61,15 @@ class Credentials_Module():
if file.lower().find("twitch") != -1: if file.lower().find("twitch") != -1:
credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential) credential_loading_function = self.credentialLoadingFunctions.get(Credential.Twitch_Credential)
output = credential_loading_function(self, file) 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: if file.lower().find("discord") != -1:
credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential) credential_loading_function = self.credentialLoadingFunctions.get(Credential.Discord_Credential)
output = credential_loading_function(self, file) 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: if file.lower().find("db") != -1:
credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential) credential_loading_function = self.credentialLoadingFunctions.get(Credential.DB_Credential)
output = credential_loading_function(self, file) 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): def list_credential_files(self):
credentialPath = self.get_credentials_dir() credentialPath = self.get_credentials_dir()

View File

@ -1 +0,0 @@
engine_url = "mysql+mysqlconnector://"

29
main.py
View File

@ -4,21 +4,36 @@
import sys import sys
import time import time
import twitch_script_class import twitch_script
import utilities_script as utility import utilities_script as utility
twitch_chat: twitch_script_class.Twitch_Module import credentials
twitch_chat: twitch_script.Twitch_Module
credentials_manager: credentials.Credentials_Module
def main(): def main():
print("Connecting to Channels...")
global twitch_chat global twitch_chat
twitch_chat = twitch_script_class.Twitch_Module() global credentials_manager
print("Loading credentials...")
credentials_manager = credentials.Credentials_Module()
credentials_manager.load_credentials()
twitch_chat = twitch_script.Twitch_Module()
twitch_chat.join_channel("thecuriousnerd") if credentials_manager.Twitch_Credentials_List is not None:
# twitch_chat.send_message("activated") for cert in credentials_manager.Twitch_Credentials_List:
if cert.username == "praxis_bot":
print("Twitch Certificate Found: {" + cert.username + "}")
mainCert = cert
print("Loading Credential: {" + cert.username + "} into Twitch_Module")
twitch_chat.twitchCredential = mainCert
print("Connecting to Channel: " + "thecuriousnerd")
twitch_chat.join_channel(None, "thecuriousnerd")
#twitch_chat.send_message("activated")
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -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/

View File

@ -5,14 +5,15 @@ import twitch
import twitch.chat import twitch.chat
import config as config import config as config
import db #import db
import tts import tts
import twitch_cred as twitch_credentials
import credentials
class Twitch_Module(): class Twitch_Module():
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.twitchCredential: credentials.Twitch_Credential
self.chat: twitch.Chat self.chat: twitch.Chat
self.tts_enabled: bool = False self.tts_enabled: bool = False
self.tts_whitelist_enabled: bool = False self.tts_whitelist_enabled: bool = False
@ -22,14 +23,16 @@ class Twitch_Module():
self._urlMatcher = re.compile( 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))") "(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 channel_name = "#" + channel_name
if credential is None:
credential = self.twitchCredential
self.chat = twitch.Chat( self.chat = twitch.Chat(
channel=channel_name, channel = channel_name,
nickname=twitch_credentials.username, nickname = credential.username,
oauth=twitch_credentials.oauth, oauth = credential.oauth,
helix=twitch.Helix(twitch_credentials.helix, use_cache=True) helix = twitch.Helix(credential.helix, use_cache=True)
) )
self.chat.subscribe(self.twitch_chat) self.chat.subscribe(self.twitch_chat)