diff options
| -rw-r--r-- | bot/__main__.py | 5 | ||||
| -rw-r--r-- | bot/cogs/deployment.py | 75 | ||||
| -rw-r--r-- | bot/constants.py | 8 |
3 files changed, 85 insertions, 3 deletions
diff --git a/bot/__main__.py b/bot/__main__.py index 6d5c2c063..2b4f9047c 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -25,11 +25,10 @@ bot.load_extension("bot.cogs.security") bot.load_extension("bot.cogs.events") -# Owner-only -bot.load_extension("bot.cogs.eval") - # Commands, etc bot.load_extension("bot.cogs.bot") +bot.load_extension("bot.cogs.deployment") +bot.load_extension("bot.cogs.eval") bot.load_extension("bot.cogs.verification") bot.run(os.environ.get("BOT_TOKEN")) diff --git a/bot/cogs/deployment.py b/bot/cogs/deployment.py new file mode 100644 index 000000000..da0d3ef86 --- /dev/null +++ b/bot/cogs/deployment.py @@ -0,0 +1,75 @@ +# coding=utf-8 +from aiohttp import ClientSession +from discord import Embed, Colour + +from discord.ext.commands import AutoShardedBot, Context, command + +from bot.constants import ADMIN_ROLE, DEPLOY_BOT_KEY, DEPLOY_SITE_KEY, DEPLOY_URL, OWNER_ROLE, STATUS_URL +from bot.decorators import with_role + + +class Deployment: + """ + Bot information commands + """ + + def __init__(self, bot: AutoShardedBot): + self.bot = bot + + @command(name="redeploy()", aliases=["bot.redeploy", "bot.redeploy()", "redeploy"]) + @with_role(ADMIN_ROLE, OWNER_ROLE) + async def redeploy(self, ctx: Context): + """ + Trigger bot deployment on the server + """ + + with ClientSession() as session: + result = await session.get(DEPLOY_URL, headers={"token": DEPLOY_BOT_KEY}) + + if result == "True": + await ctx.send(f"{ctx.author.mention} Bot deployment started.") + else: + await ctx.send(f"{ctx.author.mention} Bot deployment failed - check the logs!") + + @command(name="deploy_site()", aliases=["bot.deploy_site", "bot.deploy_site()", "deploy_site"]) + @with_role(ADMIN_ROLE, OWNER_ROLE) + async def deploy_site(self, ctx: Context): + """ + Trigger website deployment on the server + """ + + with ClientSession() as session: + result = await session.get(DEPLOY_URL, headers={"token": DEPLOY_SITE_KEY}) + + if result == "True": + await ctx.send(f"{ctx.author.mention} Site deployment started.") + else: + await ctx.send(f"{ctx.author.mention} Site deployment failed - check the logs!") + + @command(name="uptimes()", aliases=["bot.uptimes", "bot.uptimes()", "uptimes"]) + @with_role(ADMIN_ROLE, OWNER_ROLE) + async def uptimes(self, ctx: Context): + """ + Check the various deployment uptimes for each service + """ + + with ClientSession() as session: + response = await session.get(STATUS_URL) + data = await response.json() + + embed = Embed( + title="Service status", + color=Colour.blurple() + ) + + for key, value in data.items(): + embed.add_field( + name=key, value=value, inline=True + ) + + await ctx.send(embed=embed) + + +def setup(bot): + bot.add_cog(Deployment(bot)) + print("Cog loaded: Deployment") diff --git a/bot/constants.py b/bot/constants.py index 59f500403..6bcd190f1 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,5 +1,7 @@ # coding=utf-8 +import os + DEVLOG_CHANNEL = 409308876241108992 VERIFICATION_CHANNEL = 352442727016693763 @@ -8,3 +10,9 @@ ADMIN_ROLE = 267628507062992896 MODERATOR_ROLE = 267629731250176001 VERIFIED_ROLE = 352427296948486144 OWNER_ROLE = 267627879762755584 + +DEPLOY_URL = os.environ.get("DEPLOY_URL") +STATUS_URL = os.environ.get("STATUS_URL") + +DEPLOY_BOT_KEY = os.environ.get("DEPLOY_BOT_KEY") +DEPLOY_SITE_KEY = os.environ.get("DEPLOY_SITE_KEY") |