Skip to content

Commit 77fbb69

Browse files
martinbndrTaaku18
andauthored
confirm_thread_creation Buttons instead of reactions (#3273)
* Reminder Plugin Created a reminder plugin * Fix indentations * confirm_thread_creation Buttons instead of reactions * Changelog+Small fixes * Updated the react to confirm message, and removed changelog entry * Code linting with black * Update changelog --------- Co-authored-by: Taku <[email protected]>
1 parent 1adbacf commit 77fbb69

File tree

5 files changed

+51
-36
lines changed

5 files changed

+51
-36
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
2525
- Repo moved to https://github.com/modmail-dev/modmail.
2626
- 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))
2727
- Discord.py internal logging is now enabled by default. ([PR #3216](https://github.com/modmail-dev/Modmail/pull/3216))
28+
- The confirm-thread-creation dialog now uses buttons instead of reactions. ([PR #3273](https://github.com/modmail-dev/Modmail/pull/3273))
2829

2930
### Internal
3031
- 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))

core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class ConfigManager:
123123
# confirm thread creation
124124
"confirm_thread_creation": False,
125125
"confirm_thread_creation_title": "Confirm thread creation",
126-
"confirm_thread_response": "React to confirm thread creation which will directly contact the moderators",
126+
"confirm_thread_response": "Click the button to confirm thread creation which will directly contact the moderators.",
127127
"confirm_thread_creation_accept": "\N{WHITE HEAVY CHECK MARK}",
128128
"confirm_thread_creation_deny": "\N{NO ENTRY SIGN}",
129129
# regex

core/config_help.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,10 +1014,10 @@
10141014
]
10151015
},
10161016
"confirm_thread_response": {
1017-
"default": "React to confirm thread creation which will directly contact the moderators",
1017+
"default": "Click the button to confirm thread creation which will directly contact the moderators.",
10181018
"description": "Description for the embed message sent to users to confirm a thread creation",
10191019
"examples":[
1020-
"`{prefix}config set confirm_thread_response React to confirm`"
1020+
"`{prefix}config set confirm_thread_response Click to confirm`"
10211021
],
10221022
"notes": [
10231023
"See also: `confirm_thread_creation`, `confirm_thread_creation_title`, `confirm_thread_creation_accept`, `confirm_thread_creation_deny`"

core/thread.py

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
get_top_role,
3030
create_thread_channel,
3131
get_joint_id,
32+
AcceptButton,
33+
DenyButton,
34+
ConfirmThreadCreationView,
3235
)
3336

3437
logger = getLogger(__name__)
@@ -1418,30 +1421,19 @@ async def create(
14181421
destination = recipient
14191422
else:
14201423
destination = message.channel
1424+
view = ConfirmThreadCreationView()
1425+
view.add_item(AcceptButton(self.bot.config["confirm_thread_creation_accept"]))
1426+
view.add_item(DenyButton(self.bot.config["confirm_thread_creation_deny"]))
14211427
confirm = await destination.send(
14221428
embed=discord.Embed(
14231429
title=self.bot.config["confirm_thread_creation_title"],
14241430
description=self.bot.config["confirm_thread_response"],
14251431
color=self.bot.main_color,
1426-
)
1432+
),
1433+
view=view,
14271434
)
1428-
accept_emoji = self.bot.config["confirm_thread_creation_accept"]
1429-
deny_emoji = self.bot.config["confirm_thread_creation_deny"]
1430-
emojis = [accept_emoji, deny_emoji]
1431-
for emoji in emojis:
1432-
await confirm.add_reaction(emoji)
1433-
await asyncio.sleep(0.2)
1434-
1435-
try:
1436-
r, _ = await self.bot.wait_for(
1437-
"reaction_add",
1438-
check=lambda r, u: u.id == recipient.id
1439-
and r.message.id == confirm.id
1440-
and r.message.channel.id == confirm.channel.id
1441-
and str(r.emoji) in (accept_emoji, deny_emoji),
1442-
timeout=20,
1443-
)
1444-
except asyncio.TimeoutError:
1435+
await view.wait()
1436+
if view.value is None:
14451437
thread.cancelled = True
14461438
self.bot.loop.create_task(
14471439
destination.send(
@@ -1452,23 +1444,16 @@ async def create(
14521444
)
14531445
)
14541446
)
1455-
else:
1456-
if str(r.emoji) == deny_emoji:
1457-
thread.cancelled = True
1458-
self.bot.loop.create_task(
1459-
destination.send(
1460-
embed=discord.Embed(
1461-
title=self.bot.config["thread_cancelled"], color=self.bot.error_color
1462-
)
1447+
await confirm.edit(view=None)
1448+
if view.value is False:
1449+
thread.cancelled = True
1450+
self.bot.loop.create_task(
1451+
destination.send(
1452+
embed=discord.Embed(
1453+
title=self.bot.config["thread_cancelled"], color=self.bot.error_color
14631454
)
14641455
)
1465-
1466-
async def remove_reactions():
1467-
for emoji in emojis:
1468-
await confirm.remove_reaction(emoji, self.bot.user)
1469-
await asyncio.sleep(0.2)
1470-
1471-
self.bot.loop.create_task(remove_reactions())
1456+
)
14721457
if thread.cancelled:
14731458
del self.cache[recipient.id]
14741459
return thread

core/utils.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
"get_top_role",
4040
"get_joint_id",
4141
"extract_block_timestamp",
42+
"AcceptButton",
43+
"DenyButton",
44+
"ConfirmThreadCreationView",
4245
]
4346

4447

@@ -559,3 +562,29 @@ def extract_block_timestamp(reason, id_):
559562
raise
560563

561564
return end_time, after
565+
566+
567+
class AcceptButton(discord.ui.Button):
568+
def __init__(self, emoji):
569+
super().__init__(style=discord.ButtonStyle.gray, emoji=emoji)
570+
571+
async def callback(self, interaction: discord.Interaction):
572+
self.view.value = True
573+
await interaction.response.edit_message(view=None)
574+
self.view.stop()
575+
576+
577+
class DenyButton(discord.ui.Button):
578+
def __init__(self, emoji):
579+
super().__init__(style=discord.ButtonStyle.gray, emoji=emoji)
580+
581+
async def callback(self, interaction: discord.Interaction):
582+
self.view.value = False
583+
await interaction.response.edit_message(view=None)
584+
self.view.stop()
585+
586+
587+
class ConfirmThreadCreationView(discord.ui.View):
588+
def __init__(self):
589+
super().__init__(timeout=20)
590+
self.value = None

0 commit comments

Comments
 (0)