add client to context
This commit is contained in:
parent
cbfae4ad86
commit
4a821aa168
@ -9,10 +9,11 @@ usertype = Union[discord.abc.User, discord.user.BaseUser, discord.Member, discor
|
||||
|
||||
|
||||
class Context:
|
||||
def __init__(self, message: discord.Message):
|
||||
def __init__(self, message: discord.Message, client: discord.Client):
|
||||
self.message: discord.Message = message
|
||||
self.client: discord.Client = client
|
||||
self.channel: discord.abc.Messageable = message.channel
|
||||
self.dm_or_text: Union[discord.DMChannel, discord.TextChannel] = message.channel
|
||||
self.dm_or_text: Union[discord.DMChannel, discord.TextChannel] = message.channel # type: ignore
|
||||
self.author: usertype = message.author
|
||||
self.content: str = message.content
|
||||
self.member: Optional[discord.Member] = message.author if isinstance(message.author, discord.Member) else None
|
||||
|
@ -4,12 +4,12 @@ from v6d2ctx.context import Context, Implicit, Explicit
|
||||
from v6d2ctx.handle_command import handle_command
|
||||
|
||||
|
||||
async def handle_args(message: discord.Message, args: list[str]):
|
||||
async def handle_args(message: discord.Message, args: list[str], client: discord.Client):
|
||||
match args:
|
||||
case []:
|
||||
return
|
||||
case [command_name, *command_args]:
|
||||
ctx = Context(message)
|
||||
ctx = Context(message, client)
|
||||
try:
|
||||
await handle_command(ctx, command_name, command_args)
|
||||
except Implicit:
|
||||
|
@ -5,11 +5,11 @@ import discord
|
||||
from v6d2ctx.handle_args import handle_args
|
||||
|
||||
|
||||
async def handle_content(message: discord.Message, content: str, prefix: str):
|
||||
async def handle_content(message: discord.Message, content: str, prefix: str, client: discord.Client):
|
||||
if message.author.bot:
|
||||
return
|
||||
if not content.startswith(prefix):
|
||||
return
|
||||
content = content.removeprefix(prefix)
|
||||
args = shlex.split(content)
|
||||
await handle_args(message, args)
|
||||
await handle_args(message, args, client)
|
||||
|
Loading…
Reference in New Issue
Block a user