Add endpoint to fetch a token
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user