Skip to content

Commit 76f12f7

Browse files
committed
fix: snooze timing
1 parent 2b3a32c commit 76f12f7

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Commands:
2929
* `clearsnoozed`: Clears all snoozed items.
3030

3131
Configuration Options:
32-
* `max_snooze_time`: Sets the maximum duration for snooze.
32+
* `default_snooze_time`: Sets the maximum duration for snooze.
3333
* `snooze_title`: Customizes the title for snooze notifications.
3434
* `snooze_text`: Customizes the text for snooze notifications.
3535
* `unsnooze_text`: Customizes the text for unsnooze notifications.

cogs/modmail.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ async def snooze(self, ctx, *, duration: UserFriendlyTime = None):
23222322
- delete (default): deletes the channel and restores it later
23232323
- move: moves the channel to the configured snoozed category
23242324
Optionally specify a duration, e.g. 'snooze 2d' for 2 days.
2325-
Uses config: max_snooze_time, snooze_title, snooze_text
2325+
Uses config: default_snooze_time, snooze_title, snooze_text
23262326
"""
23272327
thread = ctx.thread
23282328
if thread.snoozed:
@@ -2331,20 +2331,20 @@ async def snooze(self, ctx, *, duration: UserFriendlyTime = None):
23312331
return
23322332
from core.time import ShortTime
23332333

2334-
max_snooze = self.bot.config.get("max_snooze_time")
2335-
if max_snooze is None:
2336-
max_snooze = 604800
2334+
default_snooze = self.bot.config.get("default_snooze_time")
2335+
if default_snooze is None:
2336+
default_snooze = 604800
23372337
else:
23382338
try:
2339-
max_snooze = int((ShortTime(str(max_snooze)).dt - ShortTime("0s").dt).total_seconds())
2339+
default_snooze = int((ShortTime(str(default_snooze)).dt - ShortTime("0s").dt).total_seconds())
23402340
except Exception:
2341-
max_snooze = 604800
2341+
default_snooze = 604800
23422342
if duration:
23432343
snooze_for = int((duration.dt - duration.now).total_seconds())
2344-
if snooze_for > max_snooze:
2345-
snooze_for = max_snooze
2344+
if snooze_for > default_snooze:
2345+
snooze_for = default_snooze
23462346
else:
2347-
snooze_for = max_snooze
2347+
snooze_for = default_snooze
23482348

23492349
# Capacity pre-check: if behavior is move, ensure snoozed category has room (<49 channels)
23502350
behavior = (self.bot.config.get("snooze_behavior") or "delete").lower()
@@ -2425,11 +2425,18 @@ async def snooze(self, ctx, *, duration: UserFriendlyTime = None):
24252425
except Exception:
24262426
pass
24272427

2428-
# Storing snooze_start and snooze_for in the log entry
2428+
# Store snooze_until timestamp for reliable auto-unsnooze
24292429
now = datetime.now(timezone.utc)
2430+
snooze_until = now + timedelta(seconds=snooze_for)
24302431
await self.bot.api.logs.update_one(
24312432
{"recipient.id": str(thread.id)},
2432-
{"$set": {"snooze_start": now.isoformat(), "snooze_for": snooze_for}},
2433+
{
2434+
"$set": {
2435+
"snooze_start": now.isoformat(),
2436+
"snooze_for": snooze_for,
2437+
"snooze_until": snooze_until.isoformat(),
2438+
}
2439+
},
24332440
)
24342441
embed = discord.Embed(
24352442
title=self.bot.config.get("snooze_title") or "Thread Snoozed",
@@ -2557,24 +2564,17 @@ async def snooze_auto_unsnooze_task(self):
25572564
now = datetime.now(timezone.utc)
25582565
snoozed = await self.bot.api.logs.find({"snoozed": True}).to_list(None)
25592566
for entry in snoozed:
2560-
start = entry.get("snooze_start")
2561-
snooze_for = entry.get("snooze_for")
2562-
if not start:
2563-
continue
2564-
start_dt = datetime.fromisoformat(start)
2565-
if snooze_for is not None:
2566-
duration = int(snooze_for)
2567-
else:
2568-
max_snooze = self.bot.config.get("max_snooze_time")
2569-
if max_snooze is None:
2570-
max_snooze = 604800
2571-
duration = int(max_snooze)
2572-
if (now - start_dt).total_seconds() > duration:
2573-
# Auto-unsnooze
2574-
thread = await self.bot.threads.find(recipient_id=int(entry["recipient"]["id"]))
2575-
if thread and thread.snoozed:
2576-
await thread.restore_from_snooze()
2577-
await asyncio.sleep(60)
2567+
snooze_until = entry.get("snooze_until")
2568+
if snooze_until:
2569+
try:
2570+
until_dt = datetime.fromisoformat(snooze_until)
2571+
if now >= until_dt:
2572+
thread = await self.bot.threads.find(recipient_id=int(entry["recipient"]["id"]))
2573+
if thread and thread.snoozed:
2574+
await thread.restore_from_snooze()
2575+
except (ValueError, TypeError):
2576+
pass
2577+
await asyncio.sleep(10)
25782578

25792579
async def process_dm_modmail(self, message: discord.Message) -> None:
25802580
# ... existing code ...

core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class ConfigManager:
135135
"thread_min_characters_response": "Your message is too short to create a thread. Please provide more details.",
136136
"thread_min_characters_footer": "Minimum {min_characters} characters required.",
137137
# --- SNOOZE FEATURE CONFIG ---
138-
"max_snooze_time": 604800, # in seconds, default 7 days
138+
"default_snooze_time": 604800, # in seconds, default 7 days
139139
"snooze_title": "Thread Snoozed",
140140
"snooze_text": "This thread has been snoozed. The channel will be restored when the user replies or a moderator unsnoozes it.",
141141
"unsnooze_text": "This thread has been unsnoozed and restored.",

core/thread.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ async def restore_from_snooze(self):
319319
if self._unsnoozing:
320320
logger.warning(f"Unsnooze already in progress for thread {self.id}, skipping duplicate call")
321321
return False
322-
322+
323323
# Mark that unsnooze is in progress
324324
self._unsnoozing = True
325325

0 commit comments

Comments
 (0)