예제 #1
0
 async def on_command_error(bot, ctx: commands.Context, error):
     if isinstance(error, commands.BotMissingPermissions):
         await ctx.send(error)
     elif isinstance(error, commands.CheckFailure):
         pass
     elif isinstance(error, commands.CommandOnCooldown):
         if ctx.command.name in ['krill']:
             # commands in this list have custom cooldown handler
             return
         await ctx.send(error)
     elif isinstance(error, commands.MaxConcurrencyReached):
         await ctx.send(f"Too many people are using the `{ctx.invoked_with}` command right now. Try again later")
     elif isinstance(error, commands.MissingRequiredArgument):
         param = list(ctx.command.params.values())[min(len(ctx.args) + len(ctx.kwargs), len(ctx.command.params))]
         bot.help_command.context = ctx
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} You are missing a required command argument: `{param._name}`\n{Emoji.get_chat_emoji('WRENCH')} Command usage: `{bot.help_command.get_command_signature(ctx.command)}`")
     elif isinstance(error, commands.BadArgument):
         param = list(ctx.command.params.values())[min(len(ctx.args) + len(ctx.kwargs), len(ctx.command.params))]
         bot.help_command.context = ctx
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} Failed to parse the ``{param._name}`` param: ``{error}``\n{Emoji.get_chat_emoji('WRENCH')} Command usage: `{bot.help_command.get_command_signature(ctx.command)}`")
     elif isinstance(error, commands.CommandNotFound):
         return
     elif isinstance(error, commands.UnexpectedQuoteError):
         bot.help_command.context = ctx
         await ctx.send(
             f"{Emoji.get_chat_emoji('NO')} There are quotes in there that I don't like\n{Emoji.get_chat_emoji('WRENCH')} Command usage: `{bot.help_command.get_command_signature(ctx.command)}`")
     else:
         await Utils.handle_exception("Command execution failed", bot,
                                      error.original if hasattr(error, "original") else error, ctx=ctx)
         # notify caller
         e = Emoji.get_chat_emoji('BUG')
         if ctx.channel.permissions_for(ctx.me).send_messages:
             await ctx.send(f"{e} Something went wrong while executing that command {e}")
예제 #2
0
    async def ping_unverified(self, ctx):
        guild = self.bot.get_guild(Configuration.get_var("guild_id"))
        try:
            nonmember_role = guild.get_role(
                Configuration.get_var("nonmember_role"))
            welcome_channel = self.bot.get_config_channel(
                guild.id, Utils.welcome_channel)
            rules_channel = self.bot.get_config_channel(
                guild.id, Utils.rules_channel)

            if welcome_channel and rules_channel:
                txt = Lang.get_string(
                    "welcome/welcome_msg",
                    user=nonmember_role.mention,
                    rules_channel=rules_channel.mention,
                    accept_emoji=Emoji.get_chat_emoji('CANDLE'))

                await nonmember_role.edit(mentionable=True)
                await welcome_channel.send(txt)
                await nonmember_role.edit(mentionable=False)
                return True
        except Exception as ex:
            Logging.info(f"failed to welcome unverified role.")
            Logging.error(ex)
            raise ex
        return False
예제 #3
0
    async def send_welcome(self, member):
        guild = self.bot.get_guild(Configuration.get_var("guild_id"))
        if member.guild.id != guild.id or self.is_member_verified(member):
            return False

        try:
            welcome_channel = self.bot.get_config_channel(
                guild.id, Utils.welcome_channel)
            rules_channel = self.bot.get_config_channel(
                guild.id, Utils.rules_channel)

            # Send welcome message in configured language. default to english
            if welcome_channel and rules_channel:
                txt = Lang.get_string(
                    "welcome/welcome_msg",
                    user=member.mention,
                    rules_channel=rules_channel.mention,
                    accept_emoji=Emoji.get_chat_emoji('PAINTBRUSH'))
                if self.mute_new_members:
                    # add mute notification if mute for new members is on
                    mute_txt = Lang.get_string("welcome/welcome_mute_msg")
                    txt = f"{txt}\n{mute_txt}"
                await welcome_channel.send(txt)
                return True
        except Exception as ex:
            Logging.info(f"failed to welcome {member.id}")
            Logging.error(ex)
            raise ex
        return False
