From 3ab2d064116dde6204ab4d76b759e4db737362c4 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 27 Apr 2025 01:42:45 -0400 Subject: [PATCH] Add endpoint to fetch a token --- app/client.py | 6 +++++- app/server_api.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/client.py b/app/client.py index 50f0d4c..b0e8edd 100644 --- a/app/client.py +++ b/app/client.py @@ -45,8 +45,12 @@ async def join_server(system_id, guild_id, channel_id): bot_status = await drb_api.get_bot_status() # Check if the bot is running if 'bot_running' not in bot_status or not bot_status['bot_running']: + # Get a token + bot_token = await srv_api.request_token() + if not bot_token or "token" not in bot_token or not bot_token['token']: + raise Exception("No bot token received") # TODO - Handle this better # Run the bot if not - await drb_api.start_bot() + await drb_api.start_bot(bot_token['token']) # Update status client_status = StatusValues.LISTENING op25_status = await drb_api.get_op25_status() diff --git a/app/server_api.py b/app/server_api.py index 6aa687b..9772a01 100644 --- a/app/server_api.py +++ b/app/server_api.py @@ -94,6 +94,16 @@ class RadioAPIClient: print(f"Fetching connected clients from {self.base_url}/clients") return await self._request("GET", "/clients") + async def request_token(self): + """ + Retrieves a discord bot token. + + Returns: + str: A token for the bot to use + """ + print(f"Fetching a token from {self.base_url}/request_token") + return await self._request("GET", "/request_token") + async def send_command(self, client_id: str, command_name: str, args: list = None): """ Sends a command to a specific client via the server's API.