From dadf75364e3d7717a25af108bf321520d50145f5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:06:09 -0400 Subject: [PATCH] Added Command Support --- commands/command_base.py | 1 + ....py => command_lights_rgb_color_twitch.py} | 0 ...artBot.py => command_restartBot_twitch.py} | 0 ...command_roll.py => command_roll_twitch.py} | 0 ...wnBot.py => command_shutdownBot_twitch.py} | 0 ...command_test.py => command_test_twitch.py} | 0 .../{command_tts.py => command_tts_twitch.py} | 0 user_module.py | 46 +++++++++++++++++-- 8 files changed, 43 insertions(+), 4 deletions(-) rename commands/implemented/{command_lights_rgb_color.py => command_lights_rgb_color_twitch.py} (100%) rename commands/implemented/{command_restartBot.py => command_restartBot_twitch.py} (100%) rename commands/implemented/{command_roll.py => command_roll_twitch.py} (100%) rename commands/implemented/{command_shutdownBot.py => command_shutdownBot_twitch.py} (100%) rename commands/implemented/{command_test.py => command_test_twitch.py} (100%) rename commands/implemented/{command_tts.py => command_tts_twitch.py} (100%) diff --git a/commands/command_base.py b/commands/command_base.py index 9bcbcb3..064b5c5 100644 --- a/commands/command_base.py +++ b/commands/command_base.py @@ -14,6 +14,7 @@ class AbstractCommand(metaclass=ABCMeta): class CommandType(Enum): NONE = auto() + Praxis = auto() TWITCH = auto() DISCORD = auto() diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color_twitch.py similarity index 100% rename from commands/implemented/command_lights_rgb_color.py rename to commands/implemented/command_lights_rgb_color_twitch.py diff --git a/commands/implemented/command_restartBot.py b/commands/implemented/command_restartBot_twitch.py similarity index 100% rename from commands/implemented/command_restartBot.py rename to commands/implemented/command_restartBot_twitch.py diff --git a/commands/implemented/command_roll.py b/commands/implemented/command_roll_twitch.py similarity index 100% rename from commands/implemented/command_roll.py rename to commands/implemented/command_roll_twitch.py diff --git a/commands/implemented/command_shutdownBot.py b/commands/implemented/command_shutdownBot_twitch.py similarity index 100% rename from commands/implemented/command_shutdownBot.py rename to commands/implemented/command_shutdownBot_twitch.py diff --git a/commands/implemented/command_test.py b/commands/implemented/command_test_twitch.py similarity index 100% rename from commands/implemented/command_test.py rename to commands/implemented/command_test_twitch.py diff --git a/commands/implemented/command_tts.py b/commands/implemented/command_tts_twitch.py similarity index 100% rename from commands/implemented/command_tts.py rename to commands/implemented/command_tts_twitch.py diff --git a/user_module.py b/user_module.py index a7f6899..ad2635f 100644 --- a/user_module.py +++ b/user_module.py @@ -1,19 +1,27 @@ import config as config import db +import tts import credentials +import commands.loader as command_loader +from commands.command_base import AbstractCommand + +from cooldowns import Cooldown_Module + class User_Module(): def __init__(self): super().__init__() self.dbCredential: credentials.DB_Credential + self.MessageLog:list = [] def main(self): print("Waiting on User input...") - while True: + inputLoop = True + while inputLoop: keyboardInput = input() - if "exit" or "quit" or "stop" in keyboardInput: + if "exit" in keyboardInput: print("Quitting User Module Interface...") break @@ -26,11 +34,41 @@ class User_Module(): pass def isCommand(self, input): - isCommand = False + isCommand = True + #MAKE THIS return isCommand def runCommand(self, input): - pass + self.eval_commands(input) + + def eval_commands(self, 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.Praxis: + command.do_command(self, message) + except Exception as e: + # Undo the following for debug stuff + #print(e) + pass # we don't care + + def tts_message(self, message): + tts.tts(message) if __name__ == "__main__": testModule = User_Module()