@@ -154,26 +154,27 @@ async def snooze(self, moderator=None, command_used=None):
154
154
"attachments" : [a .url for a in m .attachments ],
155
155
"embeds" : [e .to_dict () for e in m .embeds ],
156
156
"created_at" : m .created_at .isoformat (),
157
- "type" : getattr (m , ' type' , None ),
158
- "author_name" : getattr (m .author , ' name' , None ),
157
+ "type" : getattr (m , " type" , None ),
158
+ "author_name" : getattr (m .author , " name" , None ),
159
159
}
160
160
async for m in channel .history (limit = None , oldest_first = True )
161
161
],
162
- ' snoozed_by' : getattr (moderator , ' name' , None ) if moderator else None ,
163
- ' snooze_command' : command_used ,
162
+ " snoozed_by" : getattr (moderator , " name" , None ) if moderator else None ,
163
+ " snooze_command" : command_used ,
164
164
}
165
165
self .snoozed = True
166
166
# Save to DB (robust: try recipient.id, then channel_id)
167
167
result = await self .bot .api .logs .update_one (
168
- {' recipient.id' : str (self .id )},
169
- {' $set' : {' snoozed' : True , ' snooze_data' : self .snooze_data }},
168
+ {" recipient.id" : str (self .id )},
169
+ {" $set" : {" snoozed" : True , " snooze_data" : self .snooze_data }},
170
170
)
171
171
if result .modified_count == 0 and self .channel :
172
172
result = await self .bot .api .logs .update_one (
173
- {' channel_id' : str (self .channel .id )},
174
- {' $set' : {' snoozed' : True , ' snooze_data' : self .snooze_data }},
173
+ {" channel_id" : str (self .channel .id )},
174
+ {" $set" : {" snoozed" : True , " snooze_data" : self .snooze_data }},
175
175
)
176
176
import logging
177
+
177
178
logging .info (f"[SNOOZE] DB update result: { result .modified_count } " )
178
179
# Delete channel
179
180
await channel .delete (reason = "Thread snoozed by moderator" )
@@ -186,11 +187,14 @@ async def restore_from_snooze(self):
186
187
"""
187
188
if not self .snooze_data or not isinstance (self .snooze_data , dict ):
188
189
import logging
189
- logging .warning (f"[UNSNOOZE] Tried to restore thread { self .id } but snooze_data is None or not a dict." )
190
+
191
+ logging .warning (
192
+ f"[UNSNOOZE] Tried to restore thread { self .id } but snooze_data is None or not a dict."
193
+ )
190
194
return False
191
195
# Now safe to access self.snooze_data
192
- snoozed_by = self .snooze_data .get (' snoozed_by' )
193
- snooze_command = self .snooze_data .get (' snooze_command' )
196
+ snoozed_by = self .snooze_data .get (" snoozed_by" )
197
+ snooze_command = self .snooze_data .get (" snooze_command" )
194
198
guild = self .bot .modmail_guild
195
199
category = guild .get_channel (self .snooze_data ["category_id" ])
196
200
overwrites = {}
@@ -210,18 +214,18 @@ async def restore_from_snooze(self):
210
214
)
211
215
self ._channel = channel
212
216
# Replay messages
213
- for msg in self .snooze_data [' messages' ]:
214
- author = self .bot .get_user (msg [' author_id' ]) or await self .bot .get_or_fetch_user (msg [' author_id' ])
215
- content = msg [' content' ]
216
- embeds = [discord .Embed .from_dict (e ) for e in msg .get (' embeds' , []) if e ]
217
- attachments = msg .get (' attachments' , [])
218
- msg_type = msg .get (' type' )
217
+ for msg in self .snooze_data [" messages" ]:
218
+ author = self .bot .get_user (msg [" author_id" ]) or await self .bot .get_or_fetch_user (msg [" author_id" ])
219
+ content = msg [" content" ]
220
+ embeds = [discord .Embed .from_dict (e ) for e in msg .get (" embeds" , []) if e ]
221
+ attachments = msg .get (" attachments" , [])
222
+ msg_type = msg .get (" type" )
219
223
# Only send if there is content, embeds, or attachments
220
224
if not content and not embeds and not attachments :
221
225
continue # Skip empty messages
222
226
# Format internal/system/mod-only messages as 'username: textcontent'
223
- if msg_type in (' internal' , ' note' , ' system' , ' mod_only' ):
224
- username = msg .get (' author_name' ) or (getattr (author , ' name' , None )) or ' Unknown'
227
+ if msg_type in (" internal" , " note" , " system" , " mod_only" ):
228
+ username = msg .get (" author_name" ) or (getattr (author , " name" , None )) or " Unknown"
225
229
formatted = f"{ username } : { content } " if content else username
226
230
await channel .send (formatted )
227
231
else :
@@ -232,29 +236,30 @@ async def restore_from_snooze(self):
232
236
self .snooze_data = None
233
237
# Update channel_id in DB and clear snooze_data (robust: try recipient.id, then channel_id)
234
238
result = await self .bot .api .logs .update_one (
235
- {' recipient.id' : str (self .id )},
236
- {' $set' : {' snoozed' : False , ' channel_id' : str (channel .id )}, ' $unset' : {' snooze_data' : "" }},
239
+ {" recipient.id" : str (self .id )},
240
+ {" $set" : {" snoozed" : False , " channel_id" : str (channel .id )}, " $unset" : {" snooze_data" : "" }},
237
241
)
238
242
if result .modified_count == 0 :
239
243
result = await self .bot .api .logs .update_one (
240
- {' channel_id' : str (channel .id )},
241
- {' $set' : {' snoozed' : False , ' channel_id' : str (channel .id )}, ' $unset' : {' snooze_data' : "" }},
244
+ {" channel_id" : str (channel .id )},
245
+ {" $set" : {" snoozed" : False , " channel_id" : str (channel .id )}, " $unset" : {" snooze_data" : "" }},
242
246
)
243
247
import logging
248
+
244
249
logging .info (f"[UNSNOOZE] DB update result: { result .modified_count } " )
245
250
# Notify in the configured channel
246
251
notify_channel = self .bot .config .get ("unsnooze_notify_channel" ) or "thread"
247
252
notify_text = self .bot .config .get ("unsnooze_text" ) or "This thread has been unsnoozed and restored."
248
- if notify_channel == ' thread' :
253
+ if notify_channel == " thread" :
249
254
await channel .send (notify_text )
250
255
else :
251
256
ch = self .bot .get_channel (int (notify_channel ))
252
257
if ch :
253
258
await ch .send (f"Thread for user <@{ self .id } > has been unsnoozed and restored." )
254
259
# Show who ran the snooze command and the command used
255
260
# Use snooze_data_for_notify to avoid accessing self.snooze_data after it is set to None
256
- snoozed_by = snooze_data_for_notify .get (' snoozed_by' ) if snooze_data_for_notify else None
257
- snooze_command = snooze_data_for_notify .get (' snooze_command' ) if snooze_data_for_notify else None
261
+ snoozed_by = snooze_data_for_notify .get (" snoozed_by" ) if snooze_data_for_notify else None
262
+ snooze_command = snooze_data_for_notify .get (" snooze_command" ) if snooze_data_for_notify else None
258
263
if snoozed_by or snooze_command :
259
264
info = f"Snoozed by: { snoozed_by or 'Unknown' } | Command: { snooze_command or '?snooze' } "
260
265
await channel .send (info )
0 commit comments