make context generic over client

This commit is contained in:
Zomatree
2022-03-30 19:03:03 +01:00
parent 7f3253a3b5
commit 41eddffc1b
2 changed files with 7 additions and 4 deletions
+2 -1
View File
@@ -3,6 +3,7 @@ from __future__ import annotations
import traceback
import sys
from typing import Any, Union, Protocol, runtime_checkable, Optional, TYPE_CHECKING
from typing_extensions import Self
from importlib import import_module
import revolt
@@ -159,7 +160,7 @@ class CommandsClient(revolt.Client, metaclass=CommandsMeta):
def get_view(self, message: revolt.Message) -> type[StringView]:
return StringView
def get_context(self, message: revolt.Message) -> type[Context]:
def get_context(self, message: revolt.Message) -> type[Context[Self]]:
return Context
async def process_commands(self, message: revolt.Message) -> Any:
+5 -3
View File
@@ -1,6 +1,6 @@
from __future__ import annotations
from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar
import revolt
from revolt.utils import maybe_coroutine
@@ -12,11 +12,13 @@ if TYPE_CHECKING:
from .client import CommandsClient
from .view import StringView
ClientT = TypeVar("ClientT", bound="CommandsClient")
__all__ = (
"Context",
)
class Context(revolt.Messageable):
class Context(revolt.Messageable, Generic[ClientT]):
"""Stores metadata the commands execution.
Attributes
@@ -45,7 +47,7 @@ class Context(revolt.Messageable):
async def _get_channel_id(self) -> str:
return self.channel.id
def __init__(self, command: Optional[Command], invoked_with: str, view: StringView, message: revolt.Message, client: CommandsClient):
def __init__(self, command: Optional[Command], invoked_with: str, view: StringView, message: revolt.Message, client: ClientT):
self.command = command
self.invoked_with = invoked_with
self.view = view