From b77e435ff8053cdd7a430e5cd96e188b2d69988d Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 12 Mar 2023 17:22:42 +0100 Subject: [PATCH 1/7] Reminder Plugin Created a reminder plugin --- plugins/registry.json | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/registry.json b/plugins/registry.json index 8b6d26bf5f..6b4b0171d3 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -34,6 +34,15 @@ "title": "Suggest stuff.", "icon_url": "https://i.imgur.com/qtE7AH8.png", "thumbnail_url": "https://i.imgur.com/qtE7AH8.png" + }, + "reminder": { + "repository": "martinbndr/kyb3r-modmail-plugins", + "branch": "master", + "description": "Let´s you create reminders.", + "bot_version": "4.0.0", + "title": "Reminder", + "icon_url": "https://raw.githubusercontent.com/martinbndr/kyb3r-modmail-plugins/master/reminder/logo.png", + "thumbnail_url": "https://raw.githubusercontent.com/martinbndr/kyb3r-modmail-plugins/master/reminder/logo.png" }, "welcomer": { "repository": "fourjr/modmail-plugins", From ebd38d368ce6e088a46531d9764d63765114e3cb Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Tue, 14 Mar 2023 05:18:17 -0700 Subject: [PATCH 2/7] Fix indentations --- plugins/registry.json | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/registry.json b/plugins/registry.json index 6b4b0171d3..fe175ea58a 100644 --- a/plugins/registry.json +++ b/plugins/registry.json @@ -35,11 +35,11 @@ "icon_url": "https://i.imgur.com/qtE7AH8.png", "thumbnail_url": "https://i.imgur.com/qtE7AH8.png" }, - "reminder": { + "reminder": { "repository": "martinbndr/kyb3r-modmail-plugins", "branch": "master", "description": "Let´s you create reminders.", - "bot_version": "4.0.0", + "bot_version": "4.0.0", "title": "Reminder", "icon_url": "https://raw.githubusercontent.com/martinbndr/kyb3r-modmail-plugins/master/reminder/logo.png", "thumbnail_url": "https://raw.githubusercontent.com/martinbndr/kyb3r-modmail-plugins/master/reminder/logo.png" @@ -75,43 +75,43 @@ "repository": "fourjr/modmail-plugins", "branch": "v4", "description": "Allows managing server emotes via ?emoji", - "bot_version": "4.0.0", + "bot_version": "4.0.0", "title": "Emote Manager", "icon_url": "https://i.imgur.com/Mo60CdK.png", "thumbnail_url": "https://i.imgur.com/Mo60CdK.png" }, - "gen-log": { + "gen-log": { "repository": "fourjr/modmail-plugins", "branch": "v4", "description": "Outputs a text log of a thread in a specified channel", - "bot_version": "4.0.0", + "bot_version": "4.0.0", "title": "Log Generator", "icon_url": "https://i.imgur.com/Mo60CdK.png", "thumbnail_url": "https://i.imgur.com/Mo60CdK.png" }, - "media-logger": { + "media-logger": { "repository": "fourjr/modmail-plugins", "branch": "v4", "description": "Re-posts detected media from all visible channels into a specified logging channel", - "bot_version": "4.0.0", + "bot_version": "4.0.0", "title": "Media Logger", "icon_url": "https://i.imgur.com/Mo60CdK.png", "thumbnail_url": "https://i.imgur.com/Mo60CdK.png" }, - "report": { + "report": { "repository": "fourjr/modmail-plugins", "branch": "v4", "description": "Specify an emoji to react with on messages. Generates a 'report' in specified logging channel upon react.", - "bot_version": "4.0.0", + "bot_version": "4.0.0", "title": "Report", "icon_url": "https://i.imgur.com/Mo60CdK.png", "thumbnail_url": "https://i.imgur.com/Mo60CdK.png" }, - "top-supporters": { + "top-supporters": { "repository": "fourjr/modmail-plugins", "branch": "v4", "description": "Gathers and prints the top supporters of handling threads.", - "bot_version": "4.0.0", + "bot_version": "4.0.0", "title": "Top Supporters", "icon_url": "https://i.imgur.com/Mo60CdK.png", "thumbnail_url": "https://i.imgur.com/Mo60CdK.png" From f5f25b5478bbd265f6cf983910ee03eb99ff5f3f Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 3 Apr 2023 13:10:35 +0200 Subject: [PATCH 3/7] confirm_thread_creation Buttons instead of reactions --- core/thread.py | 53 ++++++++++++++++++-------------------------------- core/utils.py | 32 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/core/thread.py b/core/thread.py index 53cdd1d202..3ab6439c0f 100644 --- a/core/thread.py +++ b/core/thread.py @@ -29,6 +29,9 @@ get_top_role, create_thread_channel, get_joint_id, + AcceptButton, + DenyButton, + ConfirmThreadCreationView ) logger = getLogger(__name__) @@ -1416,30 +1419,19 @@ async def create( destination = recipient else: destination = message.channel + view = ConfirmThreadCreationView() + view.add_item(AcceptButton(self.bot.config["confirm_thread_creation_accept"])) + view.add_item(DenyButton(self.bot.config["confirm_thread_creation_deny"])) confirm = await destination.send( embed=discord.Embed( title=self.bot.config["confirm_thread_creation_title"], description=self.bot.config["confirm_thread_response"], - color=self.bot.main_color, - ) + color=self.bot.main_color + ), + view=view ) - accept_emoji = self.bot.config["confirm_thread_creation_accept"] - deny_emoji = self.bot.config["confirm_thread_creation_deny"] - emojis = [accept_emoji, deny_emoji] - for emoji in emojis: - await confirm.add_reaction(emoji) - await asyncio.sleep(0.2) - - try: - r, _ = await self.bot.wait_for( - "reaction_add", - check=lambda r, u: u.id == recipient.id - and r.message.id == confirm.id - and r.message.channel.id == confirm.channel.id - and str(r.emoji) in (accept_emoji, deny_emoji), - timeout=20, - ) - except asyncio.TimeoutError: + await view.wait() + if view.value == None: thread.cancelled = True self.bot.loop.create_task( destination.send( @@ -1450,23 +1442,16 @@ async def create( ) ) ) - else: - if str(r.emoji) == deny_emoji: - thread.cancelled = True - self.bot.loop.create_task( - destination.send( - embed=discord.Embed( - title=self.bot.config["thread_cancelled"], color=self.bot.error_color - ) + await confirm.edit(view=None) + if view.value == False: + thread.cancelled = True + self.bot.loop.create_task( + destination.send( + embed=discord.Embed( + title=self.bot.config["thread_cancelled"], color=self.bot.error_color ) ) - - async def remove_reactions(): - for emoji in emojis: - await confirm.remove_reaction(emoji, self.bot.user) - await asyncio.sleep(0.2) - - self.bot.loop.create_task(remove_reactions()) + ) if thread.cancelled: del self.cache[recipient.id] return thread diff --git a/core/utils.py b/core/utils.py index d8046ade5f..c33c4c48a3 100644 --- a/core/utils.py +++ b/core/utils.py @@ -39,6 +39,9 @@ "get_top_role", "get_joint_id", "extract_block_timestamp", + "AcceptButton", + "DenyButton", + "ConfirmThreadCreationView" ] @@ -559,3 +562,32 @@ def extract_block_timestamp(reason, id_): raise return end_time, after + +class AcceptButton(discord.ui.Button): + def __init__(self, emoji): + super().__init__( + style=discord.ButtonStyle.gray, + emoji=emoji + ) + + async def callback(self, interaction: discord.Interaction): + self.view.value = True + await interaction.response.edit_message(view=None) + self.view.stop() + +class DenyButton(discord.ui.Button): + def __init__(self, emoji): + super().__init__( + style=discord.ButtonStyle.gray, + emoji=emoji + ) + + async def callback(self, interaction: discord.Interaction): + self.view.value = False + await interaction.response.edit_message(view=None) + self.view.stop() + +class ConfirmThreadCreationView(discord.ui.View): + def __init__(self): + super().__init__(timeout=20) + self.value = None From 51a023ccdc5fe32b8be7daaf27bee91e68a1b87a Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 3 Apr 2023 13:35:56 +0200 Subject: [PATCH 4/7] Changelog+Small fixes --- CHANGELOG.md | 1 + core/thread.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 46cf14177c..80b64fd664 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s ### Breaking - Presence intent is now by-default OFF. You can turn it on by setting `ENABLE_PRESENCE_INTENT=true` in the environment variables. +- Using Buttons instead of reactions in ´´confirm_thread_creation``. ### Fixed diff --git a/core/thread.py b/core/thread.py index 3ab6439c0f..6d06dde359 100644 --- a/core/thread.py +++ b/core/thread.py @@ -1431,7 +1431,7 @@ async def create( view=view ) await view.wait() - if view.value == None: + if view.value is None: thread.cancelled = True self.bot.loop.create_task( destination.send( @@ -1443,7 +1443,7 @@ async def create( ) ) await confirm.edit(view=None) - if view.value == False: + if view.value is False: thread.cancelled = True self.bot.loop.create_task( destination.send( From 75917d7793b4c883a0984e46def2971de8dd8894 Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:56:21 -0700 Subject: [PATCH 5/7] Updated the react to confirm message, and removed changelog entry --- CHANGELOG.md | 1 - core/config.py | 2 +- core/config_help.json | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 376eb2e749..adee789203 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,6 @@ however, insignificant breaking changes do not guarantee a major version bump, s ### Breaking - Presence intent is now by-default OFF. You can turn it on by setting `ENABLE_PRESENCE_INTENT=true` in the environment variables. -- Using Buttons instead of reactions in ´´confirm_thread_creation``. ### Fixed diff --git a/core/config.py b/core/config.py index 9a033167b7..e4d73571d8 100644 --- a/core/config.py +++ b/core/config.py @@ -123,7 +123,7 @@ class ConfigManager: # confirm thread creation "confirm_thread_creation": False, "confirm_thread_creation_title": "Confirm thread creation", - "confirm_thread_response": "React to confirm thread creation which will directly contact the moderators", + "confirm_thread_response": "Click the button to confirm thread creation which will directly contact the moderators.", "confirm_thread_creation_accept": "\N{WHITE HEAVY CHECK MARK}", "confirm_thread_creation_deny": "\N{NO ENTRY SIGN}", # regex diff --git a/core/config_help.json b/core/config_help.json index e7ebb9590d..7723759ef8 100644 --- a/core/config_help.json +++ b/core/config_help.json @@ -1014,10 +1014,10 @@ ] }, "confirm_thread_response": { - "default": "React to confirm thread creation which will directly contact the moderators", + "default": "Click the button to confirm thread creation which will directly contact the moderators.", "description": "Description for the embed message sent to users to confirm a thread creation", "examples":[ - "`{prefix}config set confirm_thread_response React to confirm`" + "`{prefix}config set confirm_thread_response Click to confirm`" ], "notes": [ "See also: `confirm_thread_creation`, `confirm_thread_creation_title`, `confirm_thread_creation_accept`, `confirm_thread_creation_deny`" From 85e5c9f0049fba53a74425ecb42ed18fed943078 Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Wed, 12 Jul 2023 04:58:39 -0700 Subject: [PATCH 6/7] Code linting with black --- core/thread.py | 6 +++--- core/utils.py | 19 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/core/thread.py b/core/thread.py index 6d06dde359..87ff89a2d5 100644 --- a/core/thread.py +++ b/core/thread.py @@ -31,7 +31,7 @@ get_joint_id, AcceptButton, DenyButton, - ConfirmThreadCreationView + ConfirmThreadCreationView, ) logger = getLogger(__name__) @@ -1426,9 +1426,9 @@ async def create( embed=discord.Embed( title=self.bot.config["confirm_thread_creation_title"], description=self.bot.config["confirm_thread_response"], - color=self.bot.main_color + color=self.bot.main_color, ), - view=view + view=view, ) await view.wait() if view.value is None: diff --git a/core/utils.py b/core/utils.py index c33c4c48a3..0e9f090d12 100644 --- a/core/utils.py +++ b/core/utils.py @@ -41,7 +41,7 @@ "extract_block_timestamp", "AcceptButton", "DenyButton", - "ConfirmThreadCreationView" + "ConfirmThreadCreationView", ] @@ -563,30 +563,27 @@ def extract_block_timestamp(reason, id_): return end_time, after + class AcceptButton(discord.ui.Button): def __init__(self, emoji): - super().__init__( - style=discord.ButtonStyle.gray, - emoji=emoji - ) - + super().__init__(style=discord.ButtonStyle.gray, emoji=emoji) + async def callback(self, interaction: discord.Interaction): self.view.value = True await interaction.response.edit_message(view=None) self.view.stop() + class DenyButton(discord.ui.Button): def __init__(self, emoji): - super().__init__( - style=discord.ButtonStyle.gray, - emoji=emoji - ) - + super().__init__(style=discord.ButtonStyle.gray, emoji=emoji) + async def callback(self, interaction: discord.Interaction): self.view.value = False await interaction.response.edit_message(view=None) self.view.stop() + class ConfirmThreadCreationView(discord.ui.View): def __init__(self): super().__init__(timeout=20) From 3f356a400996d0c6bc8ea1527a5110153663067a Mon Sep 17 00:00:00 2001 From: Taku <45324516+Taaku18@users.noreply.github.com> Date: Sat, 15 Jul 2023 04:58:54 -0700 Subject: [PATCH 7/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3feb557449..35cabb1e58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s - Repo moved to https://github.com/modmail-dev/modmail. - Guild icons in embed footers and author urls now have a fixed size of 128. ([PR #3261](https://github.com/modmail-dev/modmail/pull/3261)) - Discord.py internal logging is now enabled by default. ([PR #3216](https://github.com/modmail-dev/Modmail/pull/3216)) +- The confirm-thread-creation dialog now uses buttons instead of reactions. ([PR #3273](https://github.com/modmail-dev/Modmail/pull/3273)) ### Internal - Renamed `Bot.log_file_name` to `Bot.log_file_path`. Log files are now created at `temp/logs/modmail.log`. ([PR #3216](https://github.com/modmail-dev/Modmail/pull/3216))