Skip to content

Commit 0e99fe8

Browse files
committed
Squashed commit of the following:
commit 2e32d6e Merge: 51a023c b21037c Author: Martin <[email protected]> Date: Sun Apr 9 21:22:08 2023 +0200 Merge branch 'modmail-dev:master' into master commit 51a023c Author: Martin <[email protected]> Date: Mon Apr 3 13:35:56 2023 +0200 Changelog+Small fixes commit f5f25b5 Author: Martin <[email protected]> Date: Mon Apr 3 13:10:35 2023 +0200 confirm_thread_creation Buttons instead of reactions commit 11e094c Merge: ebd38d3 e919304 Author: Taku <[email protected]> Date: Tue Mar 14 05:19:54 2023 -0700 Merge branch 'master' into master commit ebd38d3 Author: Taku <[email protected]> Date: Tue Mar 14 05:18:17 2023 -0700 Fix indentations commit b77e435 Author: Martin <[email protected]> Date: Sun Mar 12 17:22:42 2023 +0100 Reminder Plugin Created a reminder plugin
1 parent 9e9317c commit 0e99fe8

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ however, insignificant breaking changes do not guarantee a major version bump, s
2626
### Breaking
2727

2828
- Presence intent is now by-default OFF. You can turn it on by setting `ENABLE_PRESENCE_INTENT=true` in the environment variables.
29+
- Using Buttons instead of reactions in ´´confirm_thread_creation``.
2930

3031
### Fixed
3132

core/thread.py

Lines changed: 19 additions & 34 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__)
@@ -1416,30 +1419,19 @@ async def create(
14161419
destination = recipient
14171420
else:
14181421
destination = message.channel
1422+
view = ConfirmThreadCreationView()
1423+
view.add_item(AcceptButton(self.bot.config["confirm_thread_creation_accept"]))
1424+
view.add_item(DenyButton(self.bot.config["confirm_thread_creation_deny"]))
14191425
confirm = await destination.send(
14201426
embed=discord.Embed(
14211427
title=self.bot.config["confirm_thread_creation_title"],
14221428
description=self.bot.config["confirm_thread_response"],
1423-
color=self.bot.main_color,
1424-
)
1429+
color=self.bot.main_color
1430+
),
1431+
view=view
14251432
)
1426-
accept_emoji = self.bot.config["confirm_thread_creation_accept"]
1427-
deny_emoji = self.bot.config["confirm_thread_creation_deny"]
1428-
emojis = [accept_emoji, deny_emoji]
1429-
for emoji in emojis:
1430-
await confirm.add_reaction(emoji)
1431-
await asyncio.sleep(0.2)
1432-
1433-
try:
1434-
r, _ = await self.bot.wait_for(
1435-
"reaction_add",
1436-
check=lambda r, u: u.id == recipient.id
1437-
and r.message.id == confirm.id
1438-
and r.message.channel.id == confirm.channel.id
1439-
and str(r.emoji) in (accept_emoji, deny_emoji),
1440-
timeout=20,
1441-
)
1442-
except asyncio.TimeoutError:
1433+
await view.wait()
1434+
if view.value is None:
14431435
thread.cancelled = True
14441436
self.bot.loop.create_task(
14451437
destination.send(
@@ -1450,23 +1442,16 @@ async def create(
14501442
)
14511443
)
14521444
)
1453-
else:
1454-
if str(r.emoji) == deny_emoji:
1455-
thread.cancelled = True
1456-
self.bot.loop.create_task(
1457-
destination.send(
1458-
embed=discord.Embed(
1459-
title=self.bot.config["thread_cancelled"], color=self.bot.error_color
1460-
)
1445+
await confirm.edit(view=None)
1446+
if view.value is False:
1447+
thread.cancelled = True
1448+
self.bot.loop.create_task(
1449+
destination.send(
1450+
embed=discord.Embed(
1451+
title=self.bot.config["thread_cancelled"], color=self.bot.error_color
14611452
)
14621453
)
1463-
1464-
async def remove_reactions():
1465-
for emoji in emojis:
1466-
await confirm.remove_reaction(emoji, self.bot.user)
1467-
await asyncio.sleep(0.2)
1468-
1469-
self.bot.loop.create_task(remove_reactions())
1454+
)
14701455
if thread.cancelled:
14711456
del self.cache[recipient.id]
14721457
return thread

core/utils.py

Lines changed: 32 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,32 @@ def extract_block_timestamp(reason, id_):
559562
raise
560563

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

0 commit comments

Comments
 (0)