@@ -41,7 +41,11 @@ def is_help_forum_post(channel: discord.abc.GuildChannel) -> bool:
41
41
return getattr (channel , "parent_id" , None ) == constants .Channels .python_help
42
42
43
43
44
- async def _close_help_post (closed_post : discord .Thread , closing_reason : _stats .ClosingReason ) -> None :
44
+ async def _close_help_post (
45
+ closed_post : discord .Thread ,
46
+ closing_reason : _stats .ClosingReason ,
47
+ scheduler : scheduling .Scheduler ,
48
+ ) -> None :
45
49
"""Close the help post and record stats."""
46
50
# Get Thread with updated metadata (such as the title)
47
51
closed_post = await get_or_fetch_channel (bot .instance , closed_post .id )
@@ -82,6 +86,8 @@ async def _close_help_post(closed_post: discord.Thread, closing_reason: _stats.C
82
86
locked = True ,
83
87
reason = "Locked a closed help post" ,
84
88
)
89
+ if closed_post .id in scheduler :
90
+ scheduler .cancel (closed_post .id )
85
91
86
92
_stats .report_post_count ()
87
93
await _stats .report_complete_session (closed_post , closing_reason )
@@ -98,14 +104,18 @@ async def send_opened_post_message(post: discord.Thread) -> None:
98
104
await post .send (embed = embed , content = post .owner .mention )
99
105
100
106
101
- async def help_post_opened (opened_post : discord .Thread , * , reopen : bool = False ) -> None :
107
+ async def help_post_opened (
108
+ opened_post : discord .Thread ,
109
+ * ,
110
+ scheduler : scheduling .Scheduler ,
111
+ ) -> None :
102
112
"""Apply new post logic to a new help forum post."""
103
113
_stats .report_post_count ()
104
114
bot .instance .stats .incr ("help.claimed" )
105
115
106
116
if not isinstance (opened_post .owner , discord .Member ):
107
117
log .debug (f"{ opened_post .owner_id } isn't a member. Closing post." )
108
- await _close_help_post (opened_post , _stats .ClosingReason .CLEANUP )
118
+ await _close_help_post (opened_post , _stats .ClosingReason .CLEANUP , scheduler )
109
119
return
110
120
111
121
try :
@@ -124,12 +134,12 @@ async def help_post_opened(opened_post: discord.Thread, *, reopen: bool = False)
124
134
await send_opened_post_message (opened_post )
125
135
126
136
127
- async def help_post_closed (closed_post : discord .Thread ) -> None :
137
+ async def help_post_closed (closed_post : discord .Thread , scheduler : scheduling . Scheduler ) -> None :
128
138
"""Apply archive logic to a manually closed help forum post."""
129
- await _close_help_post (closed_post , _stats .ClosingReason .COMMAND )
139
+ await _close_help_post (closed_post , _stats .ClosingReason .COMMAND , scheduler )
130
140
131
141
132
- async def help_post_archived (archived_post : discord .Thread ) -> None :
142
+ async def help_post_archived (archived_post : discord .Thread , scheduler : scheduling . Scheduler ) -> None :
133
143
"""Apply archive logic to an archived help forum post."""
134
144
async for thread_update in archived_post .guild .audit_logs (limit = 50 , action = discord .AuditLogAction .thread_update ):
135
145
if thread_update .target .id != archived_post .id :
@@ -140,7 +150,7 @@ async def help_post_archived(archived_post: discord.Thread) -> None:
140
150
if thread_update .user .id == bot .instance .user .id :
141
151
return
142
152
143
- await _close_help_post (archived_post , _stats .ClosingReason .NATIVE )
153
+ await _close_help_post (archived_post , _stats .ClosingReason .NATIVE , scheduler )
144
154
145
155
146
156
async def help_post_deleted (deleted_post_event : discord .RawThreadDeleteEvent ) -> None :
@@ -204,7 +214,7 @@ async def maybe_archive_idle_post(post: discord.Thread, scheduler: scheduling.Sc
204
214
log .info (
205
215
f"#{ post } ({ post .id } ) is idle past { closing_time } and will be archived. Reason: { closing_reason .value } "
206
216
)
207
- await _close_help_post (post , closing_reason )
217
+ await _close_help_post (post , closing_reason , scheduler )
208
218
return
209
219
210
220
if post .id in scheduler :
0 commit comments