77from core import time
88
99
10- def quote (string : str ) -> str :
11- """Format a string as a markdown blockquote."""
12- lines = string .splitlines (keepends = True )
13- return '' .join (f'> { line } ' for line in lines )
14-
15-
16- async def allow_duration_bypass (ctx : commands .Context , converted_arg : time .UserFriendlyTime ) -> None :
10+ async def close_after_confirmation (ctx : commands .Context , converted_arg : time .UserFriendlyTime ) -> None :
1711 """
1812 Send a message and allow users to react to it to close the thread.
1913
20- The custom close message from the converted argument is used.
21-
22- The reaction times out after 5 minutes, after which the message
23- is deleted.
14+ The reaction times out after 5 minutes.
2415 """
2516 unicode_reaction = '\N{WHITE HEAVY CHECK MARK} '
17+ warning_message = ("\N{WARNING SIGN} A time duration wasn't provided, reacting to this message will close"
18+ " this thread instantly. The provided custom close message will be utilised." )
2619
27- embed = discord .Embed (
28- colour = ctx .bot .main_color ,
29- description = f"Reacting to this message will close this thread with the message:\n \n { quote (converted_arg .arg )} "
30- )
31-
32- message = await ctx .send (embed = embed )
20+ message = await ctx .send (warning_message )
3321 await message .add_reaction (unicode_reaction )
3422
3523 def checkmark_press_check (reaction : discord .Reaction , user : discord .User ) -> bool :
@@ -44,40 +32,39 @@ def checkmark_press_check(reaction: discord.Reaction, user: discord.User) -> boo
4432 try :
4533 await ctx .bot .wait_for ('reaction_add' , check = checkmark_press_check , timeout = 5 * 60 )
4634 except asyncio .TimeoutError :
47- await message .delete ()
35+ await message .edit (content = message .content + '\n \n **Timed out.**' )
36+ await message .clear_reactions ()
4837 else :
4938 await original_close_command (ctx , after = converted_arg )
5039
5140
52- async def fail_without_duration (
41+ async def safe_close (
5342 self : time .UserFriendlyTime ,
5443 ctx : commands .Context ,
5544 * ,
5645 after : time .UserFriendlyTime = None
5746) -> None :
5847 """
59- Fail if a time duration wasn't provided with a close message .
48+ Close the current thread .
6049
61- Unlike the default close command, a time duration must be provided
62- when a custom close message is provided .
50+ Unlike the original close command, confirmation is awaited when
51+ a time duration isn't provided but a custom close message is.
6352 """
6453 modifiers = {'silently' , 'silent' , 'cancel' }
6554
6655 argument_passed = bool (after )
6756 not_a_modifier = after .arg not in modifiers
6857
6958 if argument_passed and not_a_modifier and after .arg == after .raw :
70- # Fail since only a close message was provided.
71- err = commands .BadArgument ("A time duration must be provided when closing with a custom message." )
72- await ctx .bot .on_command_error (ctx , err ) # Sends the error message
73- await allow_duration_bypass (ctx , after )
59+ # Ask for confirmation since only a close message was provided.
60+ await close_after_confirmation (ctx , after )
7461 else :
7562 await original_close_command (ctx , after = after )
7663
7764
7865def setup (bot : ModmailBot ) -> None :
7966 """
80- Monkey patch the close command's callback to fail_without_duration .
67+ Monkey patch the close command's callback to safe_close .
8168
8269 The help text is also updated to reflect the new behaviour.
8370 """
@@ -87,8 +74,8 @@ def setup(bot: ModmailBot) -> None:
8774 original_close_command = command .copy ()
8875 original_close_command .cog = command .cog
8976
90- command .callback = fail_without_duration
91- command .help += '\n \n *Note: Providing a time duration is necessary when closing with a custom message.*'
77+ command .callback = safe_close
78+ command .help += '\n \n *Note: A time duration should be provided when closing with a custom message.*'
9279
9380
9481def teardown (bot : ModmailBot ) -> None :
0 commit comments