diff --git a/bot.py b/bot.py index 6f7b2e4..b3f3089 100755 --- a/bot.py +++ b/bot.py @@ -21,9 +21,20 @@ class Bot(commands.AutoShardedBot): description=self.config.get('description', ''), **kwargs) + self._setup_success_emojis() + for cog in self.config['cogs']: self.load_extension(cog) + def _setup_success_emojis(self): + """Load the emojis from the config to be used when a command fails or succeeds + We do it this way so that they can be used anywhere instead of requiring a bot instance. + """ + import utils.misc + default = ('❌', '✅') + utils.SUCCESS_EMOJIS = utils.misc.SUCCESS_EMOJIS = ( + self.config.get('response_emojis', {}).get('success', default)) + def run(self): super().run(self.config['tokens'].pop('discord')) diff --git a/cogs/emote.py b/cogs/emote.py index d83379a..054870f 100644 --- a/cogs/emote.py +++ b/cogs/emote.py @@ -65,7 +65,7 @@ class Emotes: if isinstance(error, commands.NoPrivateMessage): await context.send( - f'{utils.SUCCESS_EMOTES[False]} Sorry, this command may only be used in a server.') + f'{utils.SUCCESS_EMOJIS[False]} Sorry, this command may only be used in a server.') @commands.command() async def add(self, context, *args): @@ -220,7 +220,7 @@ class Emotes: for emote in emotes: await context.invoke(self.remove, emote) with contextlib.suppress(discord.HTTPException): - await context.message.add_reaction('✅') + await context.message.add_reaction(utils.SUCCESS_EMOJIS[True]) @commands.command(aliases=('mv',)) async def rename(self, context, old, new_name): diff --git a/cogs/meta.py b/cogs/meta.py index 06f1710..19cb178 100644 --- a/cogs/meta.py +++ b/cogs/meta.py @@ -32,10 +32,10 @@ class Meta: try: await context.author.send(self.bot.config['support_server_invite']) with contextlib.suppress(discord.HTTPException): - await context.message.add_reaction('📬') + await context.message.add_reaction('📬') # TODO make this emoji configurable too except discord.Forbidden: with contextlib.suppress(discord.HTTPException): - await context.message.add_reaction('❌') + await context.message.add_reaction(utils.SUCCESS_EMOJIS[True]) await context.send('Unable to send invite in DMs. Please allow DMs from server members.') def setup(bot): diff --git a/config.example.py b/config.example.py index 22517e4..b22a2d8 100644 --- a/config.example.py +++ b/config.example.py @@ -27,4 +27,17 @@ 'user_agent': 'EmojiManagerBot (https://github.com/bmintz/emoji-manager-bot)', 'ec_api_url': 'https://emoji-connoisseur.python-for.life/api/v0', + + # emotes that the bot may use to respond to you + # If not provided, the bot will use ('❌', '✅') instead. + # + # You can obtain these ones from the discordbots.org server under the name "tickNo" and "tickYes" + # but I uploaded them to my test server + # so that both the staging and the stable versions of the bot can use them + 'response_emotes': { + 'success': { # emotes used to indicate success or failure + False: '<:error:478164511879069707>', + True: '<:success:478164452261363712>' + }, + }, } diff --git a/utils/errors.py b/utils/errors.py index 35d5667..b3a323f 100644 --- a/utils/errors.py +++ b/utils/errors.py @@ -11,7 +11,7 @@ class MissingManageEmojisPermission(commands.MissingPermissions): def __init__(self): super(Exception, self).__init__( - f'{utils.SUCCESS_EMOTES[False]} ' + f'{utils.SUCCESS_EMOJIS[False]} ' "Sorry, you don't have enough permissions to run this command. " 'You and I both need the Manage Emojis permission.') diff --git a/utils/misc.py b/utils/misc.py index b2a27a0..e4b5e69 100644 --- a/utils/misc.py +++ b/utils/misc.py @@ -5,11 +5,6 @@ import discord """various utilities for use within the bot""" -"""Emotes used to indicate success/failure. You can obtain these from the discordbots.org guild, -but I uploaded them to my test server -so that both the staging and the stable versions of the bot can use them""" -SUCCESS_EMOTES = ('<:error:416845770239508512>', '<:success:416845760810844160>') - def format_user(bot, id, *, mention=False): """Format a user ID for human readable display.""" user = bot.get_user(id)