Пример #1
0
def get_online_embed_users(guild_id):
    usrs = get_online_embed_user_keys(guild_id)
    unauths = db.session.query(UnauthenticatedUsers).filter(
        UnauthenticatedUsers.user_key.in_(usrs["UnauthenticatedUsers"]),
        UnauthenticatedUsers.revoked == False, UnauthenticatedUsers.guild_id
        == guild_id).all() if usrs["UnauthenticatedUsers"] else []
    auths = db.session.query(AuthenticatedUsers).filter(
        AuthenticatedUsers.client_id.in_(
            usrs["AuthenticatedUsers"]), AuthenticatedUsers.guild_id
        == guild_id).all() if usrs["AuthenticatedUsers"] else []
    users = {'unauthenticated': [], 'authenticated': []}
    for user in unauths:
        meta = {
            'username': user.username,
            'discriminator': user.discriminator,
        }
        users['unauthenticated'].append(meta)
    for user in auths:
        client_id = user.client_id
        usrdb = db.session.query(GuildMembers).filter(
            GuildMembers.guild_id == guild_id).filter(
                GuildMembers.user_id == client_id).first()
        meta = {
            'id': str(usrdb.user_id),
            'username': usrdb.username,
            'nickname': usrdb.nickname,
            'discriminator': usrdb.discriminator,
            'avatar_url': generate_avatar_url(usrdb.user_id, usrdb.avatar),
        }
        users['authenticated'].append(meta)
    return users
Пример #2
0
def user_info(guild_id, user_id):
    usr = {
        "id": None,
        "username": None,
        "nickname": None,
        "discriminator": None,
        "avatar": None,
        "avatar_url": None,
        "roles": [],
        "badges": [],
    }
    member = db.session.query(GuildMembers).filter(
        GuildMembers.guild_id == guild_id,
        GuildMembers.user_id == user_id).first()
    if member:
        usr["id"] = str(member.user_id)
        usr["username"] = member.username
        usr["nickname"] = member.nickname
        usr["discriminator"] = member.discriminator
        usr["avatar"] = member.avatar
        usr["avatar_url"] = generate_avatar_url(usr["id"], usr["avatar"],
                                                usr["discriminator"], True)
        roles = get_member_roles(guild_id, user_id)
        dbguild = db.session.query(Guilds).filter(
            Guilds.guild_id == guild_id).first()
        guild_roles = json.loads(dbguild.roles)
        for r in roles:
            for gr in guild_roles:
                if gr["id"] == r:
                    usr["roles"].append(gr)
        usr["badges"] = get_badges(user_id)
        if redis_store.get("DiscordBotsOrgVoted/" + str(member.user_id)):
            usr["badges"].append("discordbotsorgvoted")
    return jsonify(usr)
Пример #3
0
def get_online_embed_users(guild_id):
    time_past = (datetime.datetime.now() -
                 datetime.timedelta(seconds=15)).strftime('%Y-%m-%d %H:%M:%S')
    unauths = db.session.query(UnauthenticatedUsers).filter(
        UnauthenticatedUsers.last_timestamp > time_past,
        UnauthenticatedUsers.revoked == False,
        UnauthenticatedUsers.guild_id == guild_id).all()
    auths = db.session.query(AuthenticatedUsers).filter(
        AuthenticatedUsers.last_timestamp > time_past,
        AuthenticatedUsers.guild_id == guild_id).all()
    users = {'unauthenticated': [], 'authenticated': []}
    for user in unauths:
        meta = {
            'username': user.username,
            'discriminator': user.discriminator,
        }
        users['unauthenticated'].append(meta)
    for user in auths:
        client_id = user.client_id
        usrdb = db.session.query(GuildMembers).filter(
            GuildMembers.guild_id == guild_id).filter(
                GuildMembers.user_id == client_id).first()
        meta = {
            'id': usrdb.user_id,
            'username': usrdb.username,
            'nickname': usrdb.nickname,
            'discriminator': usrdb.discriminator,
            'avatar_url': generate_avatar_url(usrdb.user_id, usrdb.avatar),
        }
        users['authenticated'].append(meta)
    return users
Пример #4
0
def callback():
    state = session.get('oauth2_state')
    if not state or request.values.get('error'):
        return redirect(url_for('user.logout'))
    discord = make_authenticated_session(state=state)
    discord_token = discord.fetch_token(token_url,
                                        client_secret=config['client-secret'],
                                        authorization_response=request.url)
    if not discord_token:
        return redirect(url_for('user.logout'))
    session['user_keys'] = discord_token
    session['unauthenticated'] = False
    session.permanent = True
    user = get_current_authenticated_user()
    session['user_id'] = int(user['id'])
    session['username'] = user['username']
    session['discriminator'] = user['discriminator']
    session['avatar'] = generate_avatar_url(user['id'], user['avatar'],
                                            user['discriminator'])
    session["tokens"] = get_titan_token(session["user_id"])
    if session["tokens"] == -1:
        session["tokens"] = 0
    if session["redirect"]:
        redir = session["redirect"]
        session['redirect'] = None
        return redirect(redir)
    return redirect(url_for("user.dashboard"))
Пример #5
0
def user_info(guild_id, user_id):
    usr = {
        "id": None,
        "username": None,
        "nickname": None,
        "discriminator": None,
        "avatar": None,
        "avatar_url": None,
        "roles": [],
        "badges": [],
    }
    member = redisqueue.get_guild_member(guild_id, user_id)
    if member:
        usr["id"] = str(member["id"])
        usr["username"] = member["username"]
        usr["nickname"] = member["nick"]
        usr["discriminator"] = member["discriminator"]
        usr["avatar"] = member["avatar"]
        usr["avatar_url"] = generate_avatar_url(usr["id"], usr["avatar"],
                                                usr["discriminator"], True)
        roles = get_member_roles(guild_id, user_id)
        guild_roles = redisqueue.get_guild(guild_id)["roles"]
        for r in roles:
            for gr in guild_roles:
                if gr["id"] == r:
                    usr["roles"].append(gr)
        usr["badges"] = get_badges(user_id)
        if redis_store.get("DiscordBotsOrgVoted/" + str(member["id"])):
            usr["badges"].append("discordbotsorgvoted")
    return jsonify(usr)
Пример #6
0
def get_all_users(guild_id):
    users = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id, GuildMembers.active == True).all()
    mem = []
    for u in users:
        mem.append({
            "id": str(u.user_id),
            "avatar": u.avatar,
            "avatar_url": generate_avatar_url(u.user_id, u.avatar, u.discriminator, True),
            "username": u.username,
            "nickname": u.nickname,
            "discriminator": u.discriminator
        })
    return mem
Пример #7
0
def get_all_users(guild_id):
    users = redisqueue.list_guild_members(guild_id)
    mem = []
    for u in users:
        mem.append({
            "id":
            str(u["id"]),
            "avatar":
            u["avatar"],
            "avatar_url":
            generate_avatar_url(u["id"], u["avatar"], u["discriminator"],
                                True),
            "username":
            u["username"],
            "nickname":
            u["nick"],
            "discriminator":
            u["discriminator"]
        })
    return mem