Passed
Pull Request — main (#297)
by
unknown
01:50
created

pincer.commands.groups   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Group.__hash__() 0 2 1
A Subgroup.__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
    name: str
36
    description: Optional[str] = None
37
38
    def __hash__(self) -> int:
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 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
            async 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[:class:`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