Skip to content

Instantly share code, notes, and snippets.

@spacelatte
Last active July 19, 2020 13:51
Show Gist options
  • Save spacelatte/3a56d3a10f36692f18d1c7837eaed632 to your computer and use it in GitHub Desktop.
Save spacelatte/3a56d3a10f36692f18d1c7837eaed632 to your computer and use it in GitHub Desktop.
#irc #bot using #shell #bash #script #remote #exec #code #execution
#!/usr/bin/env bash
#set -x
set -o pipefail
PREFIX=usr
NAME="${PREFIX}$(hostname | cut -d. -f1)"
CHAN="${1:-#test}"
INFO="$(date) $(uname -a)"
PING=10.0
tee /dev/stderr | {
sleep 2
echo "NICK ${NAME}"
echo "USER $(whoami) * * : $(hostname -i)"
sleep 5
echo "JOIN ${CHAN}"
while sleep ${PING}; do echo PING :${RANDOM}; done &
echo "PRIVMSG ${CHAN} :${INFO}"
cat - \
| grep --line-buffered \
-e "PRIVMSG ${CHAN}" \
-e "PRIVMSG ${NAME}" \
| grep --line-buffered -v \
-e "^:${PREFIX}" \
-e "^:${NAME}" \
| stdbuf -i0 -oL -eL cut -d':' -f3- \
| grep --line-buffered -oE '\$.+$' \
| stdbuf -i0 -oL -eL cut -d'$' -f2- \
| stdbuf -i0 -oL -eL tr -d '\r' \
| bash -x /dev/stdin 2>&1 \
| sed -u "s/^/PRIVMSG ${CHAN} :/g" \
| while read line; do
echo "${line}";
sleep 1.${RANDOM}; # flood protection
done
} | tee /dev/stderr
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment