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.
This commit is contained in:
parent
d773d8b8da
commit
85909ecad9
@ -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"
|
||||||
}
|
}
|
||||||
@ -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,17 +61,14 @@ 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):
|
||||||
|
|||||||
23
main.py
23
main.py
@ -8,16 +8,31 @@ import twitch_script_class
|
|||||||
|
|
||||||
import utilities_script as utility
|
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():
|
def main():
|
||||||
print("Connecting to Channels...")
|
|
||||||
|
|
||||||
global twitch_chat
|
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 = 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")
|
# twitch_chat.send_message("activated")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,10 +9,12 @@ import db
|
|||||||
import tts
|
import tts
|
||||||
import twitch_cred as twitch_credentials
|
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 +24,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)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user