From 9f8d8741c9f470ff54029ba8dd3fa7bb59851d8e Mon Sep 17 00:00:00 2001 From: fourjr <28086837+fourjr@users.noreply.github.com> Date: Thu, 5 Nov 2020 14:04:29 +0800 Subject: [PATCH] Added alert_on_mention, resolve #2833 --- CHANGELOG.md | 1 + bot.py | 18 ++++++++++++++++++ core/config.py | 2 ++ core/config_help.json | 10 ++++++++++ 4 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1132d2b0f0..f159aa15a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s - Added `thread_move_notify_mods` to mention all mods again after moving thread. ([GH #215](https://github.com/kyb3r/modmail/issues/215)) - Added `transfer_reactions` to link reactions between mods and users. ([GH #2763](https://github.com/kyb3r/modmail/issues/2763)) - Added `close_on_leave` to automatically close threads upon recipient leaving the server. ([GH #2757](https://github.com/kyb3r/modmail/issues/2757)) +- Added `alert_on_mention` to mention mods upon a bot mention. ([GH #2833](https://github.com/kyb3r/modmail/issues/2833)) ### Fixed diff --git a/bot.py b/bot.py index 6613735843..5642cb21ce 100644 --- a/bot.py +++ b/bot.py @@ -862,6 +862,24 @@ async def on_message(self, message): await self.wait_for_connected() if message.type == discord.MessageType.pins_add and message.author == self.user: await message.delete() + + if ( + (f"<@{self.user.id}" in message.content or f"<@!{self.user.id}" in message.content) + and self.config["alert_on_mention"] + and not message.author.bot + ): + if len(message.content) > 50: + extra = "..." + else: + extra = "" + em = discord.Embed( + title="Bot mention", + description=f"[Jump URL]({message.jump_url})\n{message.content[:50]}{extra}", + color=self.main_color, + timestamp=datetime.utcnow(), + ) + await self.log_channel.send(content=self.config["mention"], embed=em) + await self.process_commands(message) async def process_commands(self, message): diff --git a/core/config.py b/core/config.py index 132ac27ee0..936278d67b 100644 --- a/core/config.py +++ b/core/config.py @@ -70,6 +70,7 @@ class ConfigManager: "disabled_current_thread_footer": "Please try again later...", "transfer_reactions": True, "close_on_leave": False, + "alert_on_mention": False, # moderation "recipient_color": str(discord.Color.gold()), "mod_color": str(discord.Color.green()), @@ -144,6 +145,7 @@ class ConfigManager: "thread_move_notify_mods", "transfer_reactions", "close_on_leave", + "alert_on_mention", "enable_plugins", "enable_eval", } diff --git a/core/config_help.json b/core/config_help.json index b8c626b4b8..acb2834e53 100644 --- a/core/config_help.json +++ b/core/config_help.json @@ -580,6 +580,16 @@ ], "notes": [] }, + "alert_on_mention": { + "default": "No", + "description": "Mentions all mods (mention) in logs channel when bot is mentioned", + "examples":[ + "`{prefix}config set alert_on_mention yes" + ], + "notes": [ + "See also: `mention`" + ] + }, "modmail_guild_id": { "default": "Fallback on `GUILD_ID`", "description": "The ID of the discord server where the threads channels should be created (receiving server).",