-
Notifications
You must be signed in to change notification settings - Fork 24
/
Utils.py
76 lines (64 loc) · 2.77 KB
/
Utils.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
import io
import discord
from discord.ext import commands
async def send_code_block_maybe_as_file(ctx, text):
"""
Sends a code block to the current context.
If it's too long to fit in a single message, it will
instead be sent as a file.
"""
if len(text) > 2000:
file = io.StringIO()
file.writelines(text)
file.seek(0)
await ctx.send(file=discord.File(file, filename="agenda.md"))
else:
await ctx.send(f"```{text}```")
class CustomHelp(commands.DefaultHelpCommand): # ( ͡° ͜ʖ ͡°)
"""Custom help command"""
async def send_bot_help(self, mapping):
"""Shows a list of commands"""
embed = discord.Embed(title="Commands Help")
embed.colour = discord.Colour.blurple()
for cog, commands in mapping.items():
command_signatures = [self.get_command_signature(c) for c in commands]
if command_signatures:
cog_name = getattr(cog, "qualified_name", "No Category")
embed.add_field(
name=cog_name, value="\n".join(command_signatures), inline=False
)
channel = self.get_destination()
await channel.send(embed=embed)
async def send_command_help(self, command):
"""Shows how to use each command"""
embed_command = discord.Embed(
title=self.get_command_signature(command), description=command.help
)
embed_command.colour = discord.Colour.green()
channel = self.get_destination()
await channel.send(embed=embed_command)
async def send_group_help(self, group: commands.Group):
"""Shows how to use each group of commands"""
embed_group = discord.Embed(
title=self.get_command_signature(group), description=group.short_doc
)
for c in group.walk_commands():
embed_group.add_field(name=c, value=c.short_doc, inline=False)
embed_group.colour = discord.Colour.yellow()
channel = self.get_destination()
await channel.send(embed=embed_group)
async def send_cog_help(self, cog):
"""Shows how to use each category"""
embed_cog = discord.Embed(title=cog.qualified_name, description=cog.description)
comms = cog.get_commands()
for c in comms:
embed_cog.add_field(name=c, value=c.short_doc, inline=False)
embed_cog.colour = discord.Colour.green()
channel = self.get_destination()
await channel.send(embed=embed_cog)
async def send_error_message(self, error):
"shows if command does not exist"
embed_error = discord.Embed(title="Error", description=error)
embed_error.colour = discord.Colour.red()
channel = self.get_destination()
await channel.send(embed=embed_error)