Skip to content

Instantly share code, notes, and snippets.

@atcasanova
Created April 22, 2019 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atcasanova/3a7890436b23bb0e5d31e104f6f5997b to your computer and use it in GitHub Desktop.
Save atcasanova/3a7890436b23bb0e5d31e104f6f5997b to your computer and use it in GitHub Desktop.
this bot will put your name in github.com/izabera 1-2-3 ranking
#!/bin/bash
# this bot will put your name in izabera's 1-2-3 ranking
# https://github.com/izabera/1-2-3
# run it with socat like:
# socat TCP4:arin.ga:44444 EXEC:/full/path/to/record.sh,fdin=3,fdout=4
#
read -n4 line <&3
echo "a">&4
ans=0
score=0
while read line; do
echo "$line" >&2
if grep -qoE "([0-9] [-+=] ){2,}\?" <<< "$line"; then
line="${line//=*/}"
(( ${score:-0} <= 783909 )) && ans=$((${line})) || ans=9
echo -n "${ans}" >&4
elif grep -qoE "score: [0-9]+" <<< "$line"; then
score=$(grep -Eo ": [0-9]+" <<< "$line")
score="${score/: /}"
elif fgrep -q "new high score!" <<< "$line"; then
sleep 3;
for i in a t c a s a n o v a a t c a s a n o v a ; do
echo -n "$i" >&4
done
fi
done <&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment