From 1519e878596bcaac441846cc55ff1f6bc4b5756d Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 15:48:08 -0400 Subject: [PATCH 1/6] Create user_module.py --- user_module.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 user_module.py diff --git a/user_module.py b/user_module.py new file mode 100644 index 0000000..a7f6899 --- /dev/null +++ b/user_module.py @@ -0,0 +1,41 @@ +import config as config +import db + +import credentials + +class User_Module(): + def __init__(self): + super().__init__() + self.dbCredential: credentials.DB_Credential + + def main(self): + print("Waiting on User input...") + while True: + keyboardInput = input() + + if "exit" or "quit" or "stop" in keyboardInput: + print("Quitting User Module Interface...") + break + + self.parseInput(keyboardInput) + + def parseInput(self, input): + if self.isCommand(input): + self.runCommand(input) + else: + pass + + def isCommand(self, input): + isCommand = False + return isCommand + + def runCommand(self, input): + pass + +if __name__ == "__main__": + testModule = User_Module() + + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname) + testModule.main() \ No newline at end of file -- 2.45.2 From dadf75364e3d7717a25af108bf321520d50145f5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:06:09 -0400 Subject: [PATCH 2/6] 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() -- 2.45.2 From 15abdc16f3dd6fcace419e8885c7e93a015fe8c5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:06:55 -0400 Subject: [PATCH 3/6] loop --- user_module.py | 1 + 1 file changed, 1 insertion(+) diff --git a/user_module.py b/user_module.py index ad2635f..6ffd978 100644 --- a/user_module.py +++ b/user_module.py @@ -23,6 +23,7 @@ class User_Module(): if "exit" in keyboardInput: print("Quitting User Module Interface...") + inputLoop = False break self.parseInput(keyboardInput) -- 2.45.2 From 0ae1cd880d89046683784bf89416ae43fbc223e0 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:24:57 -0400 Subject: [PATCH 4/6] Added Lights Command to User Module --- .../implemented/command_lights_rgb_color.py | 58 +++++++++++++++++++ user_module.py | 39 ++++++++----- 2 files changed, 84 insertions(+), 13 deletions(-) create mode 100644 commands/implemented/command_lights_rgb_color.py diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py new file mode 100644 index 0000000..180a868 --- /dev/null +++ b/commands/implemented/command_lights_rgb_color.py @@ -0,0 +1,58 @@ +from abc import ABCMeta +import lights_module + +from commands.command_base import AbstractCommand + +import random + +import utilities_script as utilities + +class CommandRoll(AbstractCommand, metaclass=ABCMeta): + """ + this is the roll command. + """ + command = "!lights" + + def __init__(self): + super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis) + + def do_command(self, bot, user_message): + tempBool = True + if tempBool == True: + LightModule = lights_module.Lights_Module() + LightModule.main() + print("\nRGB Command Detected!") + + tempParsedMessage = user_message.message.split(" ") + print("\nParsed Command! ", user_message.message) + if (len(tempParsedMessage)) > 2: + print("\nRGB Command!") + rgb_r = float(tempParsedMessage[1]) + rgb_g = float(tempParsedMessage[2]) + rgb_b = float(tempParsedMessage[3]) + xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) + print("got XY") + LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") + else: + if "stream" in tempParsedMessage: + LightModule.bridge_.run_scene("Downstairs", "Stream") + elif ("normal" or "regular" or "bright" or "daylight") in tempParsedMessage: + LightModule.bridge_.run_scene("Downstairs", "Bright") + elif ("haxor") in tempParsedMessage: + LightModule.bridge_.run_scene("Downstairs", "hacker vibes") + elif "off" in tempParsedMessage: + LightModule.bridge_.set_group("Downstairs", "on", False) + elif "on" in tempParsedMessage: + LightModule.bridge_.set_group("Downstairs", "on", True) + elif "ravemode" in tempParsedMessage: + LightModule.raveMode() + else: + print("\nColor Command!") + xy_result = LightModule.color_string_parser(tempParsedMessage) + print("got XY") + LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") + + returnMessage = "@" + user_message.user + " changed the light's color!" + bot.send_message(returnMessage) \ No newline at end of file diff --git a/user_module.py b/user_module.py index 6ffd978..70cd445 100644 --- a/user_module.py +++ b/user_module.py @@ -13,34 +13,37 @@ class User_Module(): def __init__(self): super().__init__() self.dbCredential: credentials.DB_Credential + self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.Praxis) self.MessageLog:list = [] def main(self): - print("Waiting on User input...") + print("\nWaiting on User input...") inputLoop = True while inputLoop: keyboardInput = input() + message = UserMessage() + message.makeMessage(message=keyboardInput) if "exit" in keyboardInput: print("Quitting User Module Interface...") inputLoop = False break - self.parseInput(keyboardInput) + self.parseInput(message) - def parseInput(self, input): - if self.isCommand(input): - self.runCommand(input) + def parseInput(self, message): + if self.isCommand(message) == True: + self.runCommand(message) else: pass - def isCommand(self, input): + def isCommand(self, message): isCommand = True #MAKE THIS return isCommand - def runCommand(self, input): - self.eval_commands(input) + def runCommand(self, message): + self.eval_commands(message) def eval_commands(self, message): # containsURL: bool = self.contains_url(message) @@ -49,16 +52,16 @@ class User_Module(): # 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(' ') + if message.message.find(" ") != -1: + first_space_idx = message.message.index(' ') else: first_space_idx = -1 command_text = ' ' if first_space_idx > -1: - command_text = message.content[0:first_space_idx] + command_text = message.message[0:first_space_idx] else: - command_text = message.content + command_text = message.message command = self.commands[command_text] if command is not None and command.command_type is AbstractCommand.CommandType.Praxis: @@ -68,9 +71,19 @@ class User_Module(): #print(e) pass # we don't care - def tts_message(self, message): + def tts(self, message): tts.tts(message) +class UserMessage(): + def __init__(self): + super().__init__() + self.user = "User" + self.message = "" + + def makeMessage(self, user = "User", message = ""): + self.user = user + self.message = message + if __name__ == "__main__": testModule = User_Module() -- 2.45.2 From 79a4977b3831a26002e5b36f9525383626bdd4a5 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:28:21 -0400 Subject: [PATCH 5/6] Return Message --- commands/implemented/command_lights_rgb_color.py | 6 +++--- user_module.py | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py index 180a868..0454f74 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -37,9 +37,9 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): else: if "stream" in tempParsedMessage: LightModule.bridge_.run_scene("Downstairs", "Stream") - elif ("normal" or "regular" or "bright" or "daylight") in tempParsedMessage: + elif "normal" in tempParsedMessage: LightModule.bridge_.run_scene("Downstairs", "Bright") - elif ("haxor") in tempParsedMessage: + elif "haxor" in tempParsedMessage: LightModule.bridge_.run_scene("Downstairs", "hacker vibes") elif "off" in tempParsedMessage: LightModule.bridge_.set_group("Downstairs", "on", False) @@ -55,4 +55,4 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): print("sent color") returnMessage = "@" + user_message.user + " changed the light's color!" - bot.send_message(returnMessage) \ No newline at end of file + bot.return_message(returnMessage) \ No newline at end of file diff --git a/user_module.py b/user_module.py index 70cd445..4e904d0 100644 --- a/user_module.py +++ b/user_module.py @@ -71,6 +71,9 @@ class User_Module(): #print(e) pass # we don't care + def return_message(self, returnedMessage): + print(returnedMessage) + def tts(self, message): tts.tts(message) -- 2.45.2 From 932eb56f9787c0222d28c6abe6fab035fce04c80 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:30:26 -0400 Subject: [PATCH 6/6] fixed light command --- commands/implemented/command_lights_rgb_color_twitch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/implemented/command_lights_rgb_color_twitch.py b/commands/implemented/command_lights_rgb_color_twitch.py index 4d743ee..909ae16 100644 --- a/commands/implemented/command_lights_rgb_color_twitch.py +++ b/commands/implemented/command_lights_rgb_color_twitch.py @@ -36,9 +36,9 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): else: if "stream" in tempParsedMessage: LightModule.bridge_.run_scene("Downstairs", "Stream") - elif ("normal" or "regular" or "bright" or "daylight") in tempParsedMessage: + elif "normal" in tempParsedMessage: LightModule.bridge_.run_scene("Downstairs", "Bright") - elif ("haxor") in tempParsedMessage: + elif "haxor" in tempParsedMessage: LightModule.bridge_.run_scene("Downstairs", "hacker vibes") elif "off" in tempParsedMessage: LightModule.bridge_.set_group("Downstairs", "on", False) -- 2.45.2