6
1
mirror of https://git.mills.io/saltyim/saltyim.git synced 2024-06-25 00:08:26 +00:00
prologic-saltyim/hooks/echobot.sh
mlctrez 969a263d06 support for contacts, multiple chat threads, and persistence (#77)
Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Co-authored-by: James Mills <james@mills.io>
Co-authored-by: mlctrez <mlctrez@gmail.com>
Reviewed-on: https://git.mills.io/saltyim/saltyim/pulls/77
Co-authored-by: mlctrez <mlctrez@noreply@mills.io>
Co-committed-by: mlctrez <mlctrez@noreply@mills.io>
2022-03-28 21:49:01 +00:00

22 lines
617 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/echo.key -u echo@yourdomain.tld make-user
# $ salty-chat -i ~/.config/salty/echo.key -u echo@yourdomain.tld read --post-hook ./hooks/echobot.sh
set -e
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 send "$sender"