| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- """
- Rocketbot Discord bot. Relies on a configured config.py (copy config.py.sample
- for a template).
-
- Author: Ian Albert (@rocketsoup)
- Date: 2021-11-11
- """
- import traceback
- from discord import Intents
- from discord.ext import commands
-
- from config import CONFIG
- from rocketbot.cogs.autokickcog import AutoKickCog
- from rocketbot.cogs.configcog import ConfigCog
- from rocketbot.cogs.crosspostcog import CrossPostCog
- from rocketbot.cogs.generalcog import GeneralCog
- from rocketbot.cogs.joinagecog import JoinAgeCog
- from rocketbot.cogs.joinraidcog import JoinRaidCog
- from rocketbot.cogs.patterncog import PatternCog
- from rocketbot.cogs.urlspamcog import URLSpamCog
- from rocketbot.cogs.usernamecog import UsernamePatternCog
-
- CURRENT_CONFIG_VERSION = 3
- if (CONFIG.get('__config_version') or 0) < CURRENT_CONFIG_VERSION:
- # If you're getting this error, it means something changed in config.py's
- # format. Consult config.py.sample and compare it to your own config.py.
- # Rename/move any values as needed. When satisfied, update "__config_version"
- # to the value in config.py.sample.
- raise RuntimeError('config.py format may be outdated. Review ' +
- 'config.py.sample, update the "__config_version" field to ' +
- f'{CURRENT_CONFIG_VERSION}, and try again.')
-
- class Rocketbot(commands.Bot):
- """
- Bot subclass
- """
- def __init__(self, command_prefix, **kwargs):
- super().__init__(command_prefix, **kwargs)
-
- async def on_command_error(self, context: commands.Context, exception):
- if context.guild is None or \
- context.message.channel is None or \
- context.message.author.bot:
- return
- if not context.message.author.permissions_in(context.message.channel).ban_members:
- # Don't tell non-mods about errors
- return
- if isinstance(exception, (commands.errors.CommandError, )):
- # Reply with the error message for ordinary command errors
- await context.message.reply(
- f'{CONFIG["failure_emoji"]} {exception}',
- mention_author=False)
- return
- # Stack trace everything else
- traceback.print_exception(type(exception), exception, exception.__traceback__)
-
- intents = Intents.default()
- intents.messages = True # pylint: disable=assigning-non-slot
- intents.members = True # pylint: disable=assigning-non-slot
- bot = Rocketbot(command_prefix=CONFIG['command_prefix'], intents=intents)
-
- # Core
- bot.add_cog(GeneralCog(bot))
- bot.add_cog(ConfigCog(bot))
-
- # Optional
- bot.add_cog(AutoKickCog(bot))
- bot.add_cog(CrossPostCog(bot))
- bot.add_cog(JoinAgeCog(bot))
- bot.add_cog(JoinRaidCog(bot))
- bot.add_cog(PatternCog(bot))
- bot.add_cog(URLSpamCog(bot))
- bot.add_cog(UsernamePatternCog(bot))
-
- bot.run(CONFIG['client_token'], bot=True, reconnect=True)
- print('\nBot aborted')
|