pincer.commands.groups   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 16
dl 0
loc 80
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Subgroup.__hash__() 0 2 1
A Group.__hash__() 0 2 1
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
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
            async 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[:class:`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
36
    name: str
37
    description: Optional[str] = None
38
39
    def __hash__(self) -> int:
40
        return hash(self.name)
41
42
43
@dataclass
44
class Subgroup:
45
    """
46
    A subgroup of commands. This allows you to create subcommands inside a
47
    subcommand-group.
48
49
    .. code-block:: python
50
51
        class Bot:
52
53
            group = Group("cool_commands")
54
            sub_group = Subgroup("group_of_cool_commands")
55
56
            @command(parent=sub_group)
57
            async def a_very_cool_command():
58
                pass
59
60
    This code creates a command called ``cool_commands`` with the subcommand-group
61
    ``group_of_cool_commands`` that has the subcommand ``a_very_cool_command``.
62
63
    Parameters
64
    ----------
65
    name : str
66
        The name of the command sub-group.
67
    parent : :class:`~pincer.commands.groups.Group`
68
        The parent group of this command.
69
    description : Optional[:class:`str`]
70
        The description of the command. This has to be sent to Discord, but it does
71
        nothing, so it is optional.
72
    """
73
74
    name: str
75
    parent: Group
76
    description: Optional[str] = None
77
78
    def __hash__(self) -> int:
79
        return hash(self.name)
80