diff --git a/docs/changelog.rst b/docs/changelog.rst index 7a7c7ae7..7a773eeb 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,5 +1,12 @@ :orphan: +Master +====== +- TwitchIO + - Bug fixes + - Fix IndexError when getting prefix when empty message is sent in a reply. + + 2.7.0 ====== - TwitchIO diff --git a/twitchio/ext/commands/bot.py b/twitchio/ext/commands/bot.py index 17f0a74c..11840b5d 100644 --- a/twitchio/ext/commands/bot.py +++ b/twitchio/ext/commands/bot.py @@ -173,7 +173,9 @@ async def get_prefix(self, message): prefixes = await self.__get_prefixes__(message) message_content = message.content if "reply-parent-msg-id" in message.tags: - message_content = message_content.split(" ", 1)[1] + message_content = " ".join(message.content.split(" ")[1:]) + else: + message_content = message.content if not isinstance(prefixes, str): for prefix in prefixes: if message_content.startswith(prefix): diff --git a/twitchio/ext/commands/core.py b/twitchio/ext/commands/core.py index 57556545..4e4c519c 100644 --- a/twitchio/ext/commands/core.py +++ b/twitchio/ext/commands/core.py @@ -201,8 +201,6 @@ async def invoke(self, context: Context, *, index=0) -> None: # TODO Docs if not context.view: return - args, kwargs = await self.parse_args(context, self._instance, context.view.words, index=index) - context.args, context.kwargs = args, kwargs async def try_run(func, *, to_command=False): try: @@ -213,6 +211,17 @@ async def try_run(func, *, to_command=False): else: context.bot.run_event("command_error", context, _e) + try: + args, kwargs = await self.parse_args(context, self._instance, context.view.words, index=index) + except (MissingRequiredArgument, BadArgument) as e: + if self.event_error: + args_ = [self._instance, context] if self._instance else [context] + await try_run(self.event_error(*args_, e)) + + context.bot.run_event("command_error", context, e) + return + + context.args, context.kwargs = args, kwargs check_result = await self.handle_checks(context) if check_result is not True: diff --git a/twitchio/ext/routines/__init__.py b/twitchio/ext/routines/__init__.py index 92b14d85..89d4867c 100644 --- a/twitchio/ext/routines/__init__.py +++ b/twitchio/ext/routines/__init__.py @@ -360,7 +360,9 @@ async def _routine(self, *args, **kwargs) -> None: if self._remaining_iterations == 0: self._remaining_iterations = self._iterations + iteration: int = 0 while True: + iteration += 1 start = datetime.datetime.now(datetime.timezone.utc) try: @@ -387,7 +389,7 @@ async def _routine(self, *args, **kwargs) -> None: break if self._time: - sleep = compute_timedelta(self._time + datetime.timedelta(days=self._completed_loops)) + sleep = compute_timedelta(self._time + datetime.timedelta(days=iteration)) else: sleep = max((start - datetime.datetime.now(datetime.timezone.utc)).total_seconds() + self._delta, 0)