2022-03-23 15:42:20 +00:00
|
|
|
#!/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
|
2022-03-23 16:07:42 +00:00
|
|
|
# $ salty-chat -i ~/.config/salty/echobot.key -u echo@yourdomain.tld read --post-hook ./echobot.sh
|
2022-03-23 15:42:20 +00:00
|
|
|
|
|
|
|
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"
|