mirror of
https://github.com/stoatchat/python-client-sdk.git
synced 2026-07-25 00:15:23 -04:00
add more attributes to context
This commit is contained in:
@@ -13,7 +13,7 @@ __all__ = (
|
||||
|
||||
class Context:
|
||||
"""Stores metadata the commands execution.
|
||||
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
command: Optional[:class:`Command`]
|
||||
@@ -22,16 +22,28 @@ class Context:
|
||||
The command name that was used, this can be an alias, the commands name or a command that doesnt exist
|
||||
message: :class:`Message`
|
||||
The message that was sent to invoke the command
|
||||
channel: :class:`Messageable`
|
||||
The channel the command was invoked in
|
||||
server: :class:`Server`
|
||||
The server the command was invoked in
|
||||
author: Union[:class:`Member`, :class:`User`]
|
||||
The user or member that invoked the commad, will be :class:`User` in DMs
|
||||
args: list[:class:`str`]
|
||||
The arguments being passed to the command
|
||||
"""
|
||||
__slots__ = ("command", "invoked_with", "message")
|
||||
__slots__ = ("command", "invoked_with", "args", "message", "server", "channel", "author")
|
||||
|
||||
def __init__(self, command: Optional[Command], invoked_with: str, message: revolt.Message):
|
||||
def __init__(self, command: Optional[Command], invoked_with: str, args: list[str], message: revolt.Message):
|
||||
self.command = command
|
||||
self.invoked_with = invoked_with
|
||||
self.args = args
|
||||
self.message = message
|
||||
self.server = message.server
|
||||
self.channel = message.channel
|
||||
self.author = message.author
|
||||
|
||||
async def invoke(self, args: list[str]) -> Any:
|
||||
"""Invokes the command, this is equal to `await context.command.invoke(context, args)`.
|
||||
async def invoke(self) -> Any:
|
||||
"""Invokes the command, this is equal to `await command.invoke(context, context.args)`.
|
||||
|
||||
.. note:: If the command is `None`, this function will do nothing.
|
||||
|
||||
@@ -41,7 +53,7 @@ class Context:
|
||||
The args being passed to the command
|
||||
"""
|
||||
if command := self.command:
|
||||
return await command.invoke(self, args)
|
||||
return await command.invoke(self, self.args)
|
||||
|
||||
@copy_doc(revolt.Messageable.send)
|
||||
async def send(self, content: Optional[str] = None, *, embeds: Optional[list[revolt.Embed]] = None, embed: Optional[revolt.Embed] = None, attachments: Optional[list[revolt.File]] = None) -> revolt.Message:
|
||||
|
||||
@@ -172,12 +172,12 @@ class CommandsMixin(metaclass=CommandsMeta):
|
||||
try:
|
||||
command = self.get_command(command_name)
|
||||
except KeyError:
|
||||
return self.dispatch("command_error", Context(None, command_name, message), CommandNotFound(command_name))
|
||||
return self.dispatch("command_error", Context(None, command_name, args, message), CommandNotFound(command_name))
|
||||
|
||||
context = self.get_context(message)(command, command_name, message)
|
||||
context = self.get_context(message)(command, command_name, args, message)
|
||||
|
||||
try:
|
||||
return await context.invoke(args)
|
||||
return await context.invoke()
|
||||
except Exception as e:
|
||||
self.dispatch("command_error", context, e)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user