Fresh start - excluded large ROM JSON files
This commit is contained in:
81
tools/reminder-bot.py
Normal file
81
tools/reminder-bot.py
Normal file
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Discord Reminder Bot - Called by OpenClaw cron to deliver reminders
|
||||
Uses the message tool to actually post to Discord
|
||||
"""
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
DB_PATH = os.path.expanduser("~/.openclaw/workspace/data/reminders.db")
|
||||
|
||||
|
||||
def get_due_reminders():
|
||||
"""Get reminders that are due now."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
c = conn.cursor()
|
||||
c.execute('''SELECT id, user_id, channel_id, message, remind_at
|
||||
FROM reminders
|
||||
WHERE active = 1 AND remind_at <= datetime('now')''')
|
||||
results = c.fetchall()
|
||||
conn.close()
|
||||
return results
|
||||
|
||||
|
||||
def mark_reminder_sent(reminder_id):
|
||||
"""Mark reminder as inactive after sending."""
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
c = conn.cursor()
|
||||
c.execute('UPDATE reminders SET active = 0 WHERE id = ?', (reminder_id,))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
|
||||
def format_reminder_message(message, user_id):
|
||||
"""Format the reminder with mention."""
|
||||
return f"🔔 **Reminder for <@{user_id}>:** {message}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Check for specific reminder ID (from cron)
|
||||
if len(sys.argv) > 1:
|
||||
reminder_id = int(sys.argv[1])
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
c = conn.cursor()
|
||||
c.execute('''SELECT id, user_id, channel_id, message, remind_at
|
||||
FROM reminders WHERE id = ? AND active = 1''', (reminder_id,))
|
||||
result = c.fetchone()
|
||||
conn.close()
|
||||
|
||||
if result:
|
||||
# Output JSON for the agent to use with message tool
|
||||
output = {
|
||||
"action": "send_reminder",
|
||||
"reminder_id": result[0],
|
||||
"user_id": result[1],
|
||||
"channel_id": result[2],
|
||||
"message": result[3],
|
||||
"formatted": format_reminder_message(result[3], result[1])
|
||||
}
|
||||
print(json.dumps(output))
|
||||
else:
|
||||
print(json.dumps({"error": "Reminder not found or already sent"}))
|
||||
else:
|
||||
# Check for any due reminders
|
||||
due = get_due_reminders()
|
||||
if due:
|
||||
for r in due:
|
||||
output = {
|
||||
"action": "send_reminder",
|
||||
"reminder_id": r[0],
|
||||
"user_id": r[1],
|
||||
"channel_id": r[2],
|
||||
"message": r[3],
|
||||
"formatted": format_reminder_message(r[3], r[1])
|
||||
}
|
||||
print(json.dumps(output))
|
||||
else:
|
||||
print(json.dumps({"status": "no_due_reminders"}))
|
||||
Reference in New Issue
Block a user