Skip to content

Commit

Permalink
make check staff level first check cache
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahCxrest authored Jan 19, 2025
1 parent bb4b301 commit a8c88b0
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,28 +753,35 @@ async def POST_check_staff_level(self, request: Request):
json_data = await request.json()
guild_id = json_data.get("guild")
user_id = json_data.get("user")

if not guild_id or not user_id:
return HTTPException(status_code=400, detail="Invalid guild")

try:
guild = await self.bot.fetch_guild(guild_id)
except (discord.Forbidden, discord.HTTPException):
return HTTPException(status_code=400, detail="Invalid guild")

try:
user = await guild.fetch_member(user_id)
except (discord.Forbidden, discord.HTTPException):
return {"permission_level": 0}

raise HTTPException(status_code=400, detail="Invalid guild or user ID")

guild = None
user = None

guild = self.bot.get_guild(guild_id)
if not guild:
try:
guild = await self.bot.fetch_guild(guild_id)
except (discord.Forbidden, discord.HTTPException):
raise HTTPException(status_code=400, detail="Invalid guild")

user = guild.get_member(user_id)
if not user:
try:
user = await guild.fetch_member(user_id)
except (discord.Forbidden, discord.HTTPException):
return {"permission_level": 0}

permission_level = 0
if await management_check(self.bot, guild, user):
permission_level = 2
elif await admin_check(self.bot, guild, user):
permission_level = 3
elif await staff_check(self.bot, guild, user):
permission_level = 1



return {"permission_level": permission_level}

async def POST_get_guild_settings(self, request: Request):
Expand Down

0 comments on commit a8c88b0

Please sign in to comment.