|
1
|
|
|
# Copyright Pincer 2021-Present |
|
|
|
|
|
|
2
|
|
|
# Full MIT License can be found in `LICENSE` at the project root. |
|
3
|
|
|
|
|
4
|
|
|
from dataclasses import dataclass |
|
5
|
|
|
from typing import Optional |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
@dataclass |
|
9
|
|
|
class Group: |
|
10
|
|
|
""" |
|
11
|
|
|
The group object represents a group that commands can be in. This is always a top |
|
12
|
|
|
level command. |
|
13
|
|
|
|
|
14
|
|
|
.. code-block:: python |
|
15
|
|
|
|
|
16
|
|
|
class Bot: |
|
17
|
|
|
|
|
18
|
|
|
group = Group("cool_commands") |
|
19
|
|
|
|
|
20
|
|
|
@command(parent=group) |
|
21
|
|
|
def a_very_cool_command(): |
|
22
|
|
|
pass |
|
23
|
|
|
|
|
24
|
|
|
This code creates a command called ``cool_commands`` with the subcommand |
|
25
|
|
|
``a_very_cool_command`` |
|
26
|
|
|
|
|
27
|
|
|
Parameters |
|
28
|
|
|
---------- |
|
29
|
|
|
name : str |
|
30
|
|
|
The name of the command group. |
|
31
|
|
|
description : Optional[str] |
|
32
|
|
|
The description of the command. This has to be sent to Discord but it does |
|
33
|
|
|
nothing so it is optional. |
|
34
|
|
|
""" |
|
35
|
|
|
name: str |
|
36
|
|
|
description: Optional[str] = None |
|
37
|
|
|
|
|
38
|
|
|
def __hash__(self): |
|
39
|
|
|
return hash(self.name) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
@dataclass |
|
43
|
|
|
class Subgroup: |
|
44
|
|
|
""" |
|
45
|
|
|
A subgroup of commands. This allows you to create subcommands inside of a |
|
46
|
|
|
subcommand-group. |
|
47
|
|
|
|
|
48
|
|
|
.. code-block:: python |
|
49
|
|
|
|
|
50
|
|
|
class Bot: |
|
51
|
|
|
|
|
52
|
|
|
group = Group("cool_commands") |
|
53
|
|
|
sub_group = Subgroup("group_of_cool_commands") |
|
54
|
|
|
|
|
55
|
|
|
@command(parent=sub_group) |
|
56
|
|
|
def a_very_cool_command(): |
|
57
|
|
|
pass |
|
58
|
|
|
|
|
59
|
|
|
This code creates a command called ``cool_commands`` with the subcommand-group |
|
60
|
|
|
``group_of_cool_commands`` that has the subcommand ``a_very_cool_command``. |
|
61
|
|
|
|
|
62
|
|
|
Parameters |
|
63
|
|
|
---------- |
|
64
|
|
|
name : str |
|
65
|
|
|
The name of the command sub-group. |
|
66
|
|
|
parent : :class:`~pincer.commands.groups.Group` |
|
67
|
|
|
The parent group of this command. |
|
68
|
|
|
description : Optional[str] |
|
69
|
|
|
The description of the command. This has to be sent to Discord but it does |
|
70
|
|
|
nothing so it is optional. |
|
71
|
|
|
""" |
|
72
|
|
|
name: str |
|
73
|
|
|
parent: Group |
|
74
|
|
|
description: Optional[str] = None |
|
75
|
|
|
|
|
76
|
|
|
def __hash__(self) -> int: |
|
77
|
|
|
return hash(self.name) |
|
78
|
|
|
|