104 lines
2.8 KiB
PowerShell
104 lines
2.8 KiB
PowerShell
#!/usr/bin/env pwsh
|
|
<#
|
|
.SYNOPSIS
|
|
Discord Reminder Handler - Called by OpenClaw to process reminder commands
|
|
.DESCRIPTION
|
|
Handles: add, list, delete, cleanup
|
|
.EXAMPLE
|
|
.\reminder-handler.ps1 add "458667380332036117" "1474636036905631867" "Call mom" "2h"
|
|
.\reminder-handler.ps1 list
|
|
.\reminder-handler.ps1 delete 5
|
|
#>
|
|
|
|
$action = $args[0]
|
|
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$pythonScript = Join-Path $scriptDir "reminder-manager.py"
|
|
|
|
function Get-RemindersJson {
|
|
$json = & python $pythonScript "list" | Out-String
|
|
return $json | ConvertFrom-Json
|
|
}
|
|
|
|
switch ($action) {
|
|
"add" {
|
|
$userId = $args[1]
|
|
$channelId = $args[2]
|
|
$message = $args[3]
|
|
$time = $args[4]
|
|
|
|
if (-not $userId -or -not $message -or -not $time) {
|
|
Write-Error "Usage: add <user_id> <channel_id> <message> <time>"
|
|
exit 1
|
|
}
|
|
|
|
# Add to database
|
|
$result = & python $pythonScript "add" $userId $channelId $message $time | Out-String
|
|
$reminder = $result | ConvertFrom-Json
|
|
|
|
if ($reminder.error) {
|
|
Write-Error $reminder.error
|
|
exit 1
|
|
}
|
|
|
|
Write-Output "@{reminder_id:$($reminder.id)}"
|
|
}
|
|
|
|
"list" {
|
|
$userId = $args[1]
|
|
$reminders = Get-RemindersJson
|
|
|
|
if ($userId) {
|
|
$reminders = $reminders | Where-Object { $_.user_id -eq $userId }
|
|
}
|
|
|
|
if ($reminders.Count -eq 0) {
|
|
Write-Output "No active reminders."
|
|
} else {
|
|
$reminders | ForEach-Object {
|
|
$when = [datetime]::Parse($_.remind_at).ToString("MMM d '\at' h:mm tt")
|
|
Write-Output "`#$($_.id): $($_.message) - $when"
|
|
}
|
|
}
|
|
}
|
|
|
|
"delete" {
|
|
$id = $args[1]
|
|
if (-not $id) {
|
|
Write-Error "Usage: delete <reminder_id>"
|
|
exit 1
|
|
}
|
|
|
|
$result = & python $pythonScript "delete" $id | Out-String
|
|
$data = $result | ConvertFrom-Json
|
|
|
|
if ($data.deleted) {
|
|
Write-Output "Reminder#$id cancelled."
|
|
} else {
|
|
Write-Error "Reminder not found."
|
|
}
|
|
}
|
|
|
|
"cleanup" {
|
|
& python $pythonScript "cleanup"
|
|
}
|
|
|
|
default {
|
|
Write-Output @"
|
|
Discord Reminder Handler
|
|
|
|
Usage: reminder-handler.ps1 <command> [args]
|
|
|
|
Commands:
|
|
add <user_id> <channel_id> <message> <time> Add a reminder
|
|
list [user_id] List reminders
|
|
delete <id> Cancel a reminder
|
|
cleanup Remove old entries
|
|
|
|
Time formats:
|
|
20m, 2h, 1h30m - Relative time
|
|
9am, 2:30pm - Today at time
|
|
tomorrow 9am - Tomorrow at time
|
|
"@
|
|
}
|
|
}
|