-
Notifications
You must be signed in to change notification settings - Fork 0
/
help_command.py
170 lines (147 loc) · 6.14 KB
/
help_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""
███╗ ███╗ █████╗ ██╗
████╗ ████║██╔══██╗██║
██╔████╔██║███████║██║
██║╚██╔╝██║██╔══██║██║
██║ ╚═╝ ██║██║ ██║██║
╚═╝ ╚═╝╚═╝ ╚═╝╚═╝
Made With ❤️ By Ghoul & Nerd
"""
import datetime
import re
from datetime import timedelta
from typing import Any, List, Literal, Mapping, Optional
import discord
import humanize
from discord import Embed
from discord.ext import commands
from config.ext.parser import config
from helpers.constants import *
from helpers.custommeta import CustomCog
class MaiHelpCommand(commands.HelpCommand):
def command_not_found(self, string: str) -> str:
return f"{Emoji.ERROR} The command `{self.context.clean_prefix}{string}` was not found!, If you would like this command to be added suggest it in our [support server]({Links.SUPPORT_SERVER_INVITE})"
def subcommand_not_found(self, command: commands.Command, string: str) -> str:
return f"{Emoji.ERROR} I don't have the command `{command.qualified_name} {string}`, If you would like this command to be added suggest it in our [support server]({Links.SUPPORT_SERVER_INVITE})"
async def dispatch_help(self, help_embed: Embed) -> None:
dest: discord.abc.MessageableChannel = self.get_destination()
await dest.send(embed=help_embed)
async def send_error_message(self, error: str) -> None:
embed: Embed = Embed(
title="Error :\\", description=f"{error}", color=Colors.ERROR
)
await self.dispatch_help(embed)
async def send_bot_help(
self, mapping: Mapping[Optional[CustomCog], List[commands.Command]]
) -> None:
bot = self.context.bot
embed: Embed = Embed(
description=f"{Emoji.CHECKMARK} **Here are all my modules!**",
color=Colors.DEFAULT,
)
embed.set_author(
name=bot.user.name,
icon_url=Links.BOT_AVATAR_URL,
url=Links.BOT_DOCUMENTATION_URL,
)
embed.set_thumbnail(url=Links.BOT_AVATAR_URL)
embed.set_footer(
text=f"Requested By {self.context.author.name}",
icon_url=self.context.author.avatar.url,
)
usable_commands = await self.filter_commands(
self.context.bot.commands, sort=True
)
usable_cogs = {
command.cog for command in usable_commands if command.cog is not None
}
for cog in usable_cogs:
embed.add_field(
name=f"{cog.emoji} {cog.qualified_name}",
value=f"`{self.context.clean_prefix}help {cog.qualified_name}`",
)
await self.dispatch_help(embed)
async def send_command_help(self, command: commands.Command) -> None:
embed: Embed = Embed(title=f"Help For: `{command.name}`", color=Colors.DEFAULT)
embed.add_field(
name=f"{Emoji.QUESTION} What does this command do?",
value=command.description
if command.description is not None
else "No Description",
inline=False,
)
embed.add_field(
name="Usage",
value=f"`{self.get_command_signature(command)}`",
inline=False,
)
examples = command.extras["Examples"]
if examples:
has_examples: Literal[True] = True
else:
has_examples: Literal[True] = False
if command.extras["Notes"]:
has_notes: Literal[True] = True
else:
has_notes: Literal[True] = False
if has_examples:
embed.add_field(name="Examples", value=f"`{examples}`", inline=False)
if has_notes:
embed.add_field(name="Extra Notes", value=command.extras["Notes"])
has_cooldown: bool = command._buckets._cooldown is not None
if has_cooldown:
delta: timedelta = datetime.timedelta(
seconds=command._buckets._cooldown.per
)
cooldown: str = humanize.precisedelta(delta, format="%0.0f")
embed.add_field(name="Cooldown", value=f"`{cooldown}`", inline=False)
else:
embed.add_field(name="Cooldown", value=f"`0` (No Cooldown)", inline=False)
await self.dispatch_help(embed)
async def send_group_help(self, group: commands.Group) -> None:
embed: Embed = Embed(
title=f"Help For Command: `{group.name}`", color=Colors.DEFAULT
)
embed.add_field(
name=f"{Emoji.QUESTION} What does this command do?",
value=group.description
if group.description is not None
else "No Description",
inline=False,
)
embed.add_field(
name="Usage",
value=f"`{self.get_command_signature(group)}`",
inline=False,
)
subcommand_help: List[str] = [
f"**`{self.get_command_signature(command)}`**\n{command.description}"
for command in group.commands
]
newline: Literal["\n"] = "\n"
embed.add_field(
name="Related commands",
value=f"\n{newline.join(subcommand_help)}",
inline=False,
)
await self.dispatch_help(embed)
async def send_cog_help(self, cog: CustomCog) -> None:
embed: Embed = Embed(
title=f"Help For Module: {cog.emoji} `{cog.qualified_name}`",
color=Colors.DEFAULT,
)
embed.add_field(
name=f"{Emoji.QUESTION} What does this category do?",
value=cog.description if cog.description is not None else "No Description",
inline=False,
)
for command in cog.walk_commands():
if command.parent is None:
embed.add_field(
name=f"`{self.context.clean_prefix}{command.name}`",
value=command.description
if command.description is not None
else "No Command Description",
inline=False,
)
await self.dispatch_help(embed)