From 6b5683f61569c5604d3496ca696c694dd8b8e86e Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 30 Apr 2021 17:02:46 -0400 Subject: [PATCH] twitch tts --- config.py | 10 ++---- standalone_twitch_script.py | 67 ++++++++++++++++++++++++++++++++----- 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/config.py b/config.py index 53d5f28..7284d53 100644 --- a/config.py +++ b/config.py @@ -19,18 +19,14 @@ adminUsers_List =["thecuriousnerd", "<@76078763984551936>"] block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels blockAll_TwitchChatChannelsMessaging = False # Blocks the ability to send messages to twitch channels +autoEnabled_TwitchTTS = False # Enables TTS for ALL +autoEnabled_TwitchTTS_SpeakersList_Only = False # Enables TTS for Allowed TTS List Only #OLD CONFIGS WILL BE DELETED SOON -#autoEnabled_TwitchChannelsTTS = False #block_TwitchChannelsTTS = [""] # block supersedes the tts_enabled bool #blockAll_TwitchChatChannelsTTS = False # blockAll supersedes the force bool and force list and tts_enabled bool #force_TwitchChannelsTTS = [""] # force supersedes the block list #forceAll_TwitchChatChannelsTTS = False # forceAll supersedes the blockAll bool and block list and force list -#OLD CONFIGS WILL BE DELETED SOON -#blockAll_TTS_URL_Twitch = True - -autoEnabled_Twitch_rgbLightControl = False - #OLD CONFIGS WILL BE DELETED SOON #twitch_defaultCommandEnabledState = True #twitch_defaultCommandEnabledState_liveStreamOnly = True # If true this will make commands only available during live streams. @@ -48,8 +44,6 @@ blockAll_DiscordChannelsTTS = False # blockAll supersedes the force bool and for force_DiscordChannelsTTS = [""] # force supersedes the block list forceAll_DiscordChatChannelsTTS = False # forceAll supersedes the blockAll bool and block list and force list -blockAll_TTS_URL_Discord = True - #OLD CONFIGS WILL BE DELETED SOON #autoEnabled_Discord_rgbLightControl = False #discord_defaultCommandEnabledState = True diff --git a/standalone_twitch_script.py b/standalone_twitch_script.py index e5e02fd..78c3215 100644 --- a/standalone_twitch_script.py +++ b/standalone_twitch_script.py @@ -35,8 +35,6 @@ class Twitch_Module(): self.cooldownModule: Cooldown_Module = Cooldown_Module() self.cooldownModule.setupCooldown("twitchChat", 20, 32) - self.allow_rgbLightControl = config.autoEnabled_Twitch_rgbLightControl - def join_channel(self, credential: credentials.Twitch_Credential, channel_name: str): channel_name = "#" + channel_name print("Connecting to Channel: " + channel_name + "...") @@ -72,6 +70,16 @@ class Twitch_Module(): # print("Sent ChatMSG") self.cooldownModule.actionTrigger("twitchChat") + def eval_command(self, message): + command, rest = utility.parse_line(message.text) + try: + is_actionable = self.is_command(command) + if is_actionable: + if self.cooldownModule.isCooldownActive("twitchChat") == False: + self.exec_command(message ,command, rest) + except: + print("something went wrong with a command") + def is_command(self, word: str) -> bool: # todo need to url-escape word clean_param = urlencode({'name': word}) @@ -100,6 +108,45 @@ class Twitch_Module(): # todo handle failed requests pass + def eval_tts(self, message: twitch.chat.Message): + command, rest = utility.parse_line(message.text) + try: + is_actionable = self.is_command(command) + if not is_actionable: + self.exec_tts(message) + except: + print("something went wrong with tts") + + def exec_tts(self, message: twitch.chat.Message): + + if config.autoEnabled_TwitchTTS: + if config.autoEnabled_TwitchTTS_SpeakersList_Only: + tempName = message.sender.lower() + if tempName in config.allowedTTS_List: + text_to_say: str = "%s says, %s" % (message.sender, message.text) + self.exec_tts_sender("", text_to_say) + else: + text_to_say: str = "%s says, %s" % (message.sender, message.text) + self.exec_tts_sender("", text_to_say) + + + + def exec_tts_sender(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 send_whisper(self, user, message): pass @@ -110,13 +157,15 @@ class Twitch_Module(): praxis_logger_obj.log("\n[#" + message.channel + "](" + message.sender + ")> " + message.text) - try: - is_actionable = self.is_command(command) - if is_actionable: - if self.cooldownModule.isCooldownActive("twitchChat") == False: - self.exec_command(message ,command, rest) - except: - print("something went wrong with a command") + self.eval_command(message) + self.eval_tts(message) + #try: + # is_actionable = self.is_command(command) + # if is_actionable: + # if self.cooldownModule.isCooldownActive("twitchChat") == False: + # self.exec_command(message ,command, rest) + #except: + # print("something went wrong with a command") def isChannel_inConfigList(self, selectedChannel, selectedList): # print(channel)