diff options
| -rw-r--r-- | bot/cogs/defcon.py | 40 | ||||
| -rw-r--r-- | bot/cogs/modlog.py | 4 | ||||
| -rw-r--r-- | bot/constants.py | 1 | ||||
| -rw-r--r-- | config-default.yml | 1 |
4 files changed, 37 insertions, 9 deletions
diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index c432d377c..f07d9df9f 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -5,14 +5,11 @@ from discord import Colour, Embed, Member from discord.ext.commands import Bot, Context, group from bot.cogs.modlog import ModLog -from bot.constants import Channels, Emojis, Icons, Keys, Roles, URLs +from bot.constants import Channels, Colours, Emojis, Event, Icons, Keys, Roles, URLs 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! @@ -24,6 +21,8 @@ will be resolved soon. In the meantime, please feel free to peruse the resources <https://pythondiscord.com/>, and have a nice day! """ +BASE_CHANNEL_TOPIC = "Python Discord Defense Mechanism" + class Defcon: """Time-sensitive server defense mechanisms""" @@ -66,6 +65,8 @@ class Defcon: self.days = timedelta(days=0) log.warning(f"DEFCON disabled") + await self.update_channel_topic() + async def on_member_join(self, member: Member): if self.enabled and self.days.days > 0: now = datetime.utcnow() @@ -93,7 +94,7 @@ class Defcon: message = f"{message}\n\nUnable to send rejection message via DM; they probably have DMs disabled." await self.mod_log.send_log_message( - Icons.defcon_denied, COLOUR_RED, "Entry denied", + Icons.defcon_denied, Colours.soft_red, "Entry denied", message, member.avatar_url_as(static_format="png") ) @@ -134,7 +135,7 @@ class Defcon: ) await self.mod_log.send_log_message( - Icons.defcon_enabled, COLOUR_GREEN, "DEFCON enabled", + Icons.defcon_enabled, Colours.soft_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 " @@ -145,11 +146,13 @@ class Defcon: await ctx.send(f"{Emojis.defcon_enabled} DEFCON enabled.") await self.mod_log.send_log_message( - Icons.defcon_enabled, COLOUR_GREEN, "DEFCON enabled", + Icons.defcon_enabled, Colours.soft_green, "DEFCON enabled", f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)\n" f"**Days:** {self.days.days}\n\n" ) + await self.update_channel_topic() + @defcon_group.command(name='disable', aliases=('off', 'd')) @with_role(Roles.admin, Roles.owner) async def disable_command(self, ctx: Context): @@ -177,7 +180,7 @@ class Defcon: ) await self.mod_log.send_log_message( - Icons.defcon_disabled, COLOUR_RED, "DEFCON disabled", + Icons.defcon_disabled, Colours.soft_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" @@ -187,10 +190,12 @@ class Defcon: await ctx.send(f"{Emojis.defcon_disabled} DEFCON disabled.") await self.mod_log.send_log_message( - Icons.defcon_disabled, COLOUR_RED, "DEFCON disabled", + Icons.defcon_disabled, Colours.soft_red, "DEFCON disabled", f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)" ) + await self.update_channel_topic() + @defcon_group.command(name='status', aliases=('s',)) @with_role(Roles.admin, Roles.owner) async def status_command(self, ctx: Context): @@ -252,6 +257,23 @@ class Defcon: f"**Days:** {self.days.days}" ) + await self.update_channel_topic() + + async def update_channel_topic(self): + """ + Update the #defcon channel topic with the current DEFCON status + """ + + if self.enabled: + day_str = "days" if self.days.days > 1 else "day" + new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Enabled, Threshold: {self.days.days} {day_str})" + else: + new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Disabled)" + + self.mod_log.ignore(Event.guild_channel_update, Channels.defcon) + defcon_channel = self.bot.guilds[0].get_channel(Channels.defcon) + await defcon_channel.edit(topic=new_topic) + def setup(bot: Bot): bot.add_cog(Defcon(bot)) diff --git a/bot/cogs/modlog.py b/bot/cogs/modlog.py index 905f114c1..0561b5afb 100644 --- a/bot/cogs/modlog.py +++ b/bot/cogs/modlog.py @@ -176,6 +176,10 @@ class ModLog: if before.guild.id != GuildConstant.id: return + if before.id in self._ignored[Event.guild_channel_update]: + self._ignored[Event.guild_channel_update].remove(before.id) + return + diff = DeepDiff(before, after) changes = [] done = [] diff --git a/bot/constants.py b/bot/constants.py index 99ef98da2..05d2abf81 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -319,6 +319,7 @@ class Channels(metaclass=YAMLGetter): big_brother_logs: int bot: int checkpoint_test: int + defcon: int devalerts: int devlog: int devtest: int diff --git a/config-default.yml b/config-default.yml index 3a1ad8052..7a5960987 100644 --- a/config-default.yml +++ b/config-default.yml @@ -91,6 +91,7 @@ guild: big_brother_logs: &BBLOGS 468507907357409333 bot: 267659945086812160 checkpoint_test: 422077681434099723 + defcon: 464469101889454091 devalerts: 460181980097675264 devlog: &DEVLOG 409308876241108992 devtest: &DEVTEST 414574275865870337 |