diff options
Diffstat (limited to 'arthur/exts/cloudflare/zones.py')
| -rw-r--r-- | arthur/exts/cloudflare/zones.py | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/arthur/exts/cloudflare/zones.py b/arthur/exts/cloudflare/zones.py index 64cd5f3..20169bc 100644 --- a/arthur/exts/cloudflare/zones.py +++ b/arthur/exts/cloudflare/zones.py @@ -1,4 +1,6 @@ """The zones cog helps with managing Cloudflare zones""" +from typing import Optional + from discord.ext import commands from arthur.apis.cloudflare import zones @@ -15,5 +17,27 @@ class Zones(commands.Cog): await ctx.send_help(ctx.command) @zones.command(name="purge") - async def purge(self, ctx: commands.Context, zone_name: str = "pythondiscord.com"): - pass
\ No newline at end of file + async def purge(self, ctx: commands.Context, zone_name: Optional[str] = "pythondiscord.com"): + """Command to clear the Cloudflare cache of the specified zone""" + pydis_zones = await zones.list_zones(zone_name) + required_id = pydis_zones[zone_name] + purge_attempt_response = await zones.purge_zone(required_id) + + message = "__Cloudflare cache purge status__\n" + + if purge_attempt_response["success"]: + message += "Purge status: **Successful** :white_check_mark:\n" + message += f"Zone purged: **Zone purged: `{zone_name}`" + return await ctx.send(message) + else: + message += "Purge status: **Failed** :x:\n" + if errors := purge_attempt_response["errors"]: + message += "__Errors:__\n" + for error in errors: + message += f"**Code**: `{error.code}`\n" + message += f"**Message**: {error.message}\n" + return await ctx.send(message) + +def setup(bot: KingArthur) -> None: + """Add the extension to the bot.""" + bot.add_cog(Zones(bot))
\ No newline at end of file |