From 89afed5793221d8d55792c50f8dd30b28db4885d Mon Sep 17 00:00:00 2001
From: Taku <45324516+Taaku18@users.noreply.github.com>
Date: Thu, 16 Jan 2025 08:28:36 +0000
Subject: [PATCH 1/4] Update README.md
Signed-off-by: Taku <45324516+Taaku18@users.noreply.github.com>
---
README.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 980066ca7e..500978a1f9 100644
--- a/README.md
+++ b/README.md
@@ -6,7 +6,7 @@
-
+
@@ -24,7 +24,7 @@
-
+
From 6c820bfeca3f42d9e9e0bc4fd5d6ddfb8a1e18ad Mon Sep 17 00:00:00 2001
From: Taku <45324516+Taaku18@users.noreply.github.com>
Date: Mon, 10 Feb 2025 14:59:47 +0000
Subject: [PATCH 2/4] Update README.md
Update sponsors
Signed-off-by: Taku <45324516+Taaku18@users.noreply.github.com>
---
README.md | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/README.md b/README.md
index 500978a1f9..eef9e3f940 100644
--- a/README.md
+++ b/README.md
@@ -159,6 +159,13 @@ Discord Advice Center:
+
+
+Blacklight Promotions:
+
+
+
+
Become a sponsor on [Patreon](https://patreon.com/kyber).
From 8cd4ea0cc812ebced811cb32d045f3c0ffcd457a Mon Sep 17 00:00:00 2001
From: Martin
Date: Thu, 27 Feb 2025 18:23:17 +0100
Subject: [PATCH 3/4] recipient_thread_close via Buttons
- Updates the recipient_thread_close feature to use a button instead of a reaction.
- New config options: recipient_thread_close_button_label, recipient_thread_close_button_style
- The close_emoji default value is now None to make it possible changing the button to only have a label.
---
bot.py | 23 ++++++++++-------------
core/config.py | 9 ++++++---
core/config_help.json | 33 ++++++++++++++++++++++++++++-----
core/thread.py | 31 +++++++++++++++++++++++++++----
core/utils.py | 36 ++++++++++++++++++++++++++++++++++++
5 files changed, 107 insertions(+), 25 deletions(-)
diff --git a/bot.py b/bot.py
index 3c6ebe7911..9fb49020ac 100644
--- a/bot.py
+++ b/bot.py
@@ -48,7 +48,15 @@
)
from core.thread import ThreadManager
from core.time import human_timedelta
-from core.utils import extract_block_timestamp, normalize_alias, parse_alias, truncate, tryint, human_join
+from core.utils import (
+ extract_block_timestamp,
+ normalize_alias,
+ parse_alias,
+ truncate,
+ tryint,
+ human_join,
+ ThreadSelfCloseView,
+)
logger = getLogger(__name__)
@@ -617,6 +625,7 @@ async def on_ready(self):
self.post_metadata.start()
self.autoupdate.start()
self.log_expiry.start()
+ self.add_view(ThreadSelfCloseView(self))
self._started = True
async def convert_emoji(self, name: str) -> str:
@@ -1248,19 +1257,7 @@ async def handle_reaction_events(self, payload):
return
reaction = payload.emoji
- close_emoji = await self.convert_emoji(self.config["close_emoji"])
if from_dm:
- if (
- payload.event_type == "REACTION_ADD"
- and message.embeds
- and str(reaction) == str(close_emoji)
- and self.config.get("recipient_thread_close")
- ):
- ts = message.embeds[0].timestamp
- if ts == thread.channel.created_at:
- # the reacted message is the corresponding thread creation embed
- # closing thread
- return await thread.close(closer=user)
if (
message.author == self.user
and message.embeds
diff --git a/core/config.py b/core/config.py
index 5c6b0dd09d..c33deb21be 100644
--- a/core/config.py
+++ b/core/config.py
@@ -49,12 +49,14 @@ class ConfigManager:
# threads
"sent_emoji": "\N{WHITE HEAVY CHECK MARK}",
"blocked_emoji": "\N{NO ENTRY SIGN}",
- "close_emoji": "\N{LOCK}",
+ "close_emoji": None,
"use_user_id_channel_name": False,
"use_timestamp_channel_name": False,
"use_nickname_channel_name": False,
"use_random_channel_name": False,
"recipient_thread_close": False,
+ "recipient_thread_close_button_label": None,
+ "recipient_thread_close_button_style": "red",
"thread_show_roles": True,
"thread_show_account_age": True,
"thread_show_join_age": True,
@@ -65,7 +67,7 @@ class ConfigManager:
"thread_creation_response": "The staff team will get back to you as soon as possible.",
"thread_creation_footer": "Your message has been sent",
"thread_contact_silently": False,
- "thread_self_closable_creation_footer": "Click the lock to close the thread",
+ "thread_self_closable_creation_footer": "Click the button to close the thread",
"thread_creation_contact_title": "New Thread",
"thread_creation_self_contact_response": "You have opened a Modmail thread.",
"thread_creation_contact_response": "{creator.name} has opened a Modmail thread.",
@@ -233,7 +235,8 @@ class ConfigManager:
enums = {
"dm_disabled": DMDisabled,
"status": discord.Status,
- "activity_type": discord.ActivityType,
+ "activity_type": discord.ActivityType
+ #"recipient_thread_close_button_style": discord.ButtonStyle
}
force_str = {"command_permissions", "level_permissions"}
diff --git a/core/config_help.json b/core/config_help.json
index d301763fe4..98c662869c 100644
--- a/core/config_help.json
+++ b/core/config_help.json
@@ -285,8 +285,8 @@
]
},
"close_emoji": {
- "default": "🔒",
- "description": "This is the emoji the recipient can click to close a thread themselves. The emoji is automatically added to the `thread_creation_response` embed.",
+ "default": "None",
+ "description": "This is the emoji for the close button the recipient can click to close a thread themselves. The emoji (attached to the button) is automatically added to the `thread_creation_response` embed.",
"examples": [
"`{prefix}config set close_emoji 👍`"
],
@@ -297,14 +297,37 @@
},
"recipient_thread_close": {
"default": "Disabled",
- "description": "Setting this configuration will allow recipients to use the `close_emoji` to close the thread themselves.",
+ "description": "Setting this configuration will allow recipients to close threads by themselves via a button.",
"examples": [
"`{prefix}config set recipient_thread_close yes`",
"`{prefix}config set recipient_thread_close no`"
],
"notes": [
- "The close emoji is dictated by the configuration `close_emoji`.",
- "See also: `close_emoji`."
+ "The button attached to the `thread_creation_response` can have set a custom label, emoji or even both.",
+ "See also: `close_emoji`, `recipient_thread_close_button_label`, `recipient_thread_close_button_style`."
+ ]
+ },
+ "recipient_thread_close_button_label": {
+ "default": "None",
+ "description": "This configuration changes the label of the button for the `recipient_thread_close` feature.",
+ "examples": [
+ "`{prefix}config set recipient_thread_close_button_label Your label`"
+ ],
+ "notes": [
+ "The label cannot exceed 80 characters.",
+ "See also: `recipient_thread_close`, `close_emoji`, `recipient_thread_close_button_style`."
+ ]
+ },
+ "recipient_thread_close_button_style": {
+ "default": "red",
+ "description": "This configuration changes the style of the button for the `recipient_thread_close` feature.",
+ "examples": [
+ "`{prefix}config set recipient_thread_close_button_style green`",
+ "`{prefix}config set recipient_thread_close_button_style blurple`"
+ ],
+ "notes": [
+ "The style is limited by discord to the following colors: blurple, green, red, gray.",
+ "See also: `recipient_thread_close`, `close_emoji`, `recipient_thread_close_button_label`."
]
},
"thread_show_roles": {
diff --git a/core/thread.py b/core/thread.py
index 81dc03f44d..5cd95a68a7 100644
--- a/core/thread.py
+++ b/core/thread.py
@@ -32,6 +32,7 @@
AcceptButton,
DenyButton,
ConfirmThreadCreationView,
+ ThreadSelfCloseView,
DummyParam,
)
@@ -239,11 +240,33 @@ async def send_recipient_genesis_message():
if creator is None or creator == recipient:
msg = await recipient.send(embed=embed)
-
- if recipient_thread_close:
+ close_emoji = self.bot.config["close_emoji"]
+ close_label = self.bot.config["recipient_thread_close_button_label"]
+ if (
+ recipient_thread_close
+ and self.bot.config["recipient_thread_close_button_style"].lower()
+ in ["red", "green", "blurple", "gray"]
+ and (close_emoji is not None and close_label is not None)
+ ):
close_emoji = self.bot.config["close_emoji"]
- close_emoji = await self.bot.convert_emoji(close_emoji)
- await self.bot.add_reaction(msg, close_emoji)
+ if close_emoji:
+ close_emoji = await self.bot.convert_emoji(close_emoji)
+
+ button_style = discord.ButtonStyle(
+ int(
+ discord.ButtonStyle[
+ self.bot.config["recipient_thread_close_button_style"].lower()
+ ]
+ )
+ )
+ view = ThreadSelfCloseView(
+ button_style,
+ close_label,
+ close_emoji,
+ self.bot,
+ )
+ await msg.edit(view=view)
+ # await self.bot.add_reaction(msg, close_emoji)
async def send_persistent_notes():
notes = await self.bot.api.find_notes(self.recipient)
diff --git a/core/utils.py b/core/utils.py
index 9f9f572f5a..2ca68be346 100644
--- a/core/utils.py
+++ b/core/utils.py
@@ -42,6 +42,7 @@
"AcceptButton",
"DenyButton",
"ConfirmThreadCreationView",
+ "ThreadSelfCloseView",
"DummyParam",
]
@@ -599,6 +600,41 @@ def __init__(self):
self.value = None
+class ThreadSelfCloseView(discord.ui.View):
+ def __init__(
+ self,
+ style: typing.Optional[discord.ButtonStyle] = None,
+ label: typing.Optional[str] = None,
+ emoji: typing.Optional[str] = None,
+ bot: typing.Any = None,
+ ):
+ super().__init__(timeout=None)
+ self.bot = bot
+
+ self.self_close_button.label = label
+ self.self_close_button.style = style
+ self.self_close_button.emoji = emoji
+
+ @discord.ui.button(label="default", style=discord.ButtonStyle.secondary, custom_id="SelfCloseView")
+ async def self_close_button(self, interaction: discord.Interaction, button: discord.ui.Button):
+ await interaction.response.defer(ephemeral=False, thinking=True)
+ thread = await self.bot.threads.find(recipient=interaction.user)
+ if not thread:
+ error_embed = discord.Embed(
+ description="A thread could not be found.", color=self.bot.config["error_color"]
+ )
+ return await interaction.followup.send(embed=error_embed)
+
+ message = self.bot.config["thread_self_close_response"]
+ embed = discord.Embed(
+ title="Thread closed", description=message, color=self.bot.config["error_color"]
+ )
+ await thread.close(closer=interaction.user, silent=True)
+ self.self_close_button.disabled = True
+ await interaction.message.edit(view=self)
+ await interaction.followup.send(embed=embed)
+
+
class DummyParam:
"""
A dummy parameter that can be used for MissingRequiredArgument.
From 959166771b951c34f93bc17803fbf1e651d769b0 Mon Sep 17 00:00:00 2001
From: Martin
Date: Thu, 27 Feb 2025 18:28:17 +0100
Subject: [PATCH 4/4] Fix config.py black formatting
---
core/config.py | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/core/config.py b/core/config.py
index c33deb21be..85b6b05fb5 100644
--- a/core/config.py
+++ b/core/config.py
@@ -232,12 +232,7 @@ class ConfigManager:
"registry_plugins_only",
}
- enums = {
- "dm_disabled": DMDisabled,
- "status": discord.Status,
- "activity_type": discord.ActivityType
- #"recipient_thread_close_button_style": discord.ButtonStyle
- }
+ enums = {"dm_disabled": DMDisabled, "status": discord.Status, "activity_type": discord.ActivityType}
force_str = {"command_permissions", "level_permissions"}