Created
April 22, 2019 19:31
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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