7
7
from core import time
8
8
9
9
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 :
17
11
"""
18
12
Send a message and allow users to react to it to close the thread.
19
13
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.
24
15
"""
25
16
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 with the provided custom close message." )
26
19
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 )
33
21
await message .add_reaction (unicode_reaction )
34
22
35
23
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
44
32
try :
45
33
await ctx .bot .wait_for ('reaction_add' , check = checkmark_press_check , timeout = 5 * 60 )
46
34
except asyncio .TimeoutError :
47
- await message .delete ()
35
+ await message .edit (content = message .content + '\n \n **Timed out.**' )
36
+ await message .clear_reactions ()
48
37
else :
49
38
await original_close_command (ctx , after = converted_arg )
50
39
51
40
52
- async def fail_without_duration (
41
+ async def safe_close (
53
42
self : time .UserFriendlyTime ,
54
43
ctx : commands .Context ,
55
44
* ,
56
45
after : time .UserFriendlyTime = None
57
46
) -> None :
58
47
"""
59
- Fail if a time duration wasn't provided with a close message .
48
+ Close the current thread .
60
49
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.
63
52
"""
64
53
modifiers = {'silently' , 'silent' , 'cancel' }
65
54
66
55
argument_passed = bool (after )
67
56
not_a_modifier = after .arg not in modifiers
68
57
69
58
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 )
74
61
else :
75
62
await original_close_command (ctx , after = after )
76
63
77
64
78
65
def setup (bot : ModmailBot ) -> None :
79
66
"""
80
- Monkey patch the close command's callback to fail_without_duration .
67
+ Monkey patch the close command's callback to safe_close .
81
68
82
69
The help text is also updated to reflect the new behaviour.
83
70
"""
@@ -87,8 +74,8 @@ def setup(bot: ModmailBot) -> None:
87
74
original_close_command = command .copy ()
88
75
original_close_command .cog = command .cog
89
76
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.*'
92
79
93
80
94
81
def teardown (bot : ModmailBot ) -> None :
0 commit comments