|
| 1 | +import discord |
| 2 | + |
| 3 | +from utils import permissions |
| 4 | +from discord.ext.commands import AutoShardedBot, DefaultHelpCommand |
| 5 | + |
| 6 | + |
| 7 | +class Bot(AutoShardedBot): |
| 8 | + def __init__(self, *args, prefix=None, **kwargs): |
| 9 | + super().__init__(*args, **kwargs) |
| 10 | + self.prefix = prefix |
| 11 | + |
| 12 | + async def on_message(self, msg): |
| 13 | + if not self.is_ready() or msg.author.bot or not permissions.can_handle(msg, "send_messages"): |
| 14 | + return |
| 15 | + |
| 16 | + await self.process_commands(msg) |
| 17 | + |
| 18 | + |
| 19 | +class HelpFormat(DefaultHelpCommand): |
| 20 | + def get_destination(self, no_pm: bool = False): |
| 21 | + if no_pm: |
| 22 | + return self.context.channel |
| 23 | + else: |
| 24 | + return self.context.author |
| 25 | + |
| 26 | + async def send_error_message(self, error): |
| 27 | + destination = self.get_destination(no_pm=True) |
| 28 | + await destination.send(error) |
| 29 | + |
| 30 | + async def send_command_help(self, command): |
| 31 | + self.add_command_formatting(command) |
| 32 | + self.paginator.close_page() |
| 33 | + await self.send_pages(no_pm=True) |
| 34 | + |
| 35 | + async def send_pages(self, no_pm: bool = False): |
| 36 | + try: |
| 37 | + if permissions.can_handle(self.context, "add_reactions"): |
| 38 | + await self.context.message.add_reaction(chr(0x2709)) |
| 39 | + except discord.Forbidden: |
| 40 | + pass |
| 41 | + |
| 42 | + try: |
| 43 | + destination = self.get_destination(no_pm=no_pm) |
| 44 | + for page in self.paginator.pages: |
| 45 | + await destination.send(page) |
| 46 | + except discord.Forbidden: |
| 47 | + destination = self.get_destination(no_pm=True) |
| 48 | + await destination.send("Couldn't send help to you due to blocked DMs...") |
0 commit comments