(LionCog): Split check types.

This commit is contained in:
2024-09-08 16:17:34 +10:00
parent b7e4acfee2
commit 99bb1958a8

View File

@@ -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