6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-28 17:51:04 +00:00
prologic-saltyim/hooks/echobot.sh

28 lines
739 B
Bash
Executable File

#!/bin/sh
# A Salty IM Echo Bot written as a POSIX Shell script using salty-chat read'
# --post-hook mechanism.
#
# Setup:
#
# $ salty-chat -i ~/.config/salty/echobot.key -u echo@yourdomain.tld make-user
# $ salty-chat -i ~/.config/salty/echobot.key -u echo@yourdomain.tld read --post-hook ./echobot.sh
set -e
# XXX: Set this to the echobot's key
identity=
# XXX: Set this to the echobot's addr
user=
tmpfile="$(mktemp -t "echobot-XXXXXX")"
trap 'rm $tmpfile' EXIT
cat > "$tmpfile"
sender="$(head -n 1 < "$tmpfile" | awk '{ print $2 }')"
sender="$(echo "$sender" | sed 's/[)(]//g')"
message="$(head -n 1 < "$tmpfile" | awk '{ $1 = ""; $2 = ""; print $0; }')"
echo "$message" | salty-chat -d -i "$identity" -u "$user" send "$sender"