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.py index 4d743ee..0454f74 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -14,16 +14,17 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): command = "!lights" def __init__(self): - super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) + super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis) - def do_command(self, bot, twitch_message): - if bot.allow_rgbLightControl == True: + def do_command(self, bot, user_message): + tempBool = True + if tempBool == True: LightModule = lights_module.Lights_Module() LightModule.main() print("\nRGB Command Detected!") - tempParsedMessage = twitch_message.text.split(" ") - print("\nParsed Command! ", twitch_message.text) + tempParsedMessage = user_message.message.split(" ") + print("\nParsed Command! ", user_message.message) if (len(tempParsedMessage)) > 2: print("\nRGB Command!") rgb_r = float(tempParsedMessage[1]) @@ -36,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) @@ -53,5 +54,5 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): LightModule.bridge_.set_group(16, "xy", xy_result) print("sent color") - returnMessage = "@" + twitch_message.sender + " changed the light's color!" - bot.send_message(returnMessage) \ No newline at end of file + returnMessage = "@" + user_message.user + " changed the light's color!" + bot.return_message(returnMessage) \ No newline at end of file diff --git a/commands/implemented/command_lights_rgb_color_twitch.py b/commands/implemented/command_lights_rgb_color_twitch.py new file mode 100644 index 0000000..909ae16 --- /dev/null +++ b/commands/implemented/command_lights_rgb_color_twitch.py @@ -0,0 +1,57 @@ +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.TWITCH) + + def do_command(self, bot, twitch_message): + if bot.allow_rgbLightControl == True: + LightModule = lights_module.Lights_Module() + LightModule.main() + print("\nRGB Command Detected!") + + tempParsedMessage = twitch_message.text.split(" ") + print("\nParsed Command! ", twitch_message.text) + 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" 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 = "@" + twitch_message.sender + " changed the light's color!" + bot.send_message(returnMessage) \ No newline at end of file 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 new file mode 100644 index 0000000..4e904d0 --- /dev/null +++ b/user_module.py @@ -0,0 +1,96 @@ +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.commands = command_loader.load_commands_new(AbstractCommand.CommandType.Praxis) + self.MessageLog:list = [] + + def main(self): + 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(message) + + def parseInput(self, message): + if self.isCommand(message) == True: + self.runCommand(message) + else: + pass + + def isCommand(self, message): + isCommand = True + #MAKE THIS + return isCommand + + def runCommand(self, message): + self.eval_commands(message) + + 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.message.find(" ") != -1: + first_space_idx = message.message.index(' ') + else: + first_space_idx = -1 + + command_text = ' ' + if first_space_idx > -1: + command_text = message.message[0:first_space_idx] + else: + command_text = message.message + + 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 return_message(self, returnedMessage): + print(returnedMessage) + + 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() + + 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