Skip to content

Commit

Permalink
refactor: just use already-determined context
Browse files Browse the repository at this point in the history
  • Loading branch information
AstreaTSS committed Apr 23, 2024
1 parent 0a9a2a1 commit acde6fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
3 changes: 2 additions & 1 deletion interactions/ext/hybrid_commands/context.py
Expand Up @@ -140,8 +140,9 @@ def from_prefixed_context(cls, ctx: prefixed.PrefixedContext) -> Self:
self = cls(ctx.client)

if ctx.channel.type == 1: # dm
# note that prefixed cmds for dms cannot be used outside of bot dms
self.context = ContextType.BOT_DM
elif ctx.channel.type == 3: # group dm
elif ctx.channel.type == 3: # group dm - technically not possible but just in case
self.context = ContextType.PRIVATE_CHANNEL
else:
self.context = ContextType.GUILD
Expand Down
6 changes: 1 addition & 5 deletions interactions/ext/hybrid_commands/hybrid_slash.py
Expand Up @@ -50,11 +50,7 @@ def generate_contexts_check(contexts: list[ContextType | int]) -> Callable[["Hyb
set_contexts = frozenset(contexts)

async def _contexts_check(ctx: "HybridContext") -> bool:
if ctx.guild_id:
return ContextType.GUILD in set_contexts
if ctx.channel.type == 1 and ctx.channel.recipient.id == ctx.bot.user.id:
return ContextType.BOT_DM in set_contexts
return ContextType.PRIVATE_CHANNEL in set_contexts
return ctx.context in set_contexts

return _contexts_check # type: ignore

Expand Down

0 comments on commit acde6fc

Please sign in to comment.