Send the active token in the handshake (for reconnection)
This commit is contained in:
@@ -41,6 +41,9 @@ command_handlers = {}
|
||||
drb_api = DRBCDBAPI(CLIENT_API_URL)
|
||||
srv_api = RadioAPIClient(SERVER_API_URL)
|
||||
|
||||
# Hold the active token
|
||||
bot_token = None
|
||||
|
||||
# --- Define the client status object ---
|
||||
class DiscordStatusValues(str, Enum):
|
||||
INVOICE = "in_voice" # The discord client is in at least one voice channel
|
||||
@@ -75,6 +78,7 @@ async def join_server(websocket, system_id, guild_id, channel_id):
|
||||
# Check if the bot is running
|
||||
if 'bot_running' not in bot_status or not bot_status['bot_running']:
|
||||
# Get a token
|
||||
global bot_token
|
||||
bot_token = await srv_api.request_token()
|
||||
print("Bot token:", bot_token)
|
||||
if not bot_token or "token" not in bot_token or not bot_token['token']:
|
||||
@@ -257,7 +261,7 @@ async def main_client():
|
||||
print("Connection established.")
|
||||
|
||||
# Handshake: Send client ID immediately after connecting
|
||||
handshake_message = json.dumps({"type": "handshake", "id": CLIENT_ID, "nickname": NICKNAME})
|
||||
handshake_message = json.dumps({"type": "handshake", "id": CLIENT_ID, "nickname": NICKNAME, "active_token": bot_token})
|
||||
await websocket.send(handshake_message)
|
||||
print(f"Sent handshake with ID: {CLIENT_ID}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user