Ejemplo n.º 1
0
 def on_error(self, event, *args):
     ctx = args[0] if len(args) == 1 else None
     ctx_is_message = isinstance(ctx, discord.Message)
     error = sys.exc_info()[1]
     if ctx is None:
         yield from util.duelogger.error(
             ("**DueUtil experienced an error!**\n" +
              "__Stack trace:__ ```" + traceback.format_exc() + "```"))
         util.logger.error("None message/command error: %s", error)
     elif isinstance(error, util.DueUtilException):
         # A normal dueutil user error
         if error.channel is not None:
             yield from self.send_message(error.channel,
                                          error.get_message())
         else:
             yield from self.send_message(ctx.channel, error.get_message())
         return
     elif isinstance(error, util.DueReloadException):
         loader.reload_modules()
         yield from util.say(error.channel, loader.get_loaded_modules())
         return
     elif isinstance(error, discord.errors.Forbidden):
         if ctx_is_message:
             channel = ctx.channel
             if isinstance(error, util.SendMessagePermMissing):
                 util.logger.warning(
                     "Missing send permissions in channel %s (%s)",
                     channel.name, channel.id)
             else:
                 try:
                     # Attempt to warn user
                     yield from util.say(
                         channel,
                         "The action could not be performed as I'm **missing permissions**!"
                     )
                 except util.SendMessagePermMissing:
                     pass  # They've block sending messages too.
             return
     elif isinstance(error, discord.HTTPException):
         util.logger.error("Discord HTTP error: %s", error)
     elif isinstance(error, aiohttp.errors.ClientResponseError):
         if ctx_is_message:
             util.logger.error("%s: ctx from %s: %s", error, ctx.author.id,
                               ctx.content)
         else:
             util.logger.error(error)
     elif isinstance(error, RuntimeError) and ERROR_OF_DEATH in str(error):
         util.logger.critical(
             "Something went very wrong and the error of death came for us: %s",
             error)
         os._exit(1)
     elif ctx_is_message:
         yield from self.send_message(
             ctx.channel, (":bangbang: **Something went wrong...**"))
         trigger_message = discord.Embed(title="Trigger",
                                         type="rich",
                                         color=gconf.DUE_COLOUR)
         trigger_message.add_field(name="Message",
                                   value=ctx.author.mention + ":\n" +
                                   ctx.content)
         yield from util.duelogger.error(
             ("**Message/command triggred error!**\n" +
              "__Stack trace:__ ```" + traceback.format_exc()[-1500:] +
              "```"),
             embed=trigger_message)
     # Log exception on sentry.
     util.sentry_client.captureException()
     traceback.print_exc()
Ejemplo n.º 2
0
    async def on_error(self, event, *args):
        ctx = args[0] if len(args) == 1 else None
        ctx_is_message = isinstance(ctx, discord.Message)
        error = sys.exc_info()[1]
        if ctx is None:
            await util.duelogger.error(
                ("**BattleBanana experienced an error!**\n" +
                 "__Stack trace:__ ```" + traceback.format_exc() + "```"))
            util.logger.error("None message/command error: %s", error)
        elif isinstance(error, util.BattleBananaException):
            # A normal battlebanana user error
            try:
                if error.channel is not None:
                    await util.say(error.channel, error.get_message())
                else:
                    await util.say(ctx.channel, error.get_message())
            except:
                util.logger.warning("Unable to send Exception message")
            return
        elif isinstance(error, util.DueReloadException):
            loader.reload_modules()
            await util.say(error.channel, loader.get_loaded_modules())
            return
        elif isinstance(error, discord.Forbidden):
            if ctx_is_message:
                channel = ctx.channel
                if isinstance(error, util.SendMessagePermMissing):
                    util.logger.warning(
                        "Missing send permissions in channel %s (%s)",
                        channel.name, channel.id)
                else:
                    try:
                        # Attempt to warn user
                        perms = ctx.guild.me.permissions_in(ctx.channel)
                        await util.say(
                            ctx.channel,
                            "The action could not be performed as I'm **missing permissions**! Make sure I have the following permissions:\n"
                            + "- Manage Roles %s;\n" %
                            (":white_check_mark:" if perms.manage_roles else
                             ":x:") + "- Manage messages %s;\n" %
                            (":white_check_mark:" if perms.manage_messages else
                             ":x:") + "- Embed links %s;\n" %
                            (":white_check_mark:" if perms.embed_links else
                             ":x:") + "- Attach files %s;\n" %
                            (":white_check_mark:" if perms.attach_files else
                             ":x:") + "- Read Message History %s;\n" %
                            (":white_check_mark:" if perms.read_message_history
                             else ":x:") + "- Use external emojis %s;\n" %
                            (":white_check_mark:" if perms.external_emojis else
                             ":x:") + "- Add reactions%s" %
                            (":white_check_mark:"
                             if perms.add_reactions else ":x:"))
                    except util.SendMessagePermMissing:
                        pass  # They've block sending messages too.
                    except discord.Forbidden:
                        pass
                return
        elif isinstance(error, discord.HTTPException):
            util.logger.error("Discord HTTP error: %s", error)
            if ctx_is_message:
                await util.say(ctx.channel,
                               (":bangbang: **Something went wrong...**"))
                trigger_message = discord.Embed(title="Trigger",
                                                type="rich",
                                                color=gconf.DUE_COLOUR)
                trigger_message.add_field(name="Message",
                                          value=ctx.author.mention + ":\n" +
                                          ctx.content)
                await util.duelogger.error(
                    ("**Message/command triggred error!**\n" +
                     "__Stack trace:__ ```" + traceback.format_exc()[-1500:] +
                     "```"),
                    embed=trigger_message)

        elif isinstance(error,
                        (aiohttp.ClientResponseError, aiohttp.ClientOSError)):
            if ctx_is_message:
                util.logger.error("%s: ctx from %s: %s", error, ctx.author.id,
                                  ctx.content)
            else:
                util.logger.error(error)
        elif isinstance(error, RuntimeError) and ERROR_OF_DEATH in str(error):
            util.logger.critical(
                "Something went very wrong and the error of death came for us: %s",
                error)
            os._exit(1)
        elif ctx_is_message:
            await util.say(ctx.channel,
                           (":bangbang: **Something went wrong...**"))
            trigger_message = discord.Embed(title="Trigger",
                                            type="rich",
                                            color=gconf.DUE_COLOUR)
            trigger_message.add_field(name="Message",
                                      value=ctx.author.mention + ":\n" +
                                      ctx.content)
            await util.duelogger.error(
                ("**Message/command triggred error!**\n" +
                 "__Stack trace:__ ```" + traceback.format_exc()[-1500:] +
                 "```"),
                embed=trigger_message)
        # Log exception on sentry.
        util.sentry_client.captureException()
        traceback.print_exc()