From 3b914abf7a23d4221e4bb1bb46a7681df3a3a445 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Fri, 25 Aug 2023 12:46:08 +1000 Subject: [PATCH] bot: Send a dm with the site info when the site is ready --- discord-bot/bot.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/discord-bot/bot.py b/discord-bot/bot.py index b7969a9..ce9d578 100644 --- a/discord-bot/bot.py +++ b/discord-bot/bot.py @@ -3,6 +3,7 @@ from dotenv import load_dotenv import discord from discord import app_commands import requests +import asyncio load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') @@ -69,7 +70,24 @@ async def createsite(ctx, domain: str, licence: str): if r.status_code == 200: json = r.json() if json['success'] == "true": - await ctx.response.send_message(f"Site {domain} creating...\nPlease wait a few minutes and then send /siteinfo domain:{domain}") + await ctx.response.send_message(f"Site {domain} creating...\nI'll send you a message when it's ready") + # Set a timer to check if the site is ready + # Keep checking every 30 seconds until it is ready + + ready = False + while ready == False: + ready = await check_site_ready(domain,ctx.user.id) + if ready == False: + await asyncio.sleep(30) + + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") + json = r.json() + if json['success'] == "true": + await ctx.user.send(f"Site {domain} is ready!\nHere is the site info for {json['domain']}\nA: `{json['ip']}`\nTLSA: `{json['tlsa']}`\nMake sure you put the TLSA in either `_443._tcp.{domain}` or `*.{domain}`") + else: + await ctx.user.send(f"Error getting site info\n" + json['error']) + + else: await ctx.response.send_message(f"Error creating site\n" + json['error']) else: @@ -88,6 +106,17 @@ async def siteinfo(ctx, domain: str): else: await ctx.response.send_message(f"Error getting site info\n" + r.text) +async def check_site_ready(domain): + r = requests.get(f"http://{Master_IP}:{Master_Port}/site-info?domain={domain}") + if r.status_code == 200: + json = r.json() + if json['success'] == "true": + return True + else: + return False + else: + return False + # When the bot is ready @client.event async def on_ready():