Ejemplo n.º 1
0
    def search(self, event, query):
        queries = []

        if query.isdigit():
            queries.append((User.user_id == query))

        q = USER_MENTION_RE.findall(query)
        if len(q) and q[0].isdigit():
            queries.append((User.user_id == q[0]))
        else:
            queries.append(
                (User.username**u'%{}%'.format(query.replace('%', ''))))

        if '#' in query:
            username, discrim = query.rsplit('#', 1)
            if discrim.isdigit():
                queries.append(((User.username == username) &
                                (User.discriminator == int(discrim))))

        users = User.select().where(reduce(operator.or_, queries))
        if len(users) == 0:
            return event.msg.reply(u'No users found for query `{}`'.format(
                S(query, escape_codeblocks=True)))

        if len(users) == 1:
            if users[0].user_id in self.state.users:
                return self.info(event, self.state.users.get(users[0].user_id))

        return event.msg.reply(
            u'Found the following users for your query: ```{}```'.format(
                u'\n'.join(
                    map(lambda i: u'{} ({})'.format(unicode(i), i.user_id),
                        users[:25]))))
Ejemplo n.º 2
0
    def search(self, event, query: str):
        queries = []

        if query.isdigit():
            queries.append((User.user_id == query))

        q = USER_MENTION_RE.findall(query)
        if len(q) and q[0].isdigit():
            queries.append((User.user_id == q[0]))
        else:
            queries.append(
                (User.username**'%{}%'.format(query.replace('%', ''))))

        if '#' in query:
            username, discrim = query.rsplit('#', 1)
            if discrim is not None:
                queries.append(((User.username == username) &
                                (User.discriminator == discrim)))

        users = User.select().where(reduce(operator.or_, queries)).limit(10)
        if len(users) == 0:
            raise CommandFail('No users found for query `{}`'.format(
                S(query, escape_codeblocks=True)))

        if len(users) == 1:
            if users[0].user_id in self.state.users:
                return self.info(event, self.state.users.get(users[0].user_id))

        raise CommandSuccess(
            'Found the following users for your query: ```{}```'.format(
                '\n'.join([
                    '{} ({})'.format(str(i), i.user_id) for i in users[:25]
                ])))
Ejemplo n.º 3
0
def search_users(query=None):
    queries = []

    if query.isdigit():
        queries.append((User.user_id == query))

    q = USER_MENTION_RE.findall(query)
    if len(q) and q[0].isdigit():
        ids = []
        ids.append(q[0])
        return ids
    else:
        queries.append((User.username**u'%{}%'.format(query.replace('%', ''))))

    if '#' in query:
        username, discrim = query.rsplit('#', 1)
        if discrim.isdigit():
            queries.append(((User.username == username) &
                            (User.discriminator == int(discrim))))

    users = User.select().where(reduce(operator.or_, queries))
    if len(users) == 0:
        return []

    return map(lambda i: i.user_id, users[:25])
Ejemplo n.º 4
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')
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
 def is_global_admin(self, userid):
     global_admin = rdb.sismember('global_admins', userid)
     _usr = User.select().where(User.user_id == userid)
     if len(_usr) == 1:
         global_admin = _usr[0].admin
     return global_admin