diff options
| author | 2021-07-22 17:58:06 +0100 | |
|---|---|---|
| committer | 2021-07-22 17:58:06 +0100 | |
| commit | 941e7690b4099ee3c3da9e5d4b6ebd56327c262c (patch) | |
| tree | 34f9c0ef2591fb4903fe8dd321f22bdfbd1acfe2 /arthur/exts/cloudflare/zones.py | |
| parent | Change constant name (diff) | |
Standardise responses + more
Diffstat (limited to 'arthur/exts/cloudflare/zones.py')
| -rw-r--r-- | arthur/exts/cloudflare/zones.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/arthur/exts/cloudflare/zones.py b/arthur/exts/cloudflare/zones.py index 448ad81..ed1ff0d 100644 --- a/arthur/exts/cloudflare/zones.py +++ b/arthur/exts/cloudflare/zones.py @@ -5,6 +5,7 @@ from discord.ext import commands from arthur.apis.cloudflare import zones from arthur.bot import KingArthur +from arthur.utils import generate_error_message class Zones(commands.Cog): @@ -21,26 +22,26 @@ class Zones(commands.Cog): @zones.command(name="purge") async def purge(self, ctx: commands.Context, zone_name: Optional[str] = "pythondiscord.com" - ) -> None: + ) -> None: """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 = "" - if purge_attempt_response["success"]: - message += ":white_check_mark:" - message += f"**Cache cleared!** The Cloudflare cache for `{zone_name}` was cleared." + message = ":white_check_mark:" + message += f" **Cache cleared!** The Cloudflare cache for `{zone_name}` was cleared." else: - message += f":x: **'Tis but a scratch! The cache for `{zone_name}` couldn't be cleared." + description_content = f"The cache for `{zone_name}` couldn't be cleared.\n" if errors := purge_attempt_response["errors"]: - message += "\nReceived errors:\n" for error in errors: - message += f"**Code**: `{error.code}`\n" - message += f"**Message**: {error.message}\n" - return await ctx.send(message) + description_content += f"`{error['code']}`: {error['message']}\n" + message = generate_error_message( + description=description_content, + emote=":x:" + ) + await ctx.send(message) def setup(bot: KingArthur) -> None: """Add the extension to the bot.""" |