From 910ce1b0986997024e1f00718bc030451f9e033e Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Mon, 18 Sep 2023 14:47:14 +1000 Subject: [PATCH] bot: Display site count in bot status --- discord-bot/bot.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index e0da690..289dc34 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -51,6 +51,7 @@ async def listworkers(ctx): await ctx.response.send_message(f"Error listing workers\n" + r.text,ephemeral=True) else: await ctx.response.send_message("You do not have permission to use this command",ephemeral=True) + update_bot_status() @tree.command(name="licence", description="Gets a licence key") async def license(ctx): @@ -104,6 +105,7 @@ async def createsite(ctx, domain: str, licence: str = None): await ctx.response.send_message(f"Error creating site\n" + json['error']) else: await ctx.response.send_message(f"Error creating site\n" + r.text) + update_bot_status() @tree.command(name="siteinfo", description="Get info about a WordPress site") @@ -128,6 +130,17 @@ async def check_site_ready(domain): return False else: return False + +def site_count(): + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-count") + if r.status_code == 200: + return r.text + else: + return "Error getting site count\n" + r.text + +def update_bot_status(): + site_count = site_count() + client.loop.create_task(client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over " + site_count + " wordpress sites"))) # When the bot is ready @client.event @@ -135,6 +148,9 @@ async def on_ready(): global ADMINID ADMINID = client.application.owner.id await tree.sync() - await client.loop.create_task(client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over HNSHosting wordpress"))) + + # Get the number of sites + site_count = site_count() + await client.loop.create_task(client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="over " + site_count + " wordpress sites"))) client.run(TOKEN) \ No newline at end of file