The-CJ / Phaazebot

Phaazebot: Twitch, Discord, Osu, Twitter... Everything in one place
MIT License
0 stars 0 forks source link

Rewrite verification in Discord Requests #125

Closed The-CJ closed 4 years ago

The-CJ commented 4 years ago

But all the code of

# get user info
DiscordUser:DiscordWebUserInfo = await cls.getDiscordUserInfo(WebRequest)
if not DiscordUser.found:
  return await apiMissingAuthorisation(cls, WebRequest)

# get member
CheckMember:discord.Member = Guild.get_member(int(DiscordUser.user_id))
if not CheckMember:
  return await apiDiscordMemberNotFound(cls, WebRequest, guild_id=guild_id, user_id=DiscordUser.user_id)

# check permissions
# to edit configs, at least moderator rights are needed, (there can be options that require server only duh)
if not (CheckMember.guild_permissions.administrator or CheckMember.guild_permissions.manage_guild):
  return await apiDiscordMissingPermission(cls, WebRequest, guild_id=guild_id, user_id=DiscordUser.user_id)

into one thing like:

VerificationError:Response = checkDiscordPermission(cls, WebRequest, requires="administrator", on_guild=guild_id)
if VerificationError != None: return VerificationError
else: pass
The-CJ commented 4 years ago

You know... while i was trying to implement this, i realities that that would remove variables that are created in the auth process from the current scope, and there are often used to the the Discord user ID or DiscordWebInfo

sure could be done with return values but, meh.. i gonna... think about this more

The-CJ commented 4 years ago

After a good pile of sleep, i think this is not a good idea, for now