sync: auto-sync from HOWARD-HOME at 2026-07-07 07:23:12
Author: Howard Enos Machine: HOWARD-HOME Timestamp: 2026-07-07 07:23:12
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
# Usage:
|
||||
# discord-dm.sh <recipient> "message text"
|
||||
# echo "message text" | discord-dm.sh <recipient>
|
||||
# discord-dm.sh read <recipient> [limit] # READ recent messages — SEE replies (default 15)
|
||||
# discord-dm.sh list # show known users + channels
|
||||
#
|
||||
# <recipient> is one of:
|
||||
@@ -51,11 +52,29 @@ if [ -z "$RECIPIENT" ] || [ "$RECIPIENT" = "-h" ] || [ "$RECIPIENT" = "--help" ]
|
||||
sed -n '2,30p' "$0"; exit 1
|
||||
fi
|
||||
if [ "$RECIPIENT" = "list" ]; then print_dir; exit 0; fi
|
||||
|
||||
# --- read mode: fetch recent messages so we can SEE replies (mike/winter/etc.).
|
||||
# `discord-dm.sh read <user|#channel> [limit]` — reuses the recipient resolution,
|
||||
# token, and DM-channel-open below, then prints history instead of sending. The
|
||||
# bot participates in each DM channel it opened, so REST history returns full
|
||||
# content (the Message Content intent only gates gateway events, not this fetch).
|
||||
ACTION=send
|
||||
if [ "$RECIPIENT" = "read" ] || [ "$RECIPIENT" = "inbox" ]; then
|
||||
ACTION=read; shift
|
||||
RECIPIENT="${1:-}"
|
||||
[ -z "$RECIPIENT" ] && { echo "[ERROR] usage: discord-dm.sh read <user|#channel> [limit]" >&2; exit 1; }
|
||||
fi
|
||||
shift
|
||||
|
||||
# --- message (remaining args, else stdin) ---
|
||||
if [ "$#" -gt 0 ]; then MSG="$*"; elif [ ! -t 0 ]; then MSG="$(cat)"; else MSG=""; fi
|
||||
if [ -z "$MSG" ]; then echo "[ERROR] empty message — nothing sent" >&2; exit 1; fi
|
||||
# --- message (send) or limit (read) ---
|
||||
if [ "$ACTION" = "read" ]; then
|
||||
READ_LIMIT="${1:-15}"
|
||||
printf '%s' "$READ_LIMIT" | grep -qE '^[0-9]+$' || READ_LIMIT=15
|
||||
[ "$READ_LIMIT" -gt 100 ] && READ_LIMIT=100
|
||||
else
|
||||
if [ "$#" -gt 0 ]; then MSG="$*"; elif [ ! -t 0 ]; then MSG="$(cat)"; else MSG=""; fi
|
||||
if [ -z "$MSG" ]; then echo "[ERROR] empty message — nothing sent" >&2; exit 1; fi
|
||||
fi
|
||||
|
||||
# --- resolve recipient -> mode (dm|channel) + target id ---
|
||||
MODE=""; TARGET=""; LABEL=""
|
||||
@@ -99,6 +118,22 @@ if [ "$MODE" = "dm" ]; then
|
||||
TARGET="$CHID"
|
||||
fi
|
||||
|
||||
# --- read mode: fetch + print recent messages, then exit (no send) ---
|
||||
if [ "$ACTION" = "read" ]; then
|
||||
MSGS="$(curl -s -m 20 "${auth[@]}" "$API/channels/${TARGET}/messages?limit=${READ_LIMIT}")"
|
||||
if ! printf '%s' "$MSGS" | jq -e 'type=="array"' >/dev/null 2>&1; then
|
||||
echo "[ERROR] could not read $LABEL: $(printf '%s' "$MSGS" | head -c 200)" >&2
|
||||
bash "$ROOT/.claude/scripts/log-skill-error.sh" "discord-dm" "read history failed for $LABEL" --context "resp=$(printf '%s' "$MSGS" | head -c 80)" >/dev/null 2>&1
|
||||
exit 3
|
||||
fi
|
||||
echo "[OK] discord-dm: last ${READ_LIMIT} message(s) in ${LABEL} (oldest first; '>>>' = reply from them, ' ' = us):"
|
||||
printf '%s' "$MSGS" | jq -r 'reverse[] |
|
||||
((if (.author.bot // false) then " " else ">>> " end)
|
||||
+ (.timestamp[0:16]) + " " + .author.username + ": "
|
||||
+ ((.content // "") | gsub("\n";" ")))'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# --- chunk: Discord caps content at 2000 chars (code 50035 on overflow).
|
||||
# This tool's job is delivering LONG content intact, so split into <=1900-char
|
||||
# pieces (preferring newline boundaries) and send them in order — no markers
|
||||
|
||||
Reference in New Issue
Block a user