Skip to content

Commit f5f25b5

Browse files
committed
confirm_thread_creation Buttons instead of reactions
1 parent 11e094c commit f5f25b5

File tree

2 files changed

+51
-34
lines changed

2 files changed

+51
-34
lines changed

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 == 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 == 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)