From 32ccf5c36e9180b79e6f54a8bac37ce8441b6a46 Mon Sep 17 00:00:00 2001 From: Ferrariic Date: Tue, 12 Jul 2022 23:28:05 -0500 Subject: [PATCH] Add Embed for Active Queues --- src/bot.py | 37 ++++++++++++++++++++++++++++++++++++- src/config.py | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/bot.py b/src/bot.py index 14fbf39..9f5889e 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,9 +1,9 @@ -from dis import disco import logging import discord from discord.ext import tasks import config import json +import time from functions import get_url, post_url logger = logging.getLogger(__name__) @@ -40,8 +40,43 @@ async def on_message(message): return +async def run_active_queues(): + route = ( + config.BASE + f"V1/discord/get-active-queues?token={config.DISCORD_ROUTE_TOKEN}" + ) + + response = await get_url(route=route) + channel = client.get_channel(config.ACTIVE_QUEUES_CHANNEL) + messages = await channel.history(limit=5).flatten() + + embed = discord.Embed( + title="Active Queues", description=f"Updated: " + ) + + if "detail" in response.keys(): + if response["detail"] == "bad token": + logging.warning(response["detail"]) + return + if response["detail"] == "no information": + embed.add_field(name="Active Queues", value="None", inline=False) + else: + for activity in response: + count = response[activity] + embed.add_field(name=activity, value=count, inline=False) + + if len(messages) > 0: + message = messages[0] + await message.edit(embed=embed) + return + + await channel.send(embed=embed) + return + + @tasks.loop(seconds=5) async def manage_channels(): + await run_active_queues() + route = ( config.BASE + f"V1/discord/get-active-matches?token={config.DISCORD_ROUTE_TOKEN}" diff --git a/src/config.py b/src/config.py index e1bda76..511b37e 100644 --- a/src/config.py +++ b/src/config.py @@ -12,6 +12,7 @@ TICKET_BOT = 508391840525975553 GUILD_ID = 985750991846666284 MATCH_CATEGORY = 993321356005486592 +ACTIVE_QUEUES_CHANNEL = 996565302202605619 # BASE = "http://127.0.0.1:8000/" BASE = "http://touchgrass.online:5000/"