From 3bbd5d1611688339dd7f1e4dda548e2145347d3f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 16 Apr 2021 04:38:07 -0400 Subject: [PATCH] Improved Commands --- commands/implemented/command_clear.py | 23 +++++++++++++++++ commands/implemented/command_exit.py | 25 +++++++++++++++++++ commands/implemented/command_help.py | 6 ++--- .../implemented/command_lights_rgb_color.py | 20 +++++++-------- lights_module.py | 2 +- user_module.py | 12 +++------ 6 files changed, 66 insertions(+), 22 deletions(-) create mode 100644 commands/implemented/command_clear.py create mode 100644 commands/implemented/command_exit.py diff --git a/commands/implemented/command_clear.py b/commands/implemented/command_clear.py new file mode 100644 index 0000000..a22ec63 --- /dev/null +++ b/commands/implemented/command_clear.py @@ -0,0 +1,23 @@ +from abc import ABCMeta + +from commands.command_base import AbstractCommand + +import utilities_script as utility + +class Command_Clear(AbstractCommand, metaclass=ABCMeta): + """ + this is the clear command. + """ + command = "clear" + + def __init__(self): + super().__init__(Command_Clear.command, n_args=1, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["This is a command to clear the screen.", + "\nExample:","clear"] + self.isCommandEnabled = True + + def do_command(self, bot, user_message): + utility.clearScreen() + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_exit.py b/commands/implemented/command_exit.py new file mode 100644 index 0000000..f68b5b7 --- /dev/null +++ b/commands/implemented/command_exit.py @@ -0,0 +1,25 @@ +from abc import ABCMeta + +import time + +from commands.command_base import AbstractCommand + +class Command_Exit(AbstractCommand, metaclass=ABCMeta): + """ + this is the exit command. + """ + command = "exit" + + def __init__(self): + super().__init__(Command_Exit.command, n_args=1, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["This is a command to exit [User Module].", + "\nExample:","exit"] + self.isCommandEnabled = True + + def do_command(self, bot, user_message): + bot.return_message("\nQuitting [User Module] Interface...") + time.sleep(0.2) + bot.inputLoop = False + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_help.py b/commands/implemented/command_help.py index 324f383..6c47d4e 100644 --- a/commands/implemented/command_help.py +++ b/commands/implemented/command_help.py @@ -7,14 +7,14 @@ import random import utilities_script as utilities -class CommandChyron(AbstractCommand, metaclass=ABCMeta): +class Command_Help(AbstractCommand, metaclass=ABCMeta): """ this is the help command. """ command = "help" def __init__(self): - super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis) + super().__init__(Command_Help.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis) self.help = ["This is a command to learn more about other commands.", "\nExample:","help \"COMMAND\""] self.isCommandEnabled = True @@ -35,7 +35,7 @@ class CommandChyron(AbstractCommand, metaclass=ABCMeta): bot.return_message(returnMessage) elif i == 1: commandsList = "\n" + self.blockDecor + "Commands List:" + self.blockDecor + self.GetCommandsList(bot) + self.blockDecor - print(commandsList) + bot.return_message(commandsList) def GetCommandsList(self, bot): commandsList = "" diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py index 25d754a..f4202c4 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -24,19 +24,19 @@ class CommandLights_Praxis(AbstractCommand, metaclass=ABCMeta): if tempBool == True: LightModule = lights_module.Lights_Module() LightModule.main() - #print("\nRGB Command Detected!") + #bot.return_message("\nRGB Command Detected!") tempParsedMessage = user_message.message.split(" ") sceneCommand = False if (len(tempParsedMessage)) > 2: - print("RGB Command!") + bot.return_message("RGB 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") + #bot.return_message("got XY") LightModule.bridge_.set_group(16, "xy", xy_result) - print("sent color to [Lights_Module]") + bot.return_message("sent color to [Lights_Module]") else: if "stream" in tempParsedMessage: sceneCommand = True @@ -57,16 +57,16 @@ class CommandLights_Praxis(AbstractCommand, metaclass=ABCMeta): sceneCommand = True LightModule.raveMode() else: - print("Color Command!") + bot.return_message("Color Command!") xy_result = LightModule.color_string_parser(tempParsedMessage) - #print("got XY") + #bot.return_message("got XY") LightModule.bridge_.set_group(16, "xy", xy_result) - print("sent color to [Lights_Module]") + bot.return_message("sent color to [Lights_Module]") if sceneCommand == True: - print("Scene Command!") + bot.return_message("Scene Command!") - returnMessage = "@" + user_message.user + " changed the light's color!" + returnMessage = "@" + user_message.user.name + " changed the light's color!\n" bot.return_message(returnMessage) def get_help(self): @@ -132,7 +132,7 @@ class CommandLights_Twitch(AbstractCommand, metaclass=ABCMeta): if sceneCommand == True: print("Scene Command!") - returnMessage = "@" + twitch_message.sender + " changed the light's color!" + returnMessage = "@" + twitch_message.sender + " changed the light's color!\n" bot.send_message(returnMessage) def get_help(self): diff --git a/lights_module.py b/lights_module.py index 4fb9d08..9e5fa9d 100644 --- a/lights_module.py +++ b/lights_module.py @@ -14,7 +14,7 @@ class Lights_Module(): self.bridge_:Bridge = Bridge('192.168.191.146') def main(self): - print("Starting up [Lights_Module]...") + print("\nStarting up [Lights_Module]...") self.bridge_.connect() self.bridge_.get_api() diff --git a/user_module.py b/user_module.py index 11e862f..1454e52 100644 --- a/user_module.py +++ b/user_module.py @@ -23,24 +23,20 @@ class User_Module(): UserFlagTypes.REACTIVE: self.eval_commands_Special_Reactive} self.currentUser:User = User() + self.inputLoop = True def main(self): time.sleep(.01) print("\nWaiting on User input...\n\n") - inputLoop = True if utility.isRunningInDocker() == True: - inputLoop = False + self.inputLoop = False print("\nNo User's Input Allowed") - while inputLoop: + + while self.inputLoop: keyboardInput = input() message = UserMessage() message.makeMessage(self.currentUser, keyboardInput) - if "exit" in keyboardInput: - print("Quitting [User Module] Interface...") - inputLoop = False - break - self.parseInput(message) def parseInput(self, message):