sync: auto-sync from GURU-5070 at 2026-07-01 15:49:56
Author: Mike Swanson Machine: GURU-5070 Timestamp: 2026-07-01 15:49:56
This commit is contained in:
@@ -99,17 +99,45 @@ if [ "$MODE" = "dm" ]; then
|
||||
TARGET="$CHID"
|
||||
fi
|
||||
|
||||
# --- post the message (printf | --data-binary @- — direct -d mangles multiline JSON) ---
|
||||
RESP="$(printf '%s' "$(jq -nc --arg c "$MSG" '{content:$c}')" | \
|
||||
curl -s -m 15 -w $'\n%{http_code}' "${auth[@]}" \
|
||||
-X POST "$API/channels/${TARGET}/messages" --data-binary @-)"
|
||||
HTTP="$(printf '%s' "$RESP" | tail -n1)"
|
||||
BODY="$(printf '%s' "$RESP" | sed '$d')"
|
||||
# --- 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
|
||||
# added, so the receiver can copy-paste the sequence back together verbatim.
|
||||
LIMIT=1900
|
||||
CHUNKS=()
|
||||
rest="$MSG"
|
||||
while [ "${#rest}" -gt "$LIMIT" ]; do
|
||||
piece="${rest:0:$LIMIT}"
|
||||
at_nl="${piece%$'\n'*}" # cut at the last newline in the window
|
||||
if [ "${#at_nl}" -lt "${#piece}" ] && [ "${#at_nl}" -gt 0 ]; then
|
||||
piece="$at_nl"
|
||||
fi
|
||||
CHUNKS+=("$piece")
|
||||
rest="${rest:${#piece}}"
|
||||
rest="${rest#$'\n'}"
|
||||
done
|
||||
CHUNKS+=("$rest")
|
||||
|
||||
if [ "$HTTP" = "200" ]; then
|
||||
# --- post the message (jq | --data-binary @- — argv/-d mangles multiline + non-ASCII JSON) ---
|
||||
N=${#CHUNKS[@]}
|
||||
i=0
|
||||
for piece in "${CHUNKS[@]}"; do
|
||||
i=$((i+1))
|
||||
RESP="$(printf '%s' "$(jq -nc --arg c "$piece" '{content:$c}')" | \
|
||||
curl -s -m 15 -w $'\n%{http_code}' "${auth[@]}" \
|
||||
-X POST "$API/channels/${TARGET}/messages" --data-binary @-)"
|
||||
HTTP="$(printf '%s' "$RESP" | tail -n1)"
|
||||
BODY="$(printf '%s' "$RESP" | sed '$d')"
|
||||
if [ "$HTTP" != "200" ]; then
|
||||
echo "[ERROR] discord-dm: Discord returned ${HTTP:-no-response} on chunk ${i}/${N} — ${BODY}" >&2
|
||||
bash "$ROOT/.claude/scripts/log-skill-error.sh" "discord-dm" "Discord send to $LABEL failed (chunk ${i}/${N})" --context "http=${HTTP:-none} resp=${BODY:0:80}" >/dev/null 2>&1
|
||||
exit 3
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$N" -gt 1 ]; then
|
||||
echo "[OK] discord-dm: sent to ${LABEL} in ${N} chunks (message_id=$(printf '%s' "$BODY" | jq -r '.id // empty'))"
|
||||
else
|
||||
echo "[OK] discord-dm: sent to ${LABEL} (message_id=$(printf '%s' "$BODY" | jq -r '.id // empty'))"
|
||||
exit 0
|
||||
fi
|
||||
echo "[ERROR] discord-dm: Discord returned ${HTTP:-no-response} — ${BODY}" >&2
|
||||
bash "$ROOT/.claude/scripts/log-skill-error.sh" "discord-dm" "Discord send to $LABEL failed" --context "http=${HTTP:-none} resp=${BODY:0:80}" >/dev/null 2>&1
|
||||
exit 3
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user