diff options
| author | 2018-07-25 13:47:10 +0100 | |
|---|---|---|
| committer | 2018-07-25 13:47:10 +0100 | |
| commit | f5d1694fff20405178c36df363218ff114f27b4b (patch) | |
| tree | 8ba6a1c802ebf701d5b6af75ff2da3a539854666 | |
| parent | Attempt to speed up build (diff) | |
[DEFCON] Add embeds and icons for actions/events
| -rw-r--r-- | bot/cogs/defcon.py | 113 | ||||
| -rw-r--r-- | bot/constants.py | 9 | ||||
| -rw-r--r-- | config-default.yml | 9 |
3 files changed, 117 insertions, 14 deletions
diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index ea50bdf63..68bed418c 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -4,11 +4,15 @@ from datetime import datetime, timedelta from discord import Colour, Embed, Member from discord.ext.commands import Bot, Context, command -from bot.constants import Channels, Keys, Roles, URLs +from bot.cogs.modlog import ModLog +from bot.constants import Channels, Keys, Roles, URLs, Icons, Emojis from bot.decorators import with_role log = logging.getLogger(__name__) +COLOUR_RED = Colour(0xcd6d6d) +COLOUR_GREEN = Colour(0x68c290) + REJECTION_MESSAGE = """ Hi, {user} - Thanks for your interest in our server! @@ -31,6 +35,10 @@ class Defcon: self.days = timedelta(days=0) self.headers = {"X-API-KEY": Keys.site_api} + @property + def modlog(self) -> ModLog: + return self.bot.get_cog("ModLog") + async def on_ready(self): try: response = await self.bot.http_session.get( @@ -65,13 +73,30 @@ class Defcon: if now - member.created_at < self.days: log.info(f"Rejecting user {member}: Account is too new and DEFCON is enabled") + message_sent = False + try: await member.send(REJECTION_MESSAGE.format(user=member.mention)) + + message_sent = True except Exception: log.exception(f"Unable to send rejection message to user: {member}") await member.kick(reason="DEFCON active, user is too new") + message = ( + f"{member.name}#{member.discriminator} (`{member.id}`) " + f"was denied entry because their account is too new." + ) + + if not message_sent: + message = f"{message}\n\nUnable to send rejection message via DM; they probably have DMs disabled." + + await self.modlog.send_log_message( + Icons.defcon_denied, COLOUR_RED, "Entry denied", + message, member.avatar_url_as(static_format="png") + ) + @with_role(Roles.admin, Roles.owner) @command(name="defcon.enable", aliases=["defcon.enable()", "defcon_enable", "defcon_enable()"]) async def enable(self, ctx: Context): @@ -92,11 +117,31 @@ class Defcon: ) await response.json() - except Exception: + except Exception as e: log.exception("Unable to update DEFCON settings.") - await ctx.send("DEFCON enabled locally, but there was a problem updating the site.") + await ctx.send( + f"{Emojis.defcon_enabled} DEFCON enabled.\n\n" + "**There was a problem updating the site** - This setting may be reverted when the bot is " + "restarted.\n\n" + f"```py\n{e}\n```" + ) + + await self.modlog.send_log_message( + Icons.defcon_enabled, COLOUR_GREEN, "DEFCON enabled", + f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)\n" + f"**Days:** {self.days.days}\n\n" + "**There was a problem updating the site** - This setting may be reverted when the bot is " + "restarted.\n\n" + f"```py\n{e}\n```" + ) else: - await ctx.send("DEFCON enabled.") + await ctx.send(f"{Emojis.defcon_enabled} DEFCON enabled.") + + await self.modlog.send_log_message( + Icons.defcon_enabled, COLOUR_GREEN, "DEFCON enabled", + f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)\n" + f"**Days:** {self.days.days}\n\n" + ) @with_role(Roles.admin, Roles.owner) @command(name="defcon.disable", aliases=["defcon.disable()", "defcon_disable", "defcon_disable()"]) @@ -115,11 +160,29 @@ class Defcon: ) await response.json() - except Exception: + except Exception as e: log.exception("Unable to update DEFCON settings.") - await ctx.send("DEFCON disabled locally, but there was a problem updating the site.") + await ctx.send( + f"{Emojis.defcon_disabled} DEFCON disabled.\n\n" + "**There was a problem updating the site** - This setting may be reverted when the bot is " + "restarted.\n\n" + f"```py\n{e}\n```" + ) + + await self.modlog.send_log_message( + Icons.defcon_disabled, COLOUR_RED, "DEFCON disabled", + f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)\n" + "**There was a problem updating the site** - This setting may be reverted when the bot is " + "restarted.\n\n" + f"```py\n{e}\n```" + ) else: - await ctx.send("DEFCON disabled.") + await ctx.send(f"{Emojis.defcon_disabled} DEFCON disabled.") + + await self.modlog.send_log_message( + Icons.defcon_disabled, COLOUR_RED, "DEFCON disabled", + f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)" + ) @with_role(Roles.admin, Roles.owner) @command(name="defcon", aliases=["defcon()", "defcon.status", "defcon.status()"]) @@ -128,9 +191,11 @@ class Defcon: Check the current status of DEFCON mode. """ - embed = Embed(colour=Colour.blurple(), title="DEFCON Status") - embed.add_field(name="Enabled", value=str(self.enabled), inline=True) - embed.add_field(name="Days", value=str(self.days.days), inline=True) + embed = Embed( + colour=Colour.blurple(), title="DEFCON Status", + description=f"**Enabled:** {self.enabled}\n" + f"**Days:** {self.days.days}" + ) await ctx.send(embed=embed) @@ -151,14 +216,34 @@ class Defcon: ) await response.json() - except Exception: + except Exception as e: log.exception("Unable to update DEFCON settings.") await ctx.send( - f"DEFCON days updated; accounts must be {days} days old to join to the server " - f"- but there was a problem updating the site." + f"{Emojis.defcon_updated} DEFCON days updated; accounts must be {days} " + f"days old to join to the server.\n\n" + "**There was a problem updating the site** - This setting may be reverted when the bot is " + "restarted.\n\n" + f"```py\n{e}\n```" + ) + + await self.modlog.send_log_message( + Icons.defcon_updated, Colour.blurple(), "DEFCON updated", + f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)\n" + f"**Days:** {self.days.days}\n\n" + "**There was a problem updating the site** - This setting may be reverted when the bot is " + "restarted.\n\n" + f"```py\n{e}\n```" ) else: - await ctx.send(f"DEFCON days updated; accounts must be {days} days old to join to the server") + await ctx.send( + f"{Emojis.defcon_updated} DEFCON days updated; accounts must be {days} days old to join to the server" + ) + + await self.modlog.send_log_message( + Icons.defcon_updated, Colour.blurple(), "DEFCON updated", + f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)\n" + f"**Days:** {self.days.days}" + ) def setup(bot: Bot): diff --git a/bot/constants.py b/bot/constants.py index 30289ff0e..e61952ead 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -202,6 +202,10 @@ class Emojis(metaclass=YAMLGetter): section = "bot" subsection = "emojis" + defcon_disabled: str + defcon_enabled: str + defcon_updated: str + green_chevron: str red_chevron: str white_chevron: str @@ -218,6 +222,11 @@ class Icons(metaclass=YAMLGetter): crown_green: str crown_red: str + defcon_denied: str + defcon_disabled: str + defcon_enabled: str + defcon_updated: str + guild_update: str hash_blurple: str diff --git a/config-default.yml b/config-default.yml index ba23b6404..b5bb13c1f 100644 --- a/config-default.yml +++ b/config-default.yml @@ -7,6 +7,10 @@ bot: tags: 60 emojis: + defcon_disabled: "<:defcondisabled:470326273952972810>" + defcon_enabled: "<:defconenabled:470326274213150730>" + defcon_updated: "<:defconsettingsupdated:470326274082996224>" + green_chevron: "<:greenchevron:418104310329769993>" red_chevron: "<:redchevron:418112778184818698>" white_chevron: "<:whitechevron:418110396973711363>" @@ -20,6 +24,11 @@ bot: crown_green: "https://cdn.discordapp.com/emojis/469964154719961088.png" crown_red: "https://cdn.discordapp.com/emojis/469964154879344640.png" + defcon_denied: "https://cdn.discordapp.com/emojis/470326274217476107.png" + defcon_disabled: "https://cdn.discordapp.com/emojis/470326273952972810.png" + defcon_enabled: "https://cdn.discordapp.com/emojis/470326274213150730.png" + defcon_updated: "https://cdn.discordapp.com/emojis/470326274082996224.png" + guild_update: "https://cdn.discordapp.com/emojis/469954765141442561.png" hash_blurple: "https://cdn.discordapp.com/emojis/469950142942806017.png" |