Skip to content

Instantly share code, notes, and snippets.

@atcasanova
Created April 24, 2019 20:15
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/fd7fc4c1f61a5e216530a8a0ea1f1d5e to your computer and use it in GitHub Desktop.
Save atcasanova/fd7fc4c1f61a5e216530a8a0ea1f1d5e to your computer and use it in GitHub Desktop.
this bot will beat the game at arin.ga:44444
#!/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=3,sigint
read -n4 line <&3
echo "a">&3
ans=0
score=0 ct=0
trap errar INT
function errar(){ # press ctrl-c to send a wrong answer whenever you want
echo "pontuacao atual: $score" >&2
echo "palpites: $ct" >&2
erro=1
}
while read line; do
# echo "$line" >&2 # uncomment to see progress
if grep -qoE "([0-9] [-+=] ){2,}\?" <<< "$line"; then
line="${line//=*/}"
ans=$((${line}))
(( $erro )) && echo -n "0" >&3 || echo -n "${ans}" >&3
echo "$((++ct)) $score" >palpites.log
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" >&3
done
echo "NEW HIGH SCORE: $score atcasanova" >>logteste.log
fi
done <&3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment