Try manually adding member if not exist in db for webapp

This commit is contained in:
Jeremy Zhang 2018-07-08 20:31:36 +00:00
parent 1fda98ac89
commit d14f9889eb
2 changed files with 16 additions and 1 deletions

View File

@ -124,6 +124,11 @@ class DiscordREST:
_endpoint = "/guilds/{guild_id}/embed".format(guild_id=guild_id)
r = self.request("GET", _endpoint)
return r
def get_guild_member(self, guild_id, user_id):
_endpoint = "/guilds/{guild_id}/members/{user_id}".format(guild_id=guild_id, user_id=user_id)
r = self.request("GET", _endpoint)
return r
def modify_guild_embed(self, guild_id, **kwargs):
_endpoint = "/guilds/{guild_id}/embed".format(guild_id=guild_id)

View File

@ -195,7 +195,17 @@ def check_user_in_guild(guild_id):
def get_member_roles(guild_id, user_id):
q = db.session.query(GuildMembers).filter(GuildMembers.guild_id == guild_id).filter(GuildMembers.user_id == user_id).first()
return json.loads(q.roles)
roles = [guild_id]
if not q:
member = discord_api.get_guild_member(guild_id, user_id)
if member["success"]:
roles = list(map(int, member["content"]["roles"]))
member = GuildMembers(guild_id, user_id, member["content"]["user"]["username"], int(member["content"]["user"]["discriminator"]), member["content"].get("nick", None), member["content"]["user"]["avatar"], True, False, roles)
db.session.add(member)
db.session.commit()
else:
roles = json.loads(q.roles)
return roles
def get_guild_channels(guild_id, force_everyone=False):
if user_unauthenticated() or force_everyone: