1
|
|
|
# Copyright Pincer 2021-Present |
|
|
|
|
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root. |
3
|
|
|
|
4
|
|
|
from __future__ import annotations |
5
|
|
|
|
6
|
|
|
from abc import ABC, abstractmethod |
7
|
|
|
from typing import TYPE_CHECKING, Type, TypeVar |
8
|
|
|
|
9
|
|
|
if TYPE_CHECKING: |
10
|
|
|
from typing import Any, Awaitable, Callable |
11
|
|
|
|
12
|
|
|
T = TypeVar("T") |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
class PartialInteractable(ABC): |
16
|
|
|
""" |
17
|
|
|
Represents a command or message component to be registered to a class. |
18
|
|
|
|
19
|
|
|
Parameters |
20
|
|
|
---------- |
21
|
|
|
func : Callable[..., Awaitable[Any]] |
22
|
|
|
The function to run for this interaction. |
23
|
|
|
args : Any |
24
|
|
|
Args to be stored to used in register. |
25
|
|
|
kwargs : Any |
26
|
|
|
Kwargs to store to be used in register. |
27
|
|
|
""" |
28
|
|
|
|
29
|
|
|
def __init__(self, func: Callable[..., Awaitable[Any]], *args: Any, **kwargs: Any): |
30
|
|
|
self.func = func |
31
|
|
|
self.args = args |
32
|
|
|
self.kwargs = kwargs |
33
|
|
|
|
34
|
|
|
def __call__(self, *args: Any, **kwds: Any) -> Any: |
35
|
|
|
return self.func.__call__(*args, **kwds) |
36
|
|
|
|
37
|
|
|
@abstractmethod |
38
|
|
|
def register(self, manager: Any) -> Type[T]: |
39
|
|
|
"""Registers a command to a command handler to be called later""" |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
class Interactable: |
43
|
|
|
""" |
44
|
|
|
Class that can register :class:`~pincer.commands.interactable.PartialInteractable` |
45
|
|
|
objects. Any class that subclasses this class can register Application Commands and |
46
|
|
|
Message Components. |
47
|
|
|
""" |
48
|
|
|
def __init__(self): |
49
|
|
|
for key, value in type(self).__dict__.items(): |
50
|
|
|
if isinstance(value, PartialInteractable): |
51
|
|
|
setattr(self, key, value.register(self)) |
52
|
|
|
|