EveCogs/userslash/channel.py
everestmcarthur 8858470392 feat: add UserSlash cog — user-installable slash commands for every Red command
Replaces OneTrueSlash with full user-install support:
- Single proxy slash command bridges all text commands
- Works in servers, DMs, and group DMs
- REST API patcher sets integration_types & contexts on all global commands
- Owner commands: [p]userslash sync/patch/status
- Fuzzy autocomplete (rapidfuzz)
- Enhanced InterContext/InterMessage for non-guild contexts
2026-05-14 20:14:33 +00:00

50 lines
1.4 KiB
Python

"""
InterChannel — thin overlay that routes ``send`` / ``typing`` / ``permissions_for``
through the slash-interaction context instead of the regular channel object.
"""
from typing import TYPE_CHECKING, Union, cast
import discord
from .utils import Thinking, contexts
if TYPE_CHECKING:
from discord.context_managers import Typing
Base = discord.abc.Messageable
else:
Base = object
class InterChannel(Base):
"""Mixed into the real channel class at runtime so existing code keeps working."""
__slots__ = ()
def permissions_for(
self, obj: Union[discord.abc.User, discord.Role], /
) -> discord.Permissions:
try:
ctx = contexts.get()
except LookupError:
pass
else:
interaction = ctx._interaction
bot_user = cast(discord.ClientUser, ctx.bot.user)
if obj.id == interaction.user.id:
return ctx.permissions
elif obj.id == bot_user.id:
return ctx.bot_permissions
return super().permissions_for(obj) # type: ignore
def send(self, *args, **kwargs):
return contexts.get(super()).send(*args, **kwargs)
def typing(self) -> Union[Thinking, "Typing"]:
try:
ctx = contexts.get()
except LookupError:
return super().typing()
else:
return Thinking(ctx)