-
-
Notifications
You must be signed in to change notification settings - Fork 192
/
Copy pathdata.py
67 lines (53 loc) · 2.27 KB
/
data.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
import discord
import os
from utils import permissions, default
from utils.config import Config
from discord.ext.commands import AutoShardedBot, DefaultHelpCommand
class DiscordBot(AutoShardedBot):
def __init__(self, config: Config, prefix: list[str] = None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.prefix = prefix
self.config = config
async def setup_hook(self):
for file in os.listdir("cogs"):
if not file.endswith(".py"):
continue # Skip non-python files
name = file[:-3]
await self.load_extension(f"cogs.{name}")
async def on_message(self, msg: discord.Message):
if not self.is_ready() or msg.author.bot or \
not permissions.can_handle(msg, "send_messages"):
return
await self.process_commands(msg)
async def process_commands(self, msg):
ctx = await self.get_context(msg, cls=default.CustomContext)
await self.invoke(ctx)
class HelpFormat(DefaultHelpCommand):
def get_destination(self, no_pm: bool = False):
if no_pm:
return self.context.channel
else:
return self.context.author
async def send_error_message(self, error: str) -> None:
""" Sends an error message to the destination. """
destination = self.get_destination(no_pm=True)
await destination.send(error)
async def send_command_help(self, command) -> None:
""" Sends the help for a single command. """
self.add_command_formatting(command)
self.paginator.close_page()
await self.send_pages(no_pm=True)
async def send_pages(self, no_pm: bool = False) -> None:
""" Sends the help pages to the destination. """
try:
if permissions.can_handle(self.context, "add_reactions"):
await self.context.message.add_reaction(chr(0x2709))
except discord.Forbidden:
pass
try:
destination = self.get_destination(no_pm=no_pm)
for page in self.paginator.pages:
await destination.send(page)
except discord.Forbidden:
destination = self.get_destination(no_pm=True)
await destination.send("Couldn't send help to you due to blocked DMs...")