diff --git a/channel_rewards/implemented/ChannelReward_Hydration.py b/channel_rewards/implemented/ChannelReward_Hydration.py index 747e0b7..7579170 100644 --- a/channel_rewards/implemented/ChannelReward_Hydration.py +++ b/channel_rewards/implemented/ChannelReward_Hydration.py @@ -27,7 +27,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): #print("sending:",user, 16, "!lights hydration") try: if self.is_ChannelReward_enabled: - thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) + thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights hydration", "")) thread_.daemon = True self.threads.append(thread_) thread_.start() @@ -42,7 +42,7 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): return None - def dothething(self, username, light_group, command, rest): + 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 diff --git a/channel_rewards/implemented/ChannelReward_RubiksCube.py b/channel_rewards/implemented/ChannelReward_RubiksCube.py index be0950d..920b775 100644 --- a/channel_rewards/implemented/ChannelReward_RubiksCube.py +++ b/channel_rewards/implemented/ChannelReward_RubiksCube.py @@ -24,11 +24,11 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): - #self.dothething(user, 16, "!lights rubikscube", "") + #self.send_Lights_Command(user, 16, "!lights rubikscube", "") try: if self.is_ChannelReward_enabled: - thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights rubikscube", "")) + thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights rubikscube", "")) thread_.daemon = True self.threads.append(thread_) thread_.start() @@ -43,7 +43,7 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): return None - def dothething(self, username, light_group, command, rest): + 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 diff --git a/channel_rewards/implemented/ChannelReward_twitchBits.py b/channel_rewards/implemented/ChannelReward_twitchBits.py index fafbeb0..f73e069 100644 --- a/channel_rewards/implemented/ChannelReward_twitchBits.py +++ b/channel_rewards/implemented/ChannelReward_twitchBits.py @@ -27,7 +27,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta): #print("sending:",user, 16, "!lights hydration") try: #if self.is_ChannelReward_enabled: - #thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) + #thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights hydration", "")) #thread_.daemon = True #self.threads.append(thread_) #thread_.start() @@ -41,7 +41,7 @@ class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta): return None - def dothething(self, username, light_group, command, rest): + 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 diff --git a/channel_rewards/implemented/ChannelReward_twitchSubs.py b/channel_rewards/implemented/ChannelReward_twitchSubs.py index 67617b8..461d910 100644 --- a/channel_rewards/implemented/ChannelReward_twitchSubs.py +++ b/channel_rewards/implemented/ChannelReward_twitchSubs.py @@ -27,7 +27,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta): #print("sending:",user, 16, "!lights hydration") try: if self.is_ChannelReward_enabled: - thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights ravemode", "")) + thread_ = threading.Thread(target=self.send_Lights_Command, args=(user, 16, "!lights ravemode", "")) thread_.daemon = True self.threads.append(thread_) thread_.start() @@ -42,7 +42,7 @@ class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta): return None - def dothething(self, username, light_group, command, rest): + 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 diff --git a/commands/implemented/Command_lights_v2.py b/commands/implemented/Command_lights_v2.py index 78bb382..66e1fbd 100644 --- a/commands/implemented/Command_lights_v2.py +++ b/commands/implemented/Command_lights_v2.py @@ -31,20 +31,19 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta): praxis_logger_obj.log("\n Command>: " + command + rest) isTwitch = False - if source is not None and source == AbstractCommand.CommandSource.Twitch: - for user_ in config.allowedCommandsList_TwitchPowerUsers: - if user_.lower() == user.lower(): - praxis_logger_obj.log(user_) - praxis_logger_obj.log(user) - returnString = self.dothething(user, 16, command, rest) - isTwitch = True + if "Twitch" in source: + for name in config.allowedCommandsList_TwitchPowerUsers: + print(name) + tempName = user.lower() + if name == tempName: + returnString = self.send_Lights_Command(user, 16, command, rest) + else: + returnString = self.send_Lights_Command(user, 16, command, rest) - if isTwitch == False: - returnString = self.dothething(user, 16, command, rest) return returnString - def dothething(self, username, light_group, command, rest): + 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 diff --git a/commands/implemented/Command_tts_v2.py b/commands/implemented/Command_tts_v2.py new file mode 100644 index 0000000..6d59239 --- /dev/null +++ b/commands/implemented/Command_tts_v2.py @@ -0,0 +1,75 @@ +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_tts_v2(AbstractCommand, metaclass=ABCMeta): + """ + this is the test command. + """ + command = "!tts" + + def __init__(self): + super().__init__(Command_tts_v2.command, n_args=1, command_type=AbstractCommand.CommandType.Ver2) + self.help = ["This command allows you to do tts.", + "\nExample:","tts \"TEXT\""] + self.isCommandEnabled = True + + def do_command(self, source = AbstractCommand.CommandSource.default, user:str = "User", command = "", rest = "", bonusData = None): + returnString = "" + praxis_logger_obj.log("\n Command>: " + command + rest) + + for name in config.allowedCommandsList_TwitchPowerUsers: + print(name) + tempName = user.lower() + if name == tempName: + self.send_TTS(user, 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:42069/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 send_TTS(self, username, message): + params = urlencode({'tts_sender': username, 'tts_text': message}) + #standalone_tts_core + url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%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 + pass + + def get_help(self): + return self.help \ No newline at end of file diff --git a/config.py b/config.py index e0562d9..c35c3bb 100644 --- a/config.py +++ b/config.py @@ -10,7 +10,7 @@ user_module: bool = True autoJoin_TwitchChannel = "thecuriousnerd" autoJoin_TwitchChannels = ["thecuriousnerd"] -allowedCommandsList_TwitchPowerUsers = ["thecuriousnerd"] +allowedCommandsList_TwitchPowerUsers = ["thecuriousnerd", "lakotor", "blastofcynicism"] #Twitch Module Configs block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels diff --git a/standalone_channelrewards.py b/standalone_channelrewards.py index 34db99a..ebed9e5 100644 --- a/standalone_channelrewards.py +++ b/standalone_channelrewards.py @@ -49,9 +49,11 @@ def handle_reward(source, username, reward_name, reward_type, rewardPrompt, user try: tempType = reward_type.replace('ChannelRewardsType.', '') realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType] + tempSource = source.replace('ChannelRewardsSource.', '') + realSource = AbstractChannelRewards.ChannelRewardsSource.__dict__[tempSource] reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name] if reward is not None: - reward_response = reward.do_ChannelReward(source, username, reward_name, rewardPrompt, userInput, bonusData) + reward_response = reward.do_ChannelReward(realSource, username, reward_name, rewardPrompt, userInput, bonusData) return flask.make_response("{\"message\":\"%s\"}" % reward_response, 200, {"Content-Type": "application/json"}) except: return flask.make_response("This is a magic test", 500) diff --git a/standalone_command.py b/standalone_command.py index 527cfb8..24ad1a4 100644 --- a/standalone_command.py +++ b/standalone_command.py @@ -44,6 +44,8 @@ def handle_command(source, username, command, rest, bonusData): #print(message) return flask.make_response("{\"message\":\"%s\"}" % message, 200, {"Content-Type": "application/json"}) + tempSource = source.replace('CommandSource.', '') + realSource = AbstractCommand.CommandSource.__dict__[tempSource] cmd:AbstractCommand = loadedCommands[command] if cmd is not None: cmd_response = cmd.do_command(source, username, command, rest, bonusData) diff --git a/standalone_twitch_script.py b/standalone_twitch_script.py index 56c5dd4..e5e02fd 100644 --- a/standalone_twitch_script.py +++ b/standalone_twitch_script.py @@ -81,7 +81,13 @@ class Twitch_Module(): def exec_command(self, realMessage: twitch.chat.Message, command: str, rest: str): # todo need to url-escape command and rest - params = urlencode({'command_source': commands.command_base.AbstractCommand.CommandSource.Twitch,'user_name': realMessage.sender, 'command_name': command, 'rest': rest, 'bonus_data': realMessage}) + params = urlencode( + {'command_source': commands.command_base.AbstractCommand.CommandSource.Twitch, + 'user_name': realMessage.sender, + 'command_name': command, + 'rest': rest, + 'bonus_data': realMessage}) + url = "http://standalone_command:6009/api/v1/exec_command?%s" % params resp = requests.get(url) if resp.status_code == 200: