refactor(skills): eliminate shared/ folder, co-locate scripts per skill
Copy ntfy_send.sh into each skill's own scripts/ directory instead of referencing a shared utility folder. The skills/ directory should only contain individual skill folders. - prayer-times: ntfy_send.sh now at scripts/ntfy_send.sh (local) - reminder: ntfy_send.sh now at scripts/ntfy_send.sh (local) - Delete skills/shared/ directory entirely
This commit is contained in:
parent
f208f90f6d
commit
3a918c7d33
4 changed files with 51 additions and 7 deletions
|
|
@ -19,8 +19,8 @@ SKILL_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||||
DATA_DIR="${PRAYER_DATA_DIR:-$SKILL_DIR/data}"
|
DATA_DIR="${PRAYER_DATA_DIR:-$SKILL_DIR/data}"
|
||||||
CONFIG_FILE="$DATA_DIR/config"
|
CONFIG_FILE="$DATA_DIR/config"
|
||||||
|
|
||||||
# Locate shared ntfy_send.sh relative to this script
|
# ntfy_send.sh lives alongside this script
|
||||||
NTFY_SEND="${SCRIPT_DIR}/../../shared/scripts/ntfy_send.sh"
|
NTFY_SEND="${SCRIPT_DIR}/ntfy_send.sh"
|
||||||
|
|
||||||
mkdir -p "$DATA_DIR"
|
mkdir -p "$DATA_DIR"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -167,11 +167,11 @@ mkdir -p skills/reminder/data && echo 'NTFY_TOPIC="https://ntfy.sh/USER_TOPIC"'
|
||||||
|
|
||||||
## ntfy Push Notification
|
## ntfy Push Notification
|
||||||
|
|
||||||
Gunakan shared helper script. **WAJIB source config sendiri sebelum panggil ntfy_send.sh**:
|
Gunakan helper script milik skill ini. **WAJIB source config sendiri sebelum panggil ntfy_send.sh**:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Semua perintah ntfy harus diawali source config
|
# Semua perintah ntfy harus diawali source config
|
||||||
source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash skills/shared/scripts/ntfy_send.sh "MESSAGE" --title "JUDUL" --tags alarm_clock
|
source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash skills/reminder/scripts/ntfy_send.sh "MESSAGE" --title "JUDUL" --tags alarm_clock
|
||||||
```
|
```
|
||||||
|
|
||||||
> **JANGAN pakai curl langsung** ke ntfy. Selalu gunakan `ntfy_send.sh` agar URL dibaca dari config.
|
> **JANGAN pakai curl langsung** ke ntfy. Selalu gunakan `ntfy_send.sh` agar URL dibaca dari config.
|
||||||
|
|
@ -186,7 +186,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash
|
||||||
```
|
```
|
||||||
**Job 2 — ntfy push:**
|
**Job 2 — ntfy push:**
|
||||||
```json
|
```json
|
||||||
{"action": "add", "message": "ntfy: meeting", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/shared/scripts/ntfy_send.sh 'Meeting dengan tim marketing!' --title Reminder --tags alarm_clock", "at_seconds": 600}
|
{"action": "add", "message": "ntfy: meeting", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Meeting dengan tim marketing!' --title Reminder --tags alarm_clock", "at_seconds": 600}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Recurring reminder (2 jobs)
|
### Recurring reminder (2 jobs)
|
||||||
|
|
@ -197,7 +197,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash
|
||||||
```
|
```
|
||||||
**Job 2 — ntfy push:**
|
**Job 2 — ntfy push:**
|
||||||
```json
|
```json
|
||||||
{"action": "add", "message": "ntfy: minum air", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/shared/scripts/ntfy_send.sh 'Jangan lupa minum air!' --title Hydration --tags droplet", "every_seconds": 3600}
|
{"action": "add", "message": "ntfy: minum air", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Jangan lupa minum air!' --title Hydration --tags droplet", "every_seconds": 3600}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Daily cron reminder (2 jobs)
|
### Daily cron reminder (2 jobs)
|
||||||
|
|
@ -208,7 +208,7 @@ source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC="$NTFY_TOPIC" bash
|
||||||
```
|
```
|
||||||
**Job 2 — ntfy push:**
|
**Job 2 — ntfy push:**
|
||||||
```json
|
```json
|
||||||
{"action": "add", "message": "ntfy: daily review", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/shared/scripts/ntfy_send.sh 'Saatnya review laporan harian' --title 'Daily Review' --tags memo", "cron_expr": "0 17 * * 1-5"}
|
{"action": "add", "message": "ntfy: daily review", "command": "source skills/reminder/data/ntfy.conf 2>/dev/null; NTFY_TOPIC=\"$NTFY_TOPIC\" bash skills/reminder/scripts/ntfy_send.sh 'Saatnya review laporan harian' --title 'Daily Review' --tags memo", "cron_expr": "0 17 * * 1-5"}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Daily report via agent (1 job only, no ntfy)
|
### Daily report via agent (1 job only, no ntfy)
|
||||||
|
|
|
||||||
44
workspace/skills/reminder/scripts/ntfy_send.sh
Normal file
44
workspace/skills/reminder/scripts/ntfy_send.sh
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# ntfy_send.sh — Stateless ntfy notification sender utility
|
||||||
|
# Does NOT manage its own config. Reads NTFY_TOPIC from environment variable.
|
||||||
|
# Each skill is responsible for setting NTFY_TOPIC from its own config.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message"
|
||||||
|
# NTFY_TOPIC=https://ntfy.sh/topic ntfy_send.sh "message" --title "T" --tags "t" --priority "high"
|
||||||
|
#
|
||||||
|
# If NTFY_TOPIC is empty, silently skips (exit 0).
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
if [ -z "${NTFY_TOPIC:-}" ]; then
|
||||||
|
# No topic configured — skip silently so cron jobs don't fail
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
message="${1:-}"
|
||||||
|
if [ -z "$message" ]; then
|
||||||
|
echo "Usage: ntfy_send.sh \"message\" [--title T] [--tags T] [--priority P]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
|
||||||
|
# Parse optional flags
|
||||||
|
title="" tags="" priority=""
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--title) title="$2"; shift 2 ;;
|
||||||
|
--tags) tags="$2"; shift 2 ;;
|
||||||
|
--priority) priority="$2"; shift 2 ;;
|
||||||
|
*) shift ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# Build curl args
|
||||||
|
curl_args=(-sf)
|
||||||
|
[ -n "$title" ] && curl_args+=(-H "Title: $title")
|
||||||
|
[ -n "$tags" ] && curl_args+=(-H "Tags: $tags")
|
||||||
|
[ -n "$priority" ] && curl_args+=(-H "Priority: $priority")
|
||||||
|
curl_args+=(-d "$message" "$NTFY_TOPIC")
|
||||||
|
|
||||||
|
curl "${curl_args[@]}" > /dev/null 2>&1 || true
|
||||||
Loading…
Add table
Reference in a new issue