feat: Implement temporary hold management with config integration and improved notifications

fixes #19
This commit is contained in:
2025-11-09 10:11:00 -05:00
parent b6aae121bb
commit 9da21f7c89
3 changed files with 88 additions and 85 deletions

View File

@@ -20,7 +20,6 @@ class ScheduleMonitor:
self.last_check = 0
self.current_schedule = None
self.last_applied_schedule = None
self.temp_hold_start_time = None # When temporary hold was activated
self.temp_hold_duration = config.get('temp_hold_duration', 3600) # Use config value, default 1 hour
def should_run(self):
@@ -137,40 +136,33 @@ class ScheduleMonitor:
# ===== START: Check if temporary hold has expired =====
if not self.config.get('schedule_enabled', False) and not self.config.get('permanent_hold', False):
# We're in temporary hold mode
if self.temp_hold_start_time is None:
# Just entered hold mode, record start time
self.temp_hold_start_time = time.time()
print("⏸️ Temporary hold started - will auto-resume in {} minutes".format(
self.temp_hold_duration // 60
))
else:
# Check if hold has expired
elapsed = time.time() - self.temp_hold_start_time
# In temporary hold mode - check if timer expired
temp_hold_start = self.config.get('temp_hold_start_time') # <-- READ FROM CONFIG NOW
if temp_hold_start is not None:
elapsed = time.time() - temp_hold_start
if elapsed >= self.temp_hold_duration:
# Hold expired, resume schedules
print("⏰ Temporary hold expired - resuming automatic mode")
# Timer expired - resume automatic scheduling
print("⏰ Temporary hold expired - resuming schedule")
self.config['schedule_enabled'] = True
self.config['permanent_hold'] = False
self.temp_hold_start_time = None
self.config['temp_hold_start_time'] = None
# Save updated config
try:
import json
with open('config.json', 'w') as f:
json.dump(self.config, f)
except:
pass
print("✅ Config updated - automatic mode resumed")
except Exception as e:
print("⚠️ Could not save config: {}".format(e))
# Send Discord notification
# Notify user
try:
from scripts.discord_webhook import send_discord_message
send_discord_message("⏰ Temporary hold expired - Automatic mode resumed")
send_discord_message("⏰ Temporary hold expired - Schedule resumed automatically")
except:
pass
else:
# Not in temporary hold, reset timer
self.temp_hold_start_time = None
# ===== END: Check if temporary hold has expired =====
# Find and apply active schedule