Implement fixed node for token
All checks were successful
release-image / release-image (push) Successful in 2m4s

This commit is contained in:
Logan Cusano
2025-06-29 19:08:57 -04:00
parent df4e7f7d67
commit f2dd714571
2 changed files with 14 additions and 5 deletions

View File

@@ -38,7 +38,8 @@ class DiscordId:
name: str, name: str,
token: str, token: str,
active: bool, active: bool,
guild_ids: List[str]): guild_ids: List[str],
fixed_node: Optional[str]=None):
""" """
Initializes a DiscordId object. Initializes a DiscordId object.
@@ -49,6 +50,7 @@ class DiscordId:
token: The authentication token. token: The authentication token.
active: Boolean indicating if the ID is active. active: Boolean indicating if the ID is active.
guild_ids: A list of guild IDs the Discord user is part of. guild_ids: A list of guild IDs the Discord user is part of.
fixed_node: The node ID this DiscordId must use.
""" """
self._id: str = str(_id) self._id: str = str(_id)
self.discord_id: str = discord_id self.discord_id: str = discord_id
@@ -56,6 +58,7 @@ class DiscordId:
self.token: str = token self.token: str = token
self.active: bool = active self.active: bool = active
self.guild_ids: List[str] = guild_ids self.guild_ids: List[str] = guild_ids
self.fixed_node: Optional[str] = fixed_node
def __repr__(self) -> str: def __repr__(self) -> str:
""" """
@@ -75,6 +78,7 @@ class DiscordId:
"token": self.token, "token": self.token,
"active": self.active, "active": self.active,
"guild_ids": self.guild_ids, "guild_ids": self.guild_ids,
"fixed_node": self.fixed_node,
} }
@classmethod @classmethod
@@ -89,6 +93,7 @@ class DiscordId:
token=data.get("token", ""), token=data.get("token", ""),
active=data.get("active", False), # Default to False if not present active=data.get("active", False), # Default to False if not present
guild_ids=data.get("guild_ids", []), # Default to empty list if not present guild_ids=data.get("guild_ids", []), # Default to empty list if not present
fixed_node=data.get("fixed_node", None), # Default to empty if not present
) )

View File

@@ -42,15 +42,19 @@ async def request_token_route():
if not avail_ids: if not avail_ids:
abort(404, "No available active Discord IDs found.") abort(404, "No available active Discord IDs found.")
# --- Logic for selecting a preferred ID based on client_id (TODO) --- selected_id = None
# Check for any fixed IDs
for avail_id in avail_ids:
if avail_id.fixed_node and avail_id.fixed_node == client_id:
selected_id = avail_id
if not selected_id:
selected_id = avail_ids[0]
selected_id = avail_ids[0]
print("Selected Discord ID: ", selected_id) print("Selected Discord ID: ", selected_id)
current_app.active_clients[client_id].active_token = selected_id current_app.active_clients[client_id].active_token = selected_id
print(current_app.active_clients[client_id]) print(current_app.active_clients[client_id])
# --- End of logic for selecting a preferred ID ---
return jsonify(selected_id.to_dict()) return jsonify(selected_id.to_dict())
except Exception as e: except Exception as e: