bot: Send a dm with the site info when the site is ready
This commit is contained in:
parent
d7c6e1cf70
commit
3b914abf7a
@ -3,6 +3,7 @@ from dotenv import load_dotenv
|
|||||||
import discord
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
import requests
|
import requests
|
||||||
|
import asyncio
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
TOKEN = os.getenv('DISCORD_TOKEN')
|
TOKEN = os.getenv('DISCORD_TOKEN')
|
||||||
@ -69,7 +70,24 @@ async def createsite(ctx, domain: str, licence: str):
|
|||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
json = r.json()
|
json = r.json()
|
||||||
if json['success'] == "true":
|
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:
|
else:
|
||||||
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:
|
||||||
@ -88,6 +106,17 @@ async def siteinfo(ctx, domain: str):
|
|||||||
else:
|
else:
|
||||||
await ctx.response.send_message(f"Error getting site info\n" + r.text)
|
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
|
# When the bot is ready
|
||||||
@client.event
|
@client.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
|
Loading…
Reference in New Issue
Block a user