From ea55fd63e432e845008c973949f0304d02da2e79 Mon Sep 17 00:00:00 2001 From: sco1 Date: Fri, 28 Dec 2018 14:13:29 -0500 Subject: Switch local color constants to PyDis' constants --- bot/cogs/defcon.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index c432d377c..5fb5ef88f 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -5,13 +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, 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! @@ -93,7 +91,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 +132,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,7 +143,7 @@ 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" ) @@ -177,7 +175,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,7 +185,7 @@ 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}`)" ) -- cgit v1.2.3 From 199222f7b1db2964a68a969f77279af8b5c1a91c Mon Sep 17 00:00:00 2001 From: sco1 Date: Fri, 28 Dec 2018 14:25:38 -0500 Subject: Add #defcon to channel constants --- bot/constants.py | 1 + config-default.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/bot/constants.py b/bot/constants.py index 5e7927ed9..b4eca7e1d 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -317,6 +317,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 e7145289d..6d301048f 100644 --- a/config-default.yml +++ b/config-default.yml @@ -89,6 +89,7 @@ guild: big_brother_logs: &BBLOGS 468507907357409333 bot: 267659945086812160 checkpoint_test: 422077681434099723 + defcon: 464469101889454091 devalerts: 460181980097675264 devlog: &DEVLOG 409308876241108992 devtest: &DEVTEST 414574275865870337 -- cgit v1.2.3 From 912923418924749af9295232dfae398f0e4dda4f Mon Sep 17 00:00:00 2001 From: sco1 Date: Fri, 28 Dec 2018 14:42:08 -0500 Subject: Add defcon channel topic updating --- bot/cogs/defcon.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index 5fb5ef88f..d26170444 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -10,7 +10,6 @@ from bot.decorators import with_role log = logging.getLogger(__name__) - REJECTION_MESSAGE = """ Hi, {user} - Thanks for your interest in our server! @@ -22,6 +21,8 @@ will be resolved soon. In the meantime, please feel free to peruse the resources , and have a nice day! """ +BASE_CHANNEL_TOPIC = "Python Discord Defense Mechanism" + class Defcon: """Time-sensitive server defense mechanisms""" @@ -64,6 +65,8 @@ class Defcon: self.days = timedelta(days=0) log.warning(f"DEFCON disabled") + self.update_channel_topic() + async def on_member_join(self, member: Member): if self.enabled and self.days.days > 0: now = datetime.utcnow() @@ -148,6 +151,8 @@ class Defcon: f"**Days:** {self.days.days}\n\n" ) + 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): @@ -189,6 +194,8 @@ class Defcon: f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)" ) + self.update_channel_topic() + @defcon_group.command(name='status', aliases=('s',)) @with_role(Roles.admin, Roles.owner) async def status_command(self, ctx: Context): @@ -250,6 +257,21 @@ class Defcon: f"**Days:** {self.days.days}" ) + self.update_channel_topic() + + async def update_channel_topic(self): + """ + Update the #defcon channel topic with the current DEFCON status + """ + + if self.enabled: + new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Enabled, Threshold: {self.days} days)" + else: + new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Disabled)" + + defcon_channel = await self.bot.guild.get_channel(Channels.defcon) + await defcon_channel.edit(topic=new_topic) + def setup(bot: Bot): bot.add_cog(Defcon(bot)) -- cgit v1.2.3 From 32b1ec7aa21d59166458eb2bb1826c628ec8013b Mon Sep 17 00:00:00 2001 From: sco1 Date: Fri, 28 Dec 2018 14:58:28 -0500 Subject: Fix channel grabbing logic --- bot/cogs/defcon.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index d26170444..a29f4599e 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -265,11 +265,12 @@ class Defcon: """ if self.enabled: - new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Enabled, Threshold: {self.days} days)" + day_str = "days" if self.days > 1 else "day" + new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Enabled, Threshold: {self.days} {day_str})" else: new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Disabled)" - defcon_channel = await self.bot.guild.get_channel(Channels.defcon) + defcon_channel = self.bot.guilds[0].get_channel(Channels.defcon) await defcon_channel.edit(topic=new_topic) -- cgit v1.2.3 From 905aaab64736738c46e47cdbc52b977225b1ff34 Mon Sep 17 00:00:00 2001 From: sco1 Date: Sun, 30 Dec 2018 08:30:04 -0500 Subject: Add missing awaits oops --- bot/cogs/defcon.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index a29f4599e..def9a70e3 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -65,7 +65,7 @@ class Defcon: self.days = timedelta(days=0) log.warning(f"DEFCON disabled") - self.update_channel_topic() + await self.update_channel_topic() async def on_member_join(self, member: Member): if self.enabled and self.days.days > 0: @@ -151,7 +151,7 @@ class Defcon: f"**Days:** {self.days.days}\n\n" ) - self.update_channel_topic() + await self.update_channel_topic() @defcon_group.command(name='disable', aliases=('off', 'd')) @with_role(Roles.admin, Roles.owner) @@ -194,7 +194,7 @@ class Defcon: f"**Staffer:** {ctx.author.name}#{ctx.author.discriminator} (`{ctx.author.id}`)" ) - self.update_channel_topic() + await self.update_channel_topic() @defcon_group.command(name='status', aliases=('s',)) @with_role(Roles.admin, Roles.owner) @@ -257,7 +257,7 @@ class Defcon: f"**Days:** {self.days.days}" ) - self.update_channel_topic() + await self.update_channel_topic() async def update_channel_topic(self): """ -- cgit v1.2.3 From b3d1dc26b9c0c5ee8ffac8fad0a9a39bf6fdedfb Mon Sep 17 00:00:00 2001 From: sco1 Date: Tue, 1 Jan 2019 20:24:00 -0500 Subject: Fix timedelta days reference --- bot/cogs/defcon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index def9a70e3..4c043f050 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -265,8 +265,8 @@ class Defcon: """ if self.enabled: - day_str = "days" if self.days > 1 else "day" - new_topic = f"{BASE_CHANNEL_TOPIC}\n(Status: Enabled, Threshold: {self.days} {day_str})" + 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)" -- cgit v1.2.3 From 9e26d3a9a40bd692e1cbf4953376f06a14254c31 Mon Sep 17 00:00:00 2001 From: scragly <29337040+scragly@users.noreply.github.com> Date: Wed, 2 Jan 2019 21:26:30 +1100 Subject: Ignore defcon title change in modlog. --- bot/cogs/defcon.py | 3 ++- bot/cogs/modlog.py | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py index 4c043f050..f07d9df9f 100644 --- a/bot/cogs/defcon.py +++ b/bot/cogs/defcon.py @@ -5,7 +5,7 @@ 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, Colours, 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__) @@ -270,6 +270,7 @@ class Defcon: 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) 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 = [] -- cgit v1.2.3