From 99bb1958a8e64fc42973b5ec5a38c950fe4e9b9d Mon Sep 17 00:00:00 2001 From: Interitio Date: Sun, 8 Sep 2024 16:17:34 +1000 Subject: [PATCH] (LionCog): Split check types. --- src/meta/LionCog.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/meta/LionCog.py b/src/meta/LionCog.py index 75eea8dc..bc28f7c5 100644 --- a/src/meta/LionCog.py +++ b/src/meta/LionCog.py @@ -3,6 +3,7 @@ from typing import Any, Callable, Optional from discord.ext.commands import Cog from discord.ext import commands as cmds +from twitchio.ext import commands from twitchio.ext.commands import Command, Bot from twitchio.ext.commands.meta import CogEvent @@ -73,6 +74,24 @@ class LionCog(Cog): return CogEvent(name=event_name, func=func, module=cls.__module__) return decorator + async def cog_check(self, ctx): # type: ignore + """ + TwitchIO assumes cog_check is a coroutine, + so here we narrow the check to only a coroutine. + + The ctx maybe either be a twitch command context or a dpy context. + """ + if isinstance(ctx, cmds.Context): + return await self.cog_check_discord(ctx) + if isinstance(ctx, commands.Context): + return await self.cog_check_twitch(ctx) + + async def cog_check_discord(self, ctx: cmds.Context): + return True + + async def cog_check_twitch(self, ctx: commands.Context): + return True + @classmethod def placeholder_group(cls, group: cmds.HybridGroup): group._placeholder_group_ = True