From f0468e0630c6eda1cb044dee34155d7feab87b86 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 1 Oct 2020 04:33:59 -0400 Subject: [PATCH 01/26] Discord Module & Minor Fixes Started working on the discord script. Adjusted the if __name__ == "__main__": lines on a few modules. --- .../credential_template_discord.json | 6 ++-- credentials.py | 12 +++---- db.py | 10 ++++-- discord_script.py | 32 +++++++++++++++++++ twitch_script.py | 9 ++++-- 5 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 discord_script.py diff --git a/credential_templates/credential_template_discord.json b/credential_templates/credential_template_discord.json index 68038f9..51f9dc0 100644 --- a/credential_templates/credential_template_discord.json +++ b/credential_templates/credential_template_discord.json @@ -1,6 +1,4 @@ { - "username": "discord", - "helix": "secret discord", - "oauth": "token discord", - "v5_client": "I have no idea here" + "username": "AnythingYouWant", + "token": "" } \ No newline at end of file diff --git a/credentials.py b/credentials.py index 1e5c551..6bbd105 100644 --- a/credentials.py +++ b/credentials.py @@ -24,13 +24,11 @@ class Twitch_Credential(): class Discord_Credential(): # Discord Credentials explanations here. - def __init__(self, username, helix, oauth, v5_client): + def __init__(self, nickname, token): # 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 + self.nickname = nickname + self.token = token class DB_Credential(): # engine = "mysql+mysqlconnector://root:password@localhost:3306/DatabaseName" @@ -149,8 +147,8 @@ class Credentials_Module(): foundSomething = False tempCert: Discord_Credential for cert in self.Discord_Credentials_List: - if cert.username == searchParam: - print("Discord Credential Found: {" + cert.username + "}") + if cert.nickname == searchParam: + print("Discord Credential Found: {" + cert.nickname + "}") tempCert = cert foundSomething = True if foundSomething: diff --git a/db.py b/db.py index cb1aef3..2888f72 100644 --- a/db.py +++ b/db.py @@ -13,7 +13,7 @@ class db_module(): self.currentWorkingDB: str self.engine = None - def setup_engine(self, credential: credentials.DB_Credential): + def setup_engine(self, credential: credentials.DB_Credential = None): createEngine = True if credential is None: if self.dbCredential is None: @@ -69,5 +69,9 @@ class db_module(): if __name__ == "__main__": - db_connection = db_module() - db_connection.setup_engine() + testModule = db_module() + + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") + testModule.setup_engine() diff --git a/discord_script.py b/discord_script.py new file mode 100644 index 0000000..2dc66b9 --- /dev/null +++ b/discord_script.py @@ -0,0 +1,32 @@ +import random +import re + +import config as config +import db +import tts + +import credentials + +import discord + +class Discord_Module(discord.Client): + def __init__(self): + super().__init__() + self.dbCredential: credentials.DB_Credential + self.discordCredential: credentials.Discord_Credential + + self.tts_enabled: bool = False + + def main(self): + self.run(self.discordCredential.token) + + + +if __name__ == "__main__": + testModule = Discord_Module() + + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") + testModule.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") + testModule.main() diff --git a/twitch_script.py b/twitch_script.py index fa5f011..3c55d2e 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -197,5 +197,10 @@ def main_chat_commands_check(channel, sender, text): if __name__ == "__main__": - testChat = Twitch_Module() - testChat.join_channel("thecuriousnerd") + testModule = Twitch_Module() + + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + testModule.twitchCredential = credentials_manager.find_Twitch_Credential("praxis_bot") + testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") + testModule.join_channel(None ,"thecuriousnerd") \ No newline at end of file From 2559cd707687d2048f44a34c402badc071bf8d41 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 1 Oct 2020 04:35:35 -0400 Subject: [PATCH 02/26] Updated Requirements --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d052841..825bdb0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,4 +5,5 @@ SQLAlchemy pandas numpy gTTS -playsound \ No newline at end of file +playsound +discord \ No newline at end of file From fbd629a459ab08d364afb570f2308fd33ac283d7 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 2 Oct 2020 03:03:45 -0400 Subject: [PATCH 03/26] Successful Connection Was finally able to connect thanks to a thread. (Certificate Issue) Good Certificate found on: https://crt.sh/?id=2835394 Thread: https://github.com/Rapptz/discord.py/issues/4159 (Also fixed the requirements file) --- discord_script.py | 3 +++ requirements.txt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/discord_script.py b/discord_script.py index 2dc66b9..c170520 100644 --- a/discord_script.py +++ b/discord_script.py @@ -20,6 +20,9 @@ class Discord_Module(discord.Client): def main(self): self.run(self.discordCredential.token) + async def on_ready(self): + print('Logged on as', self.user) + if __name__ == "__main__": diff --git a/requirements.txt b/requirements.txt index 825bdb0..b90342e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,4 @@ pandas numpy gTTS playsound -discord \ No newline at end of file +discord.py \ No newline at end of file From 16e06f59fb06c7066791d0e4ebc2601fca1b76df Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 2 Oct 2020 03:35:49 -0400 Subject: [PATCH 04/26] Message Detection --- discord_script.py | 14 ++++++++++++++ main.py | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/discord_script.py b/discord_script.py index c170520..b0a79ac 100644 --- a/discord_script.py +++ b/discord_script.py @@ -1,6 +1,8 @@ import random import re +from discord import message + import config as config import db import tts @@ -8,6 +10,8 @@ import tts import credentials import discord +import discord.message +import discord.channel class Discord_Module(discord.Client): def __init__(self): @@ -19,10 +23,18 @@ class Discord_Module(discord.Client): def main(self): self.run(self.discordCredential.token) + async def on_ready(self): print('Logged on as', self.user) + async def on_message(self, message: discord.Message): + print("{ " + str(message.channel) + " }[" + message.author.display_name + "]: " + message.content) + #Message ID + print(str(message.id)) + #Channel ID + print(str(message.channel.id)) + if __name__ == "__main__": @@ -33,3 +45,5 @@ if __name__ == "__main__": testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") testModule.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") testModule.main() + + \ No newline at end of file diff --git a/main.py b/main.py index c30d5be..e5cd1a4 100644 --- a/main.py +++ b/main.py @@ -5,6 +5,7 @@ import sys import time import twitch_script +import discord_script import utilities_script as utility @@ -21,7 +22,9 @@ def main(): dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") - + discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") + + twitch_chat = twitch_script.Twitch_Module() twitch_chat.db_manager.setup_engine(dbCert) @@ -29,7 +32,14 @@ def main(): twitch_chat.join_channel(None, "thecuriousnerd") - # twitch_chat.send_message("activated") + discord_connection = discord_script.Discord_Module() + discord_connection.dbCredential = dbCert + discord_connection.discordCredential = discordCert + + discord_connection.main() + #Doesnt do stuff past this point + + twitch_chat.send_message("activated") if __name__ == "__main__": main() From 202b25ec26695d6ed3912ce8fa5a3b34a47e90d2 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 2 Oct 2020 03:41:35 -0400 Subject: [PATCH 05/26] Fixed Inconsistent Parts --- discord_script.py | 8 +++++--- main.py | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/discord_script.py b/discord_script.py index b0a79ac..eba8333 100644 --- a/discord_script.py +++ b/discord_script.py @@ -29,11 +29,13 @@ class Discord_Module(discord.Client): print('Logged on as', self.user) async def on_message(self, message: discord.Message): - print("{ " + str(message.channel) + " }[" + message.author.display_name + "]: " + message.content) + print("{" + message.guild.name + "}[ " + str(message.channel) + " ](" + message.author.display_name + ")> ") + print(message.content) #Message ID - print(str(message.id)) + #print(str(message.id)) #Channel ID - print(str(message.channel.id)) + #print(str(message.channel.id)) + diff --git a/main.py b/main.py index e5cd1a4..9491bb2 100644 --- a/main.py +++ b/main.py @@ -37,7 +37,7 @@ def main(): discord_connection.discordCredential = discordCert discord_connection.main() - #Doesnt do stuff past this point + #Doesn't do stuff past this point twitch_chat.send_message("activated") From 68ac5d76ee44a3a8b2d98d60004a6ace5861ef72 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Sat, 17 Oct 2020 03:36:54 -0400 Subject: [PATCH 06/26] Message Sending --- commands/implemented/command_roll_discord.py | 72 ++++++++++++++++++++ discord_script.py | 6 ++ 2 files changed, 78 insertions(+) create mode 100644 commands/implemented/command_roll_discord.py diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py new file mode 100644 index 0000000..b517b2d --- /dev/null +++ b/commands/implemented/command_roll_discord.py @@ -0,0 +1,72 @@ +from abc import ABCMeta + +from discord import message + +from commands.command_base import AbstractCommand + +import random + +import discord +import discord.message +import discord.channel + +class CommandRoll(AbstractCommand, metaclass=ABCMeta): + """ + this is the roll command. + """ + command = "!roll" + + def __init__(self): + super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD) + + def do_command(self, bot, discord_message: discord.Message): + print("!roll Detected") + #twitch_message.chat.send("test acknowledged") + + diceRoll: str = "" + discord_message.channel.send("Rolling Dice...") + print("Rolling Dice...") + + temp_preParsedMessage = discord_message.content.split("+") + + tempParsedMessage = temp_preParsedMessage[0].split(" ") + temp_dice_stmt: str = tempParsedMessage[1] + parsedMessage = temp_dice_stmt.lower().split("d") + + loopBool: bool = False + if parsedMessage[0] != "": + loopBool = True + if loopBool == True: + if int(parsedMessage[0]) == 1: + loopBool = False + + # If roll is in xdx+x format + if loopBool == True: + rolls: list = [] + for x in range(int(parsedMessage[0])): + rolls.append(random.randint(1, int(parsedMessage[1]))) + + rollTotal = 0 + for roll in rolls: + rollTotal = rollTotal + roll + diceRoll = diceRoll + str(roll) + ", " + diceRoll = diceRoll[:-2] # This removes the last two characters in the string + + if len(temp_preParsedMessage) == 2: + diceRoll = diceRoll + " + " + temp_preParsedMessage[1] + " = " + str( + rollTotal + int(temp_preParsedMessage[1])) + else: + diceRoll = diceRoll + " = " + str(rollTotal) + # If roll is in dx+x format + if loopBool == False: + roll: int = random.randint(1, int(parsedMessage[1])) + + if len(temp_preParsedMessage) == 2: + diceRoll = str(roll) + " + " + temp_preParsedMessage[1] + " = " + str( + roll + int(temp_preParsedMessage[1])) + else: + diceRoll = str(roll) + + diceRoll = "@" + message.author.display_name + " rolled: " + diceRoll + print(diceRoll) + discord_message.channel.send(diceRoll) \ No newline at end of file diff --git a/discord_script.py b/discord_script.py index eba8333..bcddc24 100644 --- a/discord_script.py +++ b/discord_script.py @@ -2,6 +2,7 @@ import random import re from discord import message +from discord.client import Client import config as config import db @@ -35,6 +36,11 @@ class Discord_Module(discord.Client): #print(str(message.id)) #Channel ID #print(str(message.channel.id)) + if message.content == "//test": + await message.channel.send('test response') + + def do_command(self): + pass From 4f55c84ba8849566b57a0fd8a4900945b427b45a Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 00:10:42 -0400 Subject: [PATCH 07/26] idea --- discord_script.py | 1 - main.py | 59 +++++++++++++++++++++++++++++++++++++++++---- utilities_script.py | 3 +++ 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/discord_script.py b/discord_script.py index bcddc24..3f767e1 100644 --- a/discord_script.py +++ b/discord_script.py @@ -16,7 +16,6 @@ import discord.channel class Discord_Module(discord.Client): def __init__(self): - super().__init__() self.dbCredential: credentials.DB_Credential self.discordCredential: credentials.Discord_Credential diff --git a/main.py b/main.py index 9491bb2..0dc3cd2 100644 --- a/main.py +++ b/main.py @@ -11,8 +11,10 @@ import utilities_script as utility import credentials -twitch_chat: twitch_script.Twitch_Module -credentials_manager: credentials.Credentials_Module +import threading + +#twitch_chat: twitch_script.Twitch_Module +#credentials_manager: credentials.Credentials_Module def main(): global twitch_chat @@ -32,14 +34,61 @@ def main(): twitch_chat.join_channel(None, "thecuriousnerd") + + + #discord_connection.main() + #Doesn't do stuff past this point + + #twitch_chat.send_message("activated") + + #discord_connection.main() + +def new_main(inputArg): + args = utility.get_args(inputArg) + + +def twitch_module_init(dbCert, twitchCert): + + twitch_chat = twitch_script.Twitch_Module() + twitch_chat.db_manager.setup_engine(dbCert) + twitch_chat.twitchCredential = twitchCert + + twitch_chat.join_channel(None, "thecuriousnerd") + + +def discord_module_init(dbCert, discordCert): + discord_connection = discord_script.Discord_Module() discord_connection.dbCredential = dbCert discord_connection.discordCredential = discordCert discord_connection.main() - #Doesn't do stuff past this point - twitch_chat.send_message("activated") + + +def thread_main(): + global twitch_chat + global credentials_manager + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") + twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") + discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") + + threads = [] + + twitch = threading.Thread(target=twitch_module_init, args=(dbCert, twitchCert)) + threads.append(twitch) + twitch.start() + + discord = threading.Thread(target=discord_module_init, args=(dbCert, discordCert)) + threads.append(discord) + discord.start() + + for t in threads: + t.join() + + if __name__ == "__main__": - main() + thread_main() diff --git a/utilities_script.py b/utilities_script.py index dc1f6b6..38a1292 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -1,3 +1,6 @@ import os clearScreen = lambda: os.system('cls' if os.name == 'nt' else 'clear') + +def get_args(text: str) -> list: + return text.split(" ") \ No newline at end of file From df3aa80a6571569494c8974c295a0f38d4d92590 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:00:33 -0400 Subject: [PATCH 08/26] Progress Maybe? This is the current error I run into: Exception in thread Thread-1: Traceback (most recent call last): File "C:\Users\ADO\AppData\Local\Programs\Python\Python37\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\ADO\AppData\Local\Programs\Python\Python37\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) TypeError: discord_module_init() argument after * must be an iterable, not Discord_Module --- discord_script.py | 22 ++++++++++++++++------ main.py | 34 +++++++++++++++++----------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/discord_script.py b/discord_script.py index 3f767e1..aa349d0 100644 --- a/discord_script.py +++ b/discord_script.py @@ -16,6 +16,7 @@ import discord.channel class Discord_Module(discord.Client): def __init__(self): + super().__init__() self.dbCredential: credentials.DB_Credential self.discordCredential: credentials.Discord_Credential @@ -23,7 +24,14 @@ class Discord_Module(discord.Client): def main(self): self.run(self.discordCredential.token) - + + def alt_main(self): + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + self.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") + self.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") + + self.run(self.discordCredential.token) async def on_ready(self): print('Logged on as', self.user) @@ -47,10 +55,12 @@ class Discord_Module(discord.Client): if __name__ == "__main__": testModule = Discord_Module() - credentials_manager = credentials.Credentials_Module() - credentials_manager.load_credentials() - testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") - testModule.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") - testModule.main() + #credentials_manager = credentials.Credentials_Module() + #credentials_manager.load_credentials() + #testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") + #testModule.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") + #testModule.main() + + testModule.alt_main() \ No newline at end of file diff --git a/main.py b/main.py index 0dc3cd2..3a5d1f9 100644 --- a/main.py +++ b/main.py @@ -48,6 +48,8 @@ def new_main(inputArg): def twitch_module_init(dbCert, twitchCert): + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() twitch_chat = twitch_script.Twitch_Module() twitch_chat.db_manager.setup_engine(dbCert) @@ -56,32 +58,30 @@ def twitch_module_init(dbCert, twitchCert): twitch_chat.join_channel(None, "thecuriousnerd") -def discord_module_init(dbCert, discordCert): +def discord_module_init(discord_connection): + #discord_connection = discord_script.Discord_Module() - discord_connection = discord_script.Discord_Module() - discord_connection.dbCredential = dbCert - discord_connection.discordCredential = discordCert - - discord_connection.main() + discord_connection.alt_main() def thread_main(): - global twitch_chat - global credentials_manager - credentials_manager = credentials.Credentials_Module() - credentials_manager.load_credentials() - dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") - twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") - discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") + #global twitch_chat + #global credentials_manager + #credentials_manager = credentials.Credentials_Module() + #credentials_manager.load_credentials() + #dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") + #twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") + #discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") threads = [] - twitch = threading.Thread(target=twitch_module_init, args=(dbCert, twitchCert)) - threads.append(twitch) - twitch.start() + #twitch = threading.Thread(target=twitch_module_init, args=(dbCert, twitchCert)) + #threads.append(twitch) + #twitch.start() - discord = threading.Thread(target=discord_module_init, args=(dbCert, discordCert)) + discord_connection = discord_script.Discord_Module() + discord = threading.Thread(target=discord_module_init, args=(discord_connection)) threads.append(discord) discord.start() From b29787d5c3ec504cd13ff0c850cbfe85239e6600 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:07:26 -0400 Subject: [PATCH 09/26] This Works? --- main.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 3a5d1f9..39d92c3 100644 --- a/main.py +++ b/main.py @@ -58,7 +58,7 @@ def twitch_module_init(dbCert, twitchCert): twitch_chat.join_channel(None, "thecuriousnerd") -def discord_module_init(discord_connection): +def discord_module_init(): #discord_connection = discord_script.Discord_Module() discord_connection.alt_main() @@ -66,22 +66,25 @@ def discord_module_init(discord_connection): def thread_main(): - #global twitch_chat - #global credentials_manager - #credentials_manager = credentials.Credentials_Module() - #credentials_manager.load_credentials() - #dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") - #twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") - #discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") + global twitch_chat + global credentials_manager + global discord_connection + + discord_connection = discord_script.Discord_Module() + credentials_manager = credentials.Credentials_Module() + + credentials_manager.load_credentials() + dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") + twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") threads = [] - #twitch = threading.Thread(target=twitch_module_init, args=(dbCert, twitchCert)) - #threads.append(twitch) - #twitch.start() + twitch = threading.Thread(target=twitch_module_init, args=(dbCert, twitchCert)) + threads.append(twitch) + twitch.start() discord_connection = discord_script.Discord_Module() - discord = threading.Thread(target=discord_module_init, args=(discord_connection)) + discord = threading.Thread(target=discord_module_init) threads.append(discord) discord.start() From c55e708928083cfdee2a6c3571b02734d8b39f2d Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:08:29 -0400 Subject: [PATCH 10/26] Added Test --- main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 39d92c3..92d48eb 100644 --- a/main.py +++ b/main.py @@ -72,7 +72,7 @@ def thread_main(): discord_connection = discord_script.Discord_Module() credentials_manager = credentials.Credentials_Module() - + credentials_manager.load_credentials() dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") @@ -92,6 +92,9 @@ def thread_main(): t.join() + print("Post Thread Test") + + if __name__ == "__main__": thread_main() From 81c458ddd1adb195f728037732338470e4f1e8e7 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:10:41 -0400 Subject: [PATCH 11/26] Removed Line --- main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/main.py b/main.py index 92d48eb..00405ca 100644 --- a/main.py +++ b/main.py @@ -48,8 +48,6 @@ def new_main(inputArg): def twitch_module_init(dbCert, twitchCert): - credentials_manager = credentials.Credentials_Module() - credentials_manager.load_credentials() twitch_chat = twitch_script.Twitch_Module() twitch_chat.db_manager.setup_engine(dbCert) From c4b409fd00fe60c51a9a38b2651ae3c58a6b3a2e Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:12:42 -0400 Subject: [PATCH 12/26] Modified more Lines --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 00405ca..e9b2703 100644 --- a/main.py +++ b/main.py @@ -13,8 +13,9 @@ import credentials import threading -#twitch_chat: twitch_script.Twitch_Module -#credentials_manager: credentials.Credentials_Module +twitch_chat: twitch_script.Twitch_Module +credentials_manager: credentials.Credentials_Module +discord_connection: discord_script.Discord_Module def main(): global twitch_chat From bab4a31d95a586cd6a8eb9bee1c17022eb33f74f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:24:53 -0400 Subject: [PATCH 13/26] Cleaned up Main --- discord_script.py | 20 ++++++-------------- main.py | 40 ++++++++++------------------------------ 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/discord_script.py b/discord_script.py index aa349d0..bf25c07 100644 --- a/discord_script.py +++ b/discord_script.py @@ -25,14 +25,6 @@ class Discord_Module(discord.Client): def main(self): self.run(self.discordCredential.token) - def alt_main(self): - credentials_manager = credentials.Credentials_Module() - credentials_manager.load_credentials() - self.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") - self.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") - - self.run(self.discordCredential.token) - async def on_ready(self): print('Logged on as', self.user) @@ -55,12 +47,12 @@ class Discord_Module(discord.Client): if __name__ == "__main__": testModule = Discord_Module() - #credentials_manager = credentials.Credentials_Module() - #credentials_manager.load_credentials() - #testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") - #testModule.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") - #testModule.main() + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + testModule.dbCredential = credentials_manager.find_DB_Credential("praxis_bot") + testModule.discordCredential = credentials_manager.find_Discord_Credential("praxis_bot") + testModule.main() - testModule.alt_main() + testModule.main() \ No newline at end of file diff --git a/main.py b/main.py index e9b2703..70654a1 100644 --- a/main.py +++ b/main.py @@ -18,31 +18,7 @@ credentials_manager: credentials.Credentials_Module discord_connection: discord_script.Discord_Module def main(): - global twitch_chat - global credentials_manager - credentials_manager = credentials.Credentials_Module() - credentials_manager.load_credentials() - - dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") - twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") - discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") - - - twitch_chat = twitch_script.Twitch_Module() - - twitch_chat.db_manager.setup_engine(dbCert) - twitch_chat.twitchCredential = twitchCert - - twitch_chat.join_channel(None, "thecuriousnerd") - - - - #discord_connection.main() - #Doesn't do stuff past this point - - #twitch_chat.send_message("activated") - - #discord_connection.main() + pass def new_main(inputArg): args = utility.get_args(inputArg) @@ -57,10 +33,12 @@ def twitch_module_init(dbCert, twitchCert): twitch_chat.join_channel(None, "thecuriousnerd") -def discord_module_init(): +def discord_module_init(dbCert, discordCert): #discord_connection = discord_script.Discord_Module() + discord_connection.dbCredential = dbCert + discord_connection.discordCredential = discordCert - discord_connection.alt_main() + discord_connection.main() @@ -75,6 +53,7 @@ def thread_main(): credentials_manager.load_credentials() dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, "praxis_bot") twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential("praxis_bot") + discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential("praxis_bot") threads = [] @@ -83,15 +62,16 @@ def thread_main(): twitch.start() discord_connection = discord_script.Discord_Module() - discord = threading.Thread(target=discord_module_init) + discord = threading.Thread(target=discord_module_init, args=(dbCert, discordCert)) threads.append(discord) discord.start() + print("---Post Thread Creation Test---") for t in threads: t.join() - - print("Post Thread Test") + print("---Point of no return---") + From 07a48e0aa769d489a8d672aafce3e249ec19e66c Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:35:14 -0400 Subject: [PATCH 14/26] Updated ReadMe & Templates --- README.md | 5 +++++ credential_templates/credential_template_discord.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9406164..9c04d2d 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,13 @@ Oauth = `https://twitchapps.com/tmi/` V5 Client ID = `https://twitchtokengenerator.com/` ### For Database Credentials +Nickname = `Anything You Want` Engine = `"mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"` +### For Discord Credentials +Nickname = `Anything You Want` +Token = `https://discord.com/developers/` + ## Credential Usage: Place json credentials in the `/credentials/` folder. diff --git a/credential_templates/credential_template_discord.json b/credential_templates/credential_template_discord.json index 51f9dc0..7a721bd 100644 --- a/credential_templates/credential_template_discord.json +++ b/credential_templates/credential_template_discord.json @@ -1,4 +1,4 @@ { - "username": "AnythingYouWant", + "nickname": "AnythingYouWant", "token": "" } \ No newline at end of file From 14894e9aed11f3c2725518ecf753f2b3b139d6c6 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:41:56 -0400 Subject: [PATCH 15/26] Fixed Inconsistency --- main.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 70654a1..3586d1e 100644 --- a/main.py +++ b/main.py @@ -25,8 +25,6 @@ def new_main(inputArg): def twitch_module_init(dbCert, twitchCert): - - twitch_chat = twitch_script.Twitch_Module() twitch_chat.db_manager.setup_engine(dbCert) twitch_chat.twitchCredential = twitchCert @@ -34,7 +32,6 @@ def twitch_module_init(dbCert, twitchCert): def discord_module_init(dbCert, discordCert): - #discord_connection = discord_script.Discord_Module() discord_connection.dbCredential = dbCert discord_connection.discordCredential = discordCert @@ -47,7 +44,9 @@ def thread_main(): global credentials_manager global discord_connection + twitch_chat = twitch_script.Twitch_Module() discord_connection = discord_script.Discord_Module() + credentials_manager = credentials.Credentials_Module() credentials_manager.load_credentials() From 7258bc0baf005ad9103acf5317c3013c12b2aec3 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 03:44:08 -0400 Subject: [PATCH 16/26] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9c04d2d..ebc005f 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,12 @@ V5 Client ID = `https://twitchtokengenerator.com/` ### For Database Credentials Nickname = `Anything You Want` + Engine = `"mysql+mysqlconnector://root:password@localhost:3306/DatabaseName"` ### For Discord Credentials Nickname = `Anything You Want` + Token = `https://discord.com/developers/` ## Credential Usage: From 6c7df8674da7aa5e446926842a0443b4d53f11da Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 04:18:45 -0400 Subject: [PATCH 17/26] Working Discord Roll Command --- commands/implemented/command_roll_discord.py | 9 +++--- discord_script.py | 32 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py index b517b2d..cc1f747 100644 --- a/commands/implemented/command_roll_discord.py +++ b/commands/implemented/command_roll_discord.py @@ -19,12 +19,12 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD) - def do_command(self, bot, discord_message: discord.Message): + async def do_command(self, bot, discord_message: discord.Message): print("!roll Detected") #twitch_message.chat.send("test acknowledged") diceRoll: str = "" - discord_message.channel.send("Rolling Dice...") + await discord_message.channel.send("Rolling Dice...") print("Rolling Dice...") temp_preParsedMessage = discord_message.content.split("+") @@ -67,6 +67,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): else: diceRoll = str(roll) - diceRoll = "@" + message.author.display_name + " rolled: " + diceRoll + + diceRoll = discord_message.author.mention + " rolled: " + diceRoll print(diceRoll) - discord_message.channel.send(diceRoll) \ No newline at end of file + await discord_message.channel.send(diceRoll) \ No newline at end of file diff --git a/discord_script.py b/discord_script.py index bf25c07..2ba46c5 100644 --- a/discord_script.py +++ b/discord_script.py @@ -8,6 +8,9 @@ import config as config import db import tts +import commands.loader as command_loader +from commands.command_base import AbstractCommand + import credentials import discord @@ -20,6 +23,8 @@ class Discord_Module(discord.Client): self.dbCredential: credentials.DB_Credential self.discordCredential: credentials.Discord_Credential + self.commands = command_loader.load_commands() + self.tts_enabled: bool = False def main(self): @@ -38,8 +43,35 @@ class Discord_Module(discord.Client): if message.content == "//test": await message.channel.send('test response') + await self.eval_commands(message) + def do_command(self): pass + + async def eval_commands(self, message: discord.Message): + # containsURL: bool = self.contains_url(message) + try: + #first_space_idx = message.text.index(' ') + + # This fixes a error where if you send a command without arguments it fails because + # it cant find the substring. + if message.content.find(" ") != -1: + first_space_idx = message.content.index(' ') + else: + first_space_idx = -1 + + command_text = ' ' + if first_space_idx > -1: + command_text = message.content[0:first_space_idx] + else: + command_text = message.content + + command = self.commands[command_text] + if command is not None and command.command_type is AbstractCommand.CommandType.DISCORD: + await command.do_command(self, message) + except Exception as e: + print(e) + pass # we don't care From 323a5b1e9e35bf1c345f22b868d67b47ca4c5d3f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 04:27:04 -0400 Subject: [PATCH 18/26] Clean Up --- discord_script.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/discord_script.py b/discord_script.py index 2ba46c5..9bc8325 100644 --- a/discord_script.py +++ b/discord_script.py @@ -45,9 +45,6 @@ class Discord_Module(discord.Client): await self.eval_commands(message) - def do_command(self): - pass - async def eval_commands(self, message: discord.Message): # containsURL: bool = self.contains_url(message) try: From b0169ec68d2a47e3dad4d96d66350e06f3b80dc5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 04:44:52 -0400 Subject: [PATCH 19/26] Setup Cooldowns & Msg Clean Up --- commands/implemented/command_roll_discord.py | 6 ++++-- discord_script.py | 10 ++++++++++ twitch_script.py | 10 +++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py index cc1f747..8c86d07 100644 --- a/commands/implemented/command_roll_discord.py +++ b/commands/implemented/command_roll_discord.py @@ -24,7 +24,8 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): #twitch_message.chat.send("test acknowledged") diceRoll: str = "" - await discord_message.channel.send("Rolling Dice...") + await bot.send_message(discord_message, "Rolling Dice...") + #await discord_message.channel.send("Rolling Dice...") print("Rolling Dice...") temp_preParsedMessage = discord_message.content.split("+") @@ -70,4 +71,5 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): diceRoll = discord_message.author.mention + " rolled: " + diceRoll print(diceRoll) - await discord_message.channel.send(diceRoll) \ No newline at end of file + await bot.send_message(discord_message, diceRoll) + #await discord_message.channel.send(diceRoll) diff --git a/discord_script.py b/discord_script.py index 9bc8325..f6041d0 100644 --- a/discord_script.py +++ b/discord_script.py @@ -17,12 +17,17 @@ import discord import discord.message import discord.channel +from cooldowns import Cooldown_Module + class Discord_Module(discord.Client): def __init__(self): super().__init__() self.dbCredential: credentials.DB_Credential self.discordCredential: credentials.Discord_Credential + self.cooldownModule:Cooldown_Module = Cooldown_Module() + self.cooldownModule.setupCooldown("discordRateLimit", 10, 1) + self.commands = command_loader.load_commands() self.tts_enabled: bool = False @@ -69,6 +74,11 @@ class Discord_Module(discord.Client): except Exception as e: print(e) pass # we don't care + + async def send_message(self, message, response): + if self.cooldownModule.isCooldownActive("discordRateLimit") == False: + await message.channel.send(response) + self.cooldownModule.actionTrigger("discordRateLimit") diff --git a/twitch_script.py b/twitch_script.py index bf4ef2c..b05ed8e 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -34,8 +34,8 @@ class Twitch_Module(): # Default Twitch Chat limit is 20 per 30 seconds # If Mod or Op, Twitch Chat limit is 100 per 30 seconds - self.twitchChat_cooldown:Cooldown_Module = Cooldown_Module() - self.twitchChat_cooldown.setupCooldown("twitchChat", 20, 32) + self.cooldownModule:Cooldown_Module = Cooldown_Module() + self.cooldownModule.setupCooldown("twitchChat", 20, 32) def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str): channel_name = "#" + channel_name @@ -60,9 +60,9 @@ class Twitch_Module(): self.chat.irc.socket.close() def send_message(self, message): - if self.twitchChat_cooldown.isCooldownActive("twitchChat") == False: + if self.cooldownModule.isCooldownActive("twitchChat") == False: self.chat.send(message) - self.twitchChat_cooldown.actionTrigger("twitchChat") + self.cooldownModule.actionTrigger("twitchChat") def send_whisper(self, user, message): pass @@ -73,7 +73,7 @@ class Twitch_Module(): if message.channel == "thecuriousnerd": if not self.isSenderBot(message): - if self.twitchChat_cooldown.isCooldownActive("twitchChat") == False: + if self.cooldownModule.isCooldownActive("twitchChat") == False: self.eval_commands(message) #elif message.channel == message.sender: #self.eval_commands(message) From 5f3b3bb7757ea07ef3a0b4ae6c439dcdecb95ffc Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 05:07:41 -0400 Subject: [PATCH 20/26] Cleaned up Main --- main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.py b/main.py index 3586d1e..4939d57 100644 --- a/main.py +++ b/main.py @@ -41,12 +41,11 @@ def discord_module_init(dbCert, discordCert): def thread_main(): global twitch_chat - global credentials_manager global discord_connection + global credentials_manager twitch_chat = twitch_script.Twitch_Module() discord_connection = discord_script.Discord_Module() - credentials_manager = credentials.Credentials_Module() credentials_manager.load_credentials() @@ -60,7 +59,6 @@ def thread_main(): threads.append(twitch) twitch.start() - discord_connection = discord_script.Discord_Module() discord = threading.Thread(target=discord_module_init, args=(dbCert, discordCert)) threads.append(discord) discord.start() From ce702b8b01791869d2772d4315aa488c9e9ec48f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 06:12:26 -0400 Subject: [PATCH 21/26] Working TTS on Discord I also cleaned up tts usage in a few other places. --- commands/implemented/command_tts_discord.py | 30 +++++++++++ config.py | 2 +- discord_script.py | 56 ++++++++++++++++++++- twitch_script.py | 5 +- 4 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 commands/implemented/command_tts_discord.py diff --git a/commands/implemented/command_tts_discord.py b/commands/implemented/command_tts_discord.py new file mode 100644 index 0000000..36e0064 --- /dev/null +++ b/commands/implemented/command_tts_discord.py @@ -0,0 +1,30 @@ +from abc import ABCMeta + +from commands.command_base import AbstractCommand + +import discord +import discord.message + +class CommandTTS(AbstractCommand, metaclass=ABCMeta): + command = "!tts" + + def __init__(self): + super().__init__(CommandTTS.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD) + + async def do_command(self, bot, discord_message: discord.message): + args = self.get_args(discord_message.content) + if args[1] == "start": + print(discord_message.author.top_role) + print("start detected") + if str(discord_message.author.top_role) == "Admin": + print("Admin Check") + response = str("tts activated on %s" % discord_message.guild.name) + await bot.send_message(discord_message, response) + bot.tts_enabled = True + elif args[1] == "stop": + print("stop detected") + if str(discord_message.author.top_role) == "Admin": + print("Admin Check") + response = str("tts deactivated on %s" % discord_message.guild.name) + await bot.send_message(discord_message, response) + bot.tts_enabled = False diff --git a/config.py b/config.py index e4899e4..af48f20 100644 --- a/config.py +++ b/config.py @@ -74,7 +74,7 @@ class PollyVoices(Enum): Zhiyu = "Zhiyu" -botList = ("Nightbot", "StreamElements", "Moobot", "praxis_bot") +botList = ("Nightbot", "StreamElements", "Moobot", "praxis_bot", "MEE6 +", "Nerdy", "Rythm", "Groovy") slurList = ("fag", "faggot", "niga", "nigga", "nigger", "retard", "tard", "rtard", "coon") diff --git a/discord_script.py b/discord_script.py index f6041d0..e40cf14 100644 --- a/discord_script.py +++ b/discord_script.py @@ -48,7 +48,11 @@ class Discord_Module(discord.Client): if message.content == "//test": await message.channel.send('test response') - await self.eval_commands(message) + if not await self.isSenderBot(message): + if self.cooldownModule.isCooldownActive("discordRateLimit") == False: + await self.eval_commands(message) + await self.tts_message(message) + async def eval_commands(self, message: discord.Message): # containsURL: bool = self.contains_url(message) @@ -72,13 +76,61 @@ class Discord_Module(discord.Client): if command is not None and command.command_type is AbstractCommand.CommandType.DISCORD: await command.do_command(self, message) except Exception as e: - print(e) + # Undo the following for debug stuff + #print(e) pass # we don't care async def send_message(self, message, response): if self.cooldownModule.isCooldownActive("discordRateLimit") == False: await message.channel.send(response) self.cooldownModule.actionTrigger("discordRateLimit") + + async def tts_message(self, message: discord.Message): + if not await self.contains_slur(message): + if self.tts_enabled: + if not message.content.startswith('!'): + text_to_say: str = "%s says, %s" % (message.author.display_name, message.content) + channel_text = "%s user msg" % message.channel + + if message.author.display_name.lower() == message.channel: + tts.tts(text_to_say) + else: + # tts.tts(message.sender + " says, " + message.text) + tts.tts(text_to_say) + + # Checks for basic slurs. + async def contains_slur(self, message: discord.Message): + containsSlur: bool = False + + if await self.slur_check(message.content) or await self.slur_check(message.author.display_name): + containsSlur = True + + return containsSlur + + async def slur_check(self, text): + containsSlur: bool = False + parsedMessage = text.split(" ") + for word in parsedMessage: + for slur in config.slurList: + if word.lower() == slur: + containsSlur = True + break # we want to immediately escape if we found a slur + if containsSlur: + break + + if containsSlur: + print("<{ slur detected! }>") + #print("<{ slur detected! }> " + " [#" + message.channel + "](" + message.author.display_name + ") used a slur in chat") + return containsSlur + + # Checks if Sender is bot. + async def isSenderBot(self, message: discord.Message): + isBot = False + for bot in config.botList: + if message.author.display_name.lower() == bot.lower(): + isBot = True + print("<{ bot detected! }> ") + return isBot diff --git a/twitch_script.py b/twitch_script.py index b05ed8e..85e5598 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -75,8 +75,6 @@ class Twitch_Module(): if not self.isSenderBot(message): if self.cooldownModule.isCooldownActive("twitchChat") == False: self.eval_commands(message) - #elif message.channel == message.sender: - #self.eval_commands(message) self.tts_message(message) def eval_commands(self, message: twitch.chat.Message): @@ -101,7 +99,8 @@ class Twitch_Module(): if command is not None and command.command_type is AbstractCommand.CommandType.TWITCH: command.do_command(self, message) except Exception as e: - print(e) + # Undo the following for debug stuff + #print(e) pass # we don't care From 83dad6764a2fd5764ec21510dd471c3a6ac786b1 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 06:16:49 -0400 Subject: [PATCH 22/26] Got rid of junk --- config.py | 2 +- discord_script.py | 6 +----- twitch_script.py | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index af48f20..1d1bb5a 100644 --- a/config.py +++ b/config.py @@ -74,7 +74,7 @@ class PollyVoices(Enum): Zhiyu = "Zhiyu" -botList = ("Nightbot", "StreamElements", "Moobot", "praxis_bot", "MEE6 +", "Nerdy", "Rythm", "Groovy") +botList = ("Nightbot", "StreamElements", "Moobot", "Praxis Bot", "praxis_bot", "MEE6 +", "Nerdy", "Rythm", "Groovy") slurList = ("fag", "faggot", "niga", "nigga", "nigger", "retard", "tard", "rtard", "coon") diff --git a/discord_script.py b/discord_script.py index e40cf14..0515592 100644 --- a/discord_script.py +++ b/discord_script.py @@ -92,11 +92,7 @@ class Discord_Module(discord.Client): text_to_say: str = "%s says, %s" % (message.author.display_name, message.content) channel_text = "%s user msg" % message.channel - if message.author.display_name.lower() == message.channel: - tts.tts(text_to_say) - else: - # tts.tts(message.sender + " says, " + message.text) - tts.tts(text_to_say) + tts.tts(text_to_say) # Checks for basic slurs. async def contains_slur(self, message: discord.Message): diff --git a/twitch_script.py b/twitch_script.py index 85e5598..8a13871 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -111,11 +111,7 @@ class Twitch_Module(): text_to_say: str = "%s says, %s" % (message.sender, message.text) channel_text = "%s user msg" % message.channel - if message.sender.lower() == message.channel: - tts.tts(text_to_say) - else: - # tts.tts(message.sender + " says, " + message.text) - tts.tts(text_to_say, channel_text) + tts.tts(text_to_say) def contains_url(self, message: twitch.chat.Message): containsURL = re.search(self._urlMatcher, message.text.lower()) is not None From 0e0456ca9ef85d443726fcd3002321e0633008a9 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 06:26:41 -0400 Subject: [PATCH 23/26] Prep for Bug Fix Currently there is a bug where if discord and twitch have the same named commands, the command will fail. --- twitch_script.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/twitch_script.py b/twitch_script.py index 8a13871..8913582 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -78,6 +78,7 @@ class Twitch_Module(): self.tts_message(message) def eval_commands(self, message: twitch.chat.Message): + print("evaling command") # containsURL: bool = self.contains_url(message) try: #first_space_idx = message.text.index(' ') @@ -97,10 +98,12 @@ class Twitch_Module(): command = self.commands[command_text] if command is not None and command.command_type is AbstractCommand.CommandType.TWITCH: + print("evaling command") command.do_command(self, message) except Exception as e: # Undo the following for debug stuff #print(e) + print("failed command") pass # we don't care From a167a7eba45bec0202b95329d94a5564080062e5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 20 Oct 2020 15:47:27 -0400 Subject: [PATCH 24/26] Updated Command Loader --- commands/loader.py | 17 ++++++++++++++++- discord_script.py | 2 +- twitch_script.py | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/commands/loader.py b/commands/loader.py index cab69b1..e885988 100644 --- a/commands/loader.py +++ b/commands/loader.py @@ -12,6 +12,9 @@ def load_commands() -> Dict[str, AbstractCommand]: commands = compile_and_load() return commands +def load_commands_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]: + commands = compile_and_load_new(commandType) + return commands def compile_and_load_file(path: str) -> (str, AbstractCommand): module_name = os.path.split(path)[1].replace(".py", "") @@ -41,6 +44,18 @@ def compile_and_load() -> Dict[str, AbstractCommand]: break return dic +def compile_and_load_new(commandType: AbstractCommand.CommandType) -> Dict[str, AbstractCommand]: + dic = {} + implementations = get_implementations_dir() + for dirName, subdirList, fileList in os.walk(implementations): + for file in fileList: + name = os.path.join(dirName, file) + print("compiling %s" % name) + name, command = compile_and_load_file(name) + if command is not None and command.command_type is commandType: + dic[name] = command + break + return dic def get_base_dir() -> str: cwd = os.getcwd() @@ -52,7 +67,7 @@ def get_base_dir() -> str: return check_dir(os.path.join(cwd, "commands")) else: print("could not find working directory for Praxis_Bot/commands") - raise + raise Exception def get_implementations_dir() -> str: diff --git a/discord_script.py b/discord_script.py index 0515592..afa0783 100644 --- a/discord_script.py +++ b/discord_script.py @@ -28,7 +28,7 @@ class Discord_Module(discord.Client): self.cooldownModule:Cooldown_Module = Cooldown_Module() self.cooldownModule.setupCooldown("discordRateLimit", 10, 1) - self.commands = command_loader.load_commands() + self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.DISCORD) self.tts_enabled: bool = False diff --git a/twitch_script.py b/twitch_script.py index 8913582..ef530ae 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -23,7 +23,7 @@ class Twitch_Module(): self.db_manager: db.db_module = db.db_module() self.chat: twitch.Chat - self.commands = command_loader.load_commands() + self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.TWITCH) self.tts_enabled: bool = False self.tts_whitelist_enabled: bool = False self.links_allowed: bool = True From b2b1d87949fec38c40f3aa05dc25e8ab4902b7b7 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Mon, 16 Nov 2020 16:59:55 -0500 Subject: [PATCH 25/26] Fixed Command Typo --- commands/implemented/command_tts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/implemented/command_tts.py b/commands/implemented/command_tts.py index 305e1cf..133d851 100644 --- a/commands/implemented/command_tts.py +++ b/commands/implemented/command_tts.py @@ -18,5 +18,5 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): bot.tts_enabled = True elif args[1] == "stop": if twitch_message.sender.lower() == twitch_message.channel: - bot.send_message("tts activated on #%s" % twitch_message.channel) + bot.send_message("tts deactivated on #%s" % twitch_message.channel) bot.tts_enabled = False From c04322ccd7c3b9f2e6b633d5531c126813bfccf9 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 17 Nov 2020 05:30:43 -0500 Subject: [PATCH 26/26] Threading Fix --- discord_script.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/discord_script.py b/discord_script.py index afa0783..64d0bf2 100644 --- a/discord_script.py +++ b/discord_script.py @@ -3,6 +3,7 @@ import re from discord import message from discord.client import Client +import asyncio import config as config import db @@ -22,6 +23,7 @@ from cooldowns import Cooldown_Module class Discord_Module(discord.Client): def __init__(self): super().__init__() + self.loop = asyncio.get_event_loop() self.dbCredential: credentials.DB_Credential self.discordCredential: credentials.Discord_Credential @@ -32,8 +34,13 @@ class Discord_Module(discord.Client): self.tts_enabled: bool = False + async def startup(self): + await self.start(self.discordCredential.token) + def main(self): - self.run(self.discordCredential.token) + print("starting loop") + self.loop.create_task(self.startup()) + self.loop.run_forever() async def on_ready(self): print('Logged on as', self.user)