Esempio n. 1
0
    def on_commands_info(self, event, mid):
        cmd = Command.select(Command, Message, Channel).join(
            Message,
            on=(Command.message_id == Message.id).alias('message')).join(
                Channel,
                on=(Channel.channel_id == Message.channel_id).alias('channel')
            ).join(
                User,
                on=(User.user_id == Message.author_id).alias('author')).where(
                    Command.message_id == mid).order_by(
                        Message.timestamp.desc(), ).get()

        embed = MessageEmbed()
        embed.title = '{}.{} ({})'.format(cmd.plugin, cmd.command,
                                          cmd.message.id)
        embed.set_author(name=str(cmd.message.author),
                         icon_url=cmd.message.author.get_avatar_url())
        embed.color = 0x77dd77 if cmd.success else 0xff6961

        if not cmd.success:
            embed.description = '```{}```'.format(cmd.traceback)

        embed.add_field(name='Message', value=cmd.message.content)
        embed.add_field(name='Channel',
                        value='{} `{}`'.format(cmd.message.channel.name,
                                               cmd.message.channel.channel_id))
        embed.add_field(name='Guild', value=str(cmd.message.guild_id))
        event.msg.reply(embed=embed)
Esempio n. 2
0
    def on_commands_stats(self, event, name):
        if '.' in name:
            plugin, command = name.split('.', 1)
            q = (
                (Command.plugin == plugin) &
                (Command.command == command)
            )
        else:
            q = (Command.command == name)

        result = list(Command.select(
            fn.COUNT('*'),
            Command.success,
        ).where(q).group_by(Command.success).order_by(fn.COUNT('*').desc()).tuples())

        success, error = 0, 0
        for count, check in result:
            if check:
                success = count
            else:
                error = count

        event.msg.reply('Command `{}` was used a total of {} times, {} of those had errors'.format(
            name,
            success + error,
            error
        ))
Esempio n. 3
0
    def on_commands_errors(self, event):
        q = Command.select().join(Message,
                                  on=(Command.message_id == Message.id)).where(
                                      Command.success == 0).order_by(
                                          Message.timestamp.desc()).limit(10)

        tbl = MessageTable()
        tbl.set_header('ID', 'Command', 'Error')

        for err in q:
            tbl.add(err.message_id, '{}.{}'.format(err.plugin, err.command),
                    err.traceback.split('\n')[-2])

        event.msg.reply(tbl.compile())
Esempio n. 4
0
    def on_commands_usage(self, event):
        q = Command.select(
            fn.COUNT('*'),
            Command.plugin,
            Command.command,
        ).group_by(Command.plugin,
                   Command.command).order_by(fn.COUNT('*').desc()).limit(25)

        tbl = MessageTable()
        tbl.set_header('Plugin', 'Command', 'Usage')

        for count, plugin, command in q.tuples():
            tbl.add(plugin, command, count)

        event.msg.reply(tbl.compile())