From 5d97066b8b4b4598aa7b0ac75280c5c3501576fa Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 14 Oct 2020 04:11:37 -0400 Subject: [PATCH] Fixed No Substring/No Arguments Bug Fixed an error where if a command without arguments is sent it would fail. --- twitch_script.py | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/twitch_script.py b/twitch_script.py index 9b66bbc..50e1bce 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -71,7 +71,15 @@ class Twitch_Module(): def eval_commands(self, message: twitch.chat.Message): # containsURL: bool = self.contains_url(message) try: - first_space_idx = message.text.index(' ') + #first_space_idx = message.text.index(' ') + + # This fixes a error where if you send a command without arguments it fails because + # it cant find the substring. + if message.text.find(" ") != -1: + first_space_idx = message.text.index(' ') + else: + first_space_idx = -1 + command_text = ' ' if first_space_idx > -1: command_text = message.text[0:first_space_idx] @@ -82,29 +90,9 @@ class Twitch_Module(): if command is not None and command.command_type is AbstractCommand.CommandType.TWITCH: command.do_command(self, message) except Exception as e: + print(e) pass # we don't care - # if message.text.startswith('!tts start'): - # print("tts activated on #" + message.channel) - # self.send_message("tts activated") - # self.tts_enabled = True - # - # if message.text.startswith('!tts stop'): - # print("tts deactivated on #" + message.channel) - # self.send_message("tts deactivated") - # self.tts_enabled = False - # - # if message.text.startswith('!test'): - # print("!test Detected") - # message.chat.send("test acknowledged") - # # message.chat.send(f'@{message.user().display_name}, you have {message.user().view_count} views.') - - # if message.text.startswith('!roll'): - # try: - # pass - # #self.dice_roll(message) - # except Exception: - # self.send_message("{something went wrong}") - # print("{something went wrong}") + def tts_message(self, message: twitch.chat.Message): if not self.contains_slur(message):