From 5b2c7c0ee92972b48af60398f19f745b4b9ac245 Mon Sep 17 00:00:00 2001 From: dtookey Date: Fri, 2 Oct 2020 15:20:15 -0400 Subject: [PATCH] handled KeyError on unfound commands better command_text finding --- twitch_script.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/twitch_script.py b/twitch_script.py index 5ccaabd..5bbc0e0 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -68,12 +68,19 @@ class Twitch_Module(): def eval_commands(self, message: twitch.chat.Message): # containsURL: bool = self.contains_url(message) - command_text = message.text[0:message.text.index(' ')] - - command = self.commands[command_text] - if command is not None and command.command_type is AbstractCommand.CommandType.TWITCH: - command.do_command(self, message) + first_space_idx = message.text.index(' ') + command_text = ' ' + if first_space_idx > -1: + command_text = message.text[0:first_space_idx] + else: + command_text = message.text + try: + command = self.commands[command_text] + if command is not None and command.command_type is AbstractCommand.CommandType.TWITCH: + command.do_command(self, message) + except Exception as e: + pass # we don't care # if message.text.startswith('!tts start'): # print("tts activated on #" + message.channel) # self.send_message("tts activated")