Something went wrong. Try again.
Dotfiles for my macos setup
Something went wrong. Try again.
2.4 kB · 69 lines
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970#!/usr/bin/env bashset -euo pipefail# Summarize the last 24h of selected Discord channels via DiscordChatExporter + kagi assistant.## Requirements:# - DiscordChatExporter.Cli (https://github.com/Tyrrrz/DiscordChatExporter)# default path below; override with DCE_CMD if installed elsewhere.# - kagi-cli authenticated with a session token.## Config:# ~/.config/discord-summary/config (sourced bash)# DISCORD_TOKEN="your-user-token"# CHANNELS=(# "111111111111111111:general"# "222222222222222222:dev-chat"# ) # format "<channel_id>:<label>"## WARNING: uses your personal Discord token. Automating a user account violates# Discord's ToS. This runs once and exits to minimize risk; use at your own peril.CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/discord-summary/config"DCE_CMD="${DCE_CMD:-$HOME/.local/bin/DiscordChatExporter.Cli.osx-arm64/DiscordChatExporter.Cli}"HOURS="${HOURS:-24}"[[ -f "$CONFIG" ]] || { echo "missing config: $CONFIG" >&2; exit 1; }# shellcheck disable=SC1090source "$CONFIG": "${DISCORD_TOKEN:?set DISCORD_TOKEN in config}"[[ "${#CHANNELS[@]}" -gt 0 ]] || { echo "no CHANNELS defined in config" >&2; exit 1; }command -v "$DCE_CMD" >/dev/null || { echo "DiscordChatExporter not found ($DCE_CMD)" >&2; exit 1; }command -v kagi >/dev/null || { echo "kagi-cli not found" >&2; exit 1; }after="$(date -u -v-"${HOURS}"H '+%Y-%m-%d %H:%M' 2>/dev/null \ || date -u -d "${HOURS} hours ago" '+%Y-%m-%d %H:%M')"workdir="$(mktemp -d)"trap 'rm -rf "$workdir"' EXITprompt='Summarize the following Discord channel log from the last 24 hours.Give a concise bulleted digest: key topics, decisions, questions raised, andanything actionable. Skip greetings and noise. If nothing substantive happened,say so in one line.'for entry in "${CHANNELS[@]}"; do cid="${entry%%:*}" label="${entry#*:}" out="$workdir/$cid.txt" "$DCE_CMD" export \ -t "$DISCORD_TOKEN" \ -c "$cid" \ --after "$after" \ -f PlainText \ -o "$out" >/dev/null 2>&1 || { echo "## $label — export failed"; echo; continue; } printf '\033[1;36m## %s\033[0m\n' "$label" if [[ ! -s "$out" ]] || [[ "$(wc -l <"$out")" -lt 5 ]]; then echo " (no messages in the last ${HOURS}h)" echo continue fi message="$(printf '%s\n\nChannel #%s log:\n---\n%s' "$prompt" "$label" "$(cat "$out")")" kagi assistant --format pretty "$message" echodone