Passed
Pull Request — main (#342)
by
unknown
01:38
created

pincer.commands.groups.SubGroup.__init__()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nop 4
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 typing import Optional
5
6
7
class Group:
8
    """
9
    The group object represents a group that commands can be in. This is always a top
10
    level command.
11
12
    .. code-block:: python
13
14
        class Bot:
15
16
            group = Group("cool_commands")
17
18
            @command(parent=group)
19
            def a_very_cool_command():
20
                pass
21
22
    This code creates a command called ``cool_commands`` with the subcommand
23
    ``a_very_cool_command``
24
25
    Parameters
26
    ----------
27
    name : str
28
        The name of the command group.
29
    description : Optional[str]
30
        The description of the command. This has to be sent to Discord but it does
31
        nothing so it is optional.
32
    """
33
34
    def __init__(self, name: str, description: Optional[str] = None):
35
        self.name = name
36
        self.description = description
37
38
    def __hash__(self):
39
        return hash(self.name)
40
41
42
class SubGroup:
43
    """
44
    A sub group of commands. This allows you to create subcommands inside of a
45
    subcommand-group.
46
47
    .. code-block:: python
48
49
        class Bot:
50
51
            group = Group("cool_commands")
52
            sub_group = SubGroup("group_of_cool_commands")
53
54
            @command(parent=sub_group)
55
            def a_very_cool_command():
56
                pass
57
58
    This code creates a command called ``cool_commands`` with the subcommand-group
59
    ``group_of_cool_commands`` that has the subcommand ``a_very_cool_command``.
60
61
    Parameters
62
    ----------
63
    name : str
64
        The name of the command sub-group.
65
    parent : :class:`~pincer.commands.groups.Group`
66
        The parent group of this command.
67
    description : Optional[str]
68
        The description of the command. This has to be sent to Discord but it does
69
        nothing so it is optional.
70
    """
71
72
    def __init__(self, name: str, parent: Group, description: Optional[str] = None):
73
        self.name = name
74
        self.parent = parent
75
        self.description = description
76
77
    def __hash__(self):
78
        return hash(self.name)
79