Fix permissions issue and role hoists

This commit is contained in:
Jeremy Zhang 2018-07-18 00:38:37 +00:00
parent 86c7232b35
commit 6cd27f2aff
4 changed files with 12 additions and 35 deletions

View File

@ -65,7 +65,8 @@ def get_formatted_user(user):
}
roles = sorted(user.roles, key=lambda k: k.position, reverse=True)
for role in roles:
userobj["roles"].append(role.id)
userobj["roles"].append(str(role.id))
print(role, role.hoist)
if role.hoist and userobj["hoist-role"] == None:
userobj["hoist-role"] = {
"id": str(role.id),

View File

@ -103,7 +103,7 @@ def get_online_discord_users(guild_id, embed):
apimembers = redisqueue.list_guild_members(guild_id)
apimembers_filtered = {}
for member in apimembers:
apimembers_filtered[member["id"]] = member
apimembers_filtered[int(member["id"])] = member
guild_roles = json.loads(db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first().roles)
guildroles_filtered = {}
for role in guild_roles:
@ -113,29 +113,10 @@ def get_online_discord_users(guild_id, embed):
member["hoist-role"] = None
member["color"] = None
if apimem:
mem_roles = []
for roleid in apimem["roles"]:
role = guildroles_filtered.get(roleid)
if not role:
continue
mem_roles.append(role)
mem_roles = sorted(mem_roles, key=lambda k: k['position'])
for role in mem_roles:
if role["color"] != 0:
member["color"] = '{0:02x}'.format(role["color"]) #int to hex
while len(member["color"]) < 6:
member["color"] = "0" + member["color"]
if role["hoist"]:
member["hoist-role"] = {}
member["hoist-role"]["name"] = role["name"]
member["hoist-role"]["id"] = role["id"]
member["hoist-role"]["position"] = role["position"]
if member.get("avatar", None):
member["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}".format(member["id"], member["avatar"])
if member["avatar"].startswith("a_"):
member["avatar_url"] = member["avatar_url"] + ".gif"
else:
member["avatar_url"] = member["avatar_url"] + ".png"
member["hoist-role"] = apimem["hoist-role"]
member["color"] = apimem["color"]
member["avatar"] = apimem["avatar"]
member["avatar_url"] = apimem["avatar_url"]
return embed['members']
def get_online_embed_users(guild_id):

View File

@ -148,7 +148,6 @@ class Gateway(Namespace):
return color
def on_lookup_user_info(self, data):
print("test")
guild_id = data["guild_id"]
name = data["name"]
discriminator = data["discriminator"]
@ -164,25 +163,18 @@ class Gateway(Namespace):
"discordbotsorgvoted": False,
}
member = redisqueue.get_guild_member_named(guild_id, "{}#{}".format(name, discriminator))
print("test1")
if member:
print("test1.5")
usr["id"] = str(member["id"])
usr["username"] = member["username"]
usr["nickname"] = member["nick"]
usr["avatar"] = member["avatar"]
print("test1.54")
usr["color"] = self.get_user_color(guild_id, usr["id"])
print("test1.55")
if (usr["avatar"]):
usr["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}.png".format(usr["id"], usr["avatar"])
usr["roles"] = member["roles"]
usr["discordbotsorgvoted"] = bool(redis_store.get("DiscordBotsOrgVoted/" + str(member["id"])))
print("test1.6")
else:
print("test2")
member = redisqueue.get_guild_member_named(guild_id, name)
print("test3")
if member:
usr["id"] = str(member["id"])
usr["username"] = member["username"]
@ -193,6 +185,5 @@ class Gateway(Namespace):
usr["avatar_url"] = "https://cdn.discordapp.com/avatars/{}/{}.png".format(usr["id"], usr["avatar"])
usr["roles"] = member["roles"]
usr["discordbotsorgvoted"] = bool(redis_store.get("DiscordBotsOrgVoted/" + str(member["id"])))
print("test4")
emit("lookup_user_info", usr)
self.teardown_db_session()

View File

@ -194,7 +194,11 @@ def check_user_in_guild(guild_id):
def get_member_roles(guild_id, user_id):
q = redisqueue.get_guild_member(guild_id, user_id)
return q["roles"]
roles = q["roles"]
role_converted = []
for role in roles:
role_converted.append(str(role))
return role_converted
def get_guild_channels(guild_id, force_everyone=False):
if user_unauthenticated() or force_everyone: