bot: Display site count in bot status
All checks were successful
Build Docker / Build Master (push) Successful in 20s
Build Docker / Build Bot (push) Successful in 22s

This commit is contained in:
Nathan Woodburn 2023-09-18 14:47:14 +10:00
parent 6741f8cac2
commit 910ce1b098
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1

View File

@ -51,6 +51,7 @@ async def listworkers(ctx):
await ctx.response.send_message(f"Error listing workers\n" + r.text,ephemeral=True) await ctx.response.send_message(f"Error listing workers\n" + r.text,ephemeral=True)
else: else:
await ctx.response.send_message("You do not have permission to use this command",ephemeral=True) 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") @tree.command(name="licence", description="Gets a licence key")
async def license(ctx): 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']) await ctx.response.send_message(f"Error creating site\n" + json['error'])
else: else:
await ctx.response.send_message(f"Error creating site\n" + r.text) 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") @tree.command(name="siteinfo", description="Get info about a WordPress site")
@ -129,12 +131,26 @@ async def check_site_ready(domain):
else: else:
return False 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 # When the bot is ready
@client.event @client.event
async def on_ready(): async def on_ready():
global ADMINID global ADMINID
ADMINID = client.application.owner.id ADMINID = client.application.owner.id
await tree.sync() 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) client.run(TOKEN)