Skip to content

Commit

Permalink
Removed wasteful nickname call.
Browse files Browse the repository at this point in the history
  • Loading branch information
JDJGInc authored Apr 25, 2024
1 parent 64a7b2d commit 7d03fa9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 67 deletions.
1 change: 1 addition & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ async def generate_url(
scopes=("identify", "connections", "guilds", "guilds.members.read"),
state=state,
)
# unused guild.members.read for now will be using it in a different method (if it comes back).

return {"url": url}

Expand Down
1 change: 0 additions & 1 deletion utils/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def stats_builder(data: dict):

connections = data["connections"]
# unknown for connection stats.
nicknames = data["nicknames"]


async def make_oauth_database(oauth_data: dict):
Expand Down
66 changes: 0 additions & 66 deletions utils/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,6 @@
from fastapi import FastAPI


async def grab_nickname_data(guild, session: aiohttp.ClientSession, api_endpoint: str, headers: dict):
# object type for guild may make this easier, to make guild_id to guild.id
# guild.id may be better.
guild_id = guild["id"]
resp = await session.get(f"{api_endpoint}/users/@me/guilds/{guild_id}/member", headers=headers)

guild_info = await resp.json()

retry_seconds = 0.0
if not resp.ok:
retry_seconds = guild_info.get("retry_after")

if not retry_seconds:
return "Retry after doesn't exist."

return retry_seconds

return guild_info


async def handle_basic_response(app: FastAPI, code: str, state: str, redirect_uri: str):

states = app.state.states
Expand Down Expand Up @@ -100,50 +80,6 @@ async def handle_basic_response(app: FastAPI, code: str, state: str, redirect_ur

guilds = await resp.json()

nicknames = {}
# this loop is a terrible way to grab it(It may be better to remove it)
for guild in guilds:

guild_id = guild["id"]
guild_info = await grab_nickname_data(guild, session, api_endpoint, headers)

if isinstance(guild_info, web.Response):
return guild_info

if not isinstance(guild_info, float) and not isinstance(guild_info, dict):
return "Something went wrong with retrying fetching."

if isinstance(guild_info, float):
retry_seconds = guild_info

if retry_seconds:
if retry_seconds > 10:
guild_info = {
"error": f"fetching data with {guild_id}",
"fetch_time": retry_seconds,
}

else:
await asyncio.sleep(retry_seconds)
# I should break out of it

if retry_seconds > 30:
break # break out of loop

guild_info = await grab_nickname_data(guild, session, api_endpoint, headers)
# should run only when more than 0 seconds.
# I should probaly not use this rn and find a way to be able to grab all without having the server timeout.

nicknames[guild_id] = guild_info

# https://discord.com/developers/docs/resources/user#get-current-user-guild-member
# I did put something in for nickname data, tied to guild.members.read.

resp = await session.get(f"{api_endpoint}/users/@me/connections", headers=headers)

if not resp.ok:
return "Grabbing data failed."

connections = await resp.json()

# connections
Expand All @@ -154,7 +90,6 @@ async def handle_basic_response(app: FastAPI, code: str, state: str, redirect_ur
"app": app_data,
"guilds": guilds,
"connections": connections,
"nicknames": nicknames,
}

"""
Expand All @@ -163,7 +98,6 @@ async def handle_basic_response(app: FastAPI, code: str, state: str, redirect_ur
complete_data["app"] = app_data
complete_data["guilds"] = guilds
complete_data["connections"] = connections
complete_data["nicknames"] = nicknames
"""
# old code the new one is better.

Expand Down

0 comments on commit 7d03fa9

Please sign in to comment.