From 0ae1cd880d89046683784bf89416ae43fbc223e0 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 16:24:57 -0400 Subject: [PATCH] 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()