async def remove(self, ctx:commands.Context, trigger:str): """command_remove_help""" trigger = trigger.lower() trigger = await Utils.clean(trigger) if len(trigger) > 20: await MessageUtils.send_to(ctx, 'WHAT', 'custom_command_trigger_too_long') elif trigger in self.commands[ctx.guild.id]: CustomCommand.get(serverid = ctx.guild.id, trigger=trigger).delete_instance() del self.commands[ctx.guild.id][trigger] await ctx.send(f"{Emoji.get_chat_emoji('YES')} {Translator.translate('custom_command_removed', ctx.guild.id, trigger=trigger)}") else: await ctx.send(f"{Emoji.get_chat_emoji('NO')} {Translator.translate('custom_command_not_found', ctx.guild.id, trigger=trigger)}")
async def remove(self, ctx: commands.Context, trigger: str): """Removes a custom command""" trigger = trigger.lower() if trigger in self.commands[ctx.guild.id]: CustomCommand.get(serverid=ctx.guild.id, trigger=trigger).delete_instance() del self.commands[ctx.guild.id][trigger] await ctx.send( f"{Emoji.get_chat_emoji('YES')} {Translator.translate('custom_command_removed', ctx.guild.id, trigger=trigger)}" ) else: await ctx.send( f"{Emoji.get_chat_emoji('NO')} {Translator.translate('custom_command_not_found', ctx.guild.id, trigger=trigger)}" )
async def create(self, ctx: commands.Context, trigger: str, *, reply: str = None): """command_create_help""" if len(trigger) == 0: await ctx.send( f"{Emoji.get_chat_emoji('WHAT')} {Translator.translate('custom_command_empty_trigger', ctx.guild.id)}" ) elif reply is None or reply == "": await ctx.send( f"{Emoji.get_chat_emoji('WHAT')} {Translator.translate('custom_command_empty_reply', ctx.guild.id)}" ) elif len(trigger) > 20: await MessageUtils.send_to(ctx, 'WHAT', 'custom_command_trigger_too_long') else: trigger = trigger.lower() trigger = await Utils.clean(trigger) command = CustomCommand.get_or_none(serverid=ctx.guild.id, trigger=trigger) if command is None: CustomCommand.create(serverid=ctx.guild.id, trigger=trigger, response=reply) self.commands[ctx.guild.id][trigger] = reply await ctx.send( f"{Emoji.get_chat_emoji('YES')} {Translator.translate('custom_command_added', ctx.guild.id, trigger=trigger)}" ) else: async def yes(): await ctx.send( Translator.translate('updating', ctx.guild.id)) await ctx.invoke(self.update, trigger, reply=reply) async def no(): await ctx.send( Translator.translate('custom_command_not_updating', ctx.guild.id)) await Confirmation.confirm( ctx, Translator.translate( 'custom_command_override_confirmation', ctx.guild.id), on_yes=yes, on_no=no)
async def reloadCommands(self): for guild in self.bot.guilds: self.commands[guild.id] = dict() for command in CustomCommand.select().where( CustomCommand.serverid == guild.id): self.commands[guild.id][command.trigger] = command.response self.loaded = True
async def update(self, ctx: commands.Context, trigger: str, *, reply: str = None): """command_update_help""" trigger = trigger.lower() trigger = await Utils.clean(trigger) if reply is None: await ctx.send( f"{Emoji.get_chat_emoji('NO')} {Translator.translate('custom_command_empty_reply', ctx)}" ) else: command = CustomCommand.get_or_none(serverid=ctx.guild.id, trigger=trigger) if command is None: await ctx.send( f"{Emoji.get_chat_emoji('WARNING')} {Translator.translate('custom_command_creating', ctx.guild.id)}" ) await ctx.invoke(self.create, trigger, reply=reply) else: command.response = reply command.save() self.commands[ctx.guild.id][trigger] = reply await ctx.send( f"{Emoji.get_chat_emoji('YES')} {Translator.translate('custom_command_updated', ctx.guild.id, trigger=trigger)}" )
async def reloadCommands(self): while not self.bot.STARTUP_COMPLETE: await asyncio.sleep(1) for guild in self.bot.guilds: self.commands[guild.id] = dict() for command in CustomCommand.select().where( CustomCommand.serverid == guild.id): self.commands[guild.id][command.trigger] = command.response
async def on_guild_remove(self, guild): del self.commands[guild.id] for command in CustomCommand.select().where( CustomCommand.serverid == guild.id): command.delete_instance()