From d346b18794133a9f87ed42b81c3860193e02b275 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 14 May 2021 16:04:43 -0400 Subject: [PATCH] Create Command_opensource_v2.py --- commands/implemented/Command_opensource_v2.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 commands/implemented/Command_opensource_v2.py diff --git a/commands/implemented/Command_opensource_v2.py b/commands/implemented/Command_opensource_v2.py new file mode 100644 index 0000000..e91d9e5 --- /dev/null +++ b/commands/implemented/Command_opensource_v2.py @@ -0,0 +1,64 @@ +from abc import ABCMeta + +from commands.command_base import AbstractCommand + +from json import loads +from urllib.parse import urlencode +import requests + +import config + +import os +import praxis_logging +praxis_logger_obj = praxis_logging.praxis_logger() +praxis_logger_obj.init(os.path.basename(__file__)) +praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__)) + +class Command_opensource_v2(AbstractCommand, metaclass=ABCMeta): + """ + this is the lights command. + """ + command = "!opensource" + + def __init__(self): + super().__init__(Command_opensource_v2.command, n_args=1, command_type=AbstractCommand.CommandType.Ver2) + self.help = ["This command educates about open source.", + "\nExample:","!opensource"] + self.isCommandEnabled = True + + def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None): + returnString = "" + praxis_logger_obj.log("\n Command>: " + command + rest) + isTwitch = False + + if "Twitch_ZZZ" in source: #temp changed for steam change back later + for name in config.allowedCommandsList_TwitchPowerUsers: + print(name) + tempName = user.lower() + if name == tempName: + returnString = self.send_Lights_Command(user, 16, "!lights", "red") + else: + returnString = self.send_Lights_Command(user, 16, command, rest) + + + return returnString + + def send_Lights_Command(self, username, light_group, command, rest): + # todo need to url-escape command and rest + params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) + #standalone_lights + url = "http://standalone_lights:42042/api/v1/exec_lights?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + return None + + def get_help(self): + return self.help \ No newline at end of file