예제 #4
0
 async def remove(self, ctx: commands.Context, *, word):
     """command_remove_help"""
     row = CountWord.get_or_none(serverid=ctx.guild.id, word=word)
     if row is not None:
         row.delete_instance()
         await self.startup_cleanup()
         emoji = Emoji.get_chat_emoji('YES')
         msg = Lang.get_locale_string('word_counter/word_removed',
                                      ctx,
                                      word=word)
     else:
         emoji = Emoji.get_chat_emoji('NO')
         msg = Lang.get_locale_string('word_counter/word_not_found',
                                      ctx,
                                      word=word)
     await ctx.send(f"{emoji} {msg}")
예제 #5
0
    async def send_response(ctx, emoji_name, lang_key, **kwargs):
        if 'trigger' in kwargs:
            kwargs['trigger'] = kwargs['trigger'].encode('utf-8').decode(
                'unicode-escape')

        msg = Lang.get_locale_string(f'custom_commands/{lang_key}', ctx,
                                     **kwargs)
        emoji = Emoji.get_chat_emoji(emoji_name)
        await ctx.send(f"{emoji} {msg}")
예제 #6
0
 async def add(self, ctx: commands.Context, *, word: str):
     """command_add_help"""
     row = CountWord.get_or_none(serverid=ctx.guild.id, word=word)
     if row is None:
         CountWord.create(serverid=ctx.guild.id, word=word)
         await self.startup_cleanup()
         emoji = Emoji.get_chat_emoji('YES')
         msg = Lang.get_locale_string('word_counter/word_added',
                                      ctx,
                                      word=word)
         await ctx.send(f"{emoji} {msg}")
     else:
         await ctx.send(
             Lang.get_locale_string('word_counter/word_found',
                                    ctx,
                                    word=word))
예제 #7
0
파일: journey.py 프로젝트: e-a-h/journeybot
    async def on_command_error(bot, ctx: commands.Context, error):
        if isinstance(error, commands.BotMissingPermissions):
            await ctx.send(error)
        elif isinstance(error, commands.CheckFailure):
            pass
        elif isinstance(error, commands.CommandOnCooldown):
            await ctx.send(error)
        elif isinstance(error, commands.MissingRequiredArgument):
            param = list(ctx.command.params.values())[min(
                len(ctx.args) + len(ctx.kwargs), len(ctx.command.params))]
            bot.help_command.context = ctx
            await ctx.send(
                f"{Emoji.get_chat_emoji('NO')} You are missing a required command argument: `{param._name}`\n{Emoji.get_chat_emoji('WRENCH')} Command usage: `{bot.help_command.get_command_signature(ctx.command)}`"
            )
        elif isinstance(error, commands.BadArgument):
            param = list(ctx.command.params.values())[min(
                len(ctx.args) + len(ctx.kwargs), len(ctx.command.params))]
            bot.help_command.context = ctx
            await ctx.send(
                f"{Emoji.get_chat_emoji('NO')} Failed to parse the ``{param._name}`` param: ``{error}``\n{Emoji.get_chat_emoji('WRENCH')} Command usage: `{bot.help_command.get_command_signature(ctx.command)}`"
            )
        elif isinstance(error, commands.CommandNotFound):
            return

        else:
            await Utils.handle_exception(
                "Command execution failed",
                bot,
                error.original if hasattr(error, "original") else error,
                ctx=ctx)
            # notify caller
            e = Emoji.get_chat_emoji('BUG')
            if ctx.channel.permissions_for(ctx.me).send_messages:
                await ctx.send(
                    f"{e} Something went wrong while executing that command {e}"
                )
예제 #8
0
    async def send_welcome(self, member):
        guild = self.bot.get_guild(Configuration.get_var("guild_id"))
        if member.guild.id != guild.id or self.is_member_verified(member):
            return False

        try:
            welcome_channel = self.bot.get_config_channel(
                guild.id, Utils.welcome_channel)
            rules_channel = self.bot.get_config_channel(
                guild.id, Utils.rules_channel)

            if welcome_channel and rules_channel:
                txt = Lang.get_string(
                    "welcome/welcome_msg",
                    user=member.mention,
                    rules_channel=rules_channel.mention,
                    accept_emoji=Emoji.get_chat_emoji('CANDLE'))
                await welcome_channel.send(txt)
                return True
        except Exception as ex:
            Logging.info(f"failed to welcome {member.id}")
            Logging.error(ex)
            raise ex
        return False