Пример #1
0
def dash_index():
    if g.user:
        if g.user.admin:
            stats = json.loads(rdb.get('web:dashboard:stats') or '{}')

            if not stats or 'refresh' in request.args:
                stats['messages'] = pretty_number(Message.select().count())
                stats['guilds'] = pretty_number(Guild.select().count())
                stats['users'] = pretty_number(User.select().count())
                stats['channels'] = pretty_number(Channel.select().count())

                rdb.setex('web:dashboard:stats', json.dumps(stats), 300)

            guilds = Guild.select().order_by(Guild.guild_id)
        else:
            stats = {}
            guilds = Guild.select(
                Guild, Guild.config['web'][str(g.user.user_id)].alias('role')
            ).where(
                (Guild.enabled == 1) &
                (~(Guild.config['web'][str(g.user.user_id)] >> None))
            )

        return render_template(
            'dashboard.html',
            stats=stats,
            guilds=guilds,
        )
    return render_template('login.html')
Пример #2
0
def stats():
    stats = json.loads(rdb.get('web:dashboard:stats') or '{}')

    if not stats or 'refresh' in request.args:
        # stats['messages'] = pretty_number(Message.select().count())
        # stats['guilds'] = pretty_number(Guild.select().count())
        # stats['users'] = pretty_number(User.select().count())
        # stats['channels'] = pretty_number(Channel.select().count())
        stats['messages'] = Message.select().count()
        stats['guilds'] = Guild.select().count()
        stats['users'] = User.select().count()
        stats['channels'] = Channel.select().count()

        rdb.setex('web:dashboard:stats', json.dumps(stats), 300)

    return jsonify(stats)
Пример #3
0
    def encode_message_json(msg):
        try:
            channel_name = Channel.select(Channel.name).where(
                Channel.channel_id == msg.channel_id).tuples()[0][0]
        except IndexError:
            channel_name = None

        return dict(id=str(msg.id),
                    timestamp=str(msg.timestamp),
                    author_id=str(msg.author.id),
                    channel=channel_name,
                    channel_id=str(msg.channel_id),
                    username=msg.author.username,
                    discriminator=str(msg.author.discriminator).zfill(4),
                    content=msg.content,
                    deleted=msg.deleted,
                    attachments=msg.attachments)