Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
PYBORG="/home/seeschloss/bin/deeborg --file=/home/seeschloss/deeplop-dlfp.db"
COOKIE="linuxfr.org_session="
DEBUG=0
BOTNAME="deeplop"
STATEFILE="$HOME/.deeplop.state"
function post() {
if test "$DEBUG" -gt "0"; then
echo $1
else
MESSAGE=$(echo "$1" | sed 's/&gt;/>/g' | sed 's/&lt;/</g')
UA="DeePlop"
test -n "$2" && UA="$UA ($2)"
curl --referer 'http://linuxfr.org/board' \
--user-agent "$UA" \
--cookie "$COOKIE" \
--header "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \
--data-urlencode "board[message]=$MESSAGE" \
--silent \
'http://linuxfr.org/board' >/dev/null
sleep 1
fi
}
OPTIND=1
while getopts "d" opt; do
case "$opt" in
d) DEBUG=1
;;
esac
done
shift $((OPTIND-1))
function find_my_clocks() {
$HOME/bin/tribune-cli -t -n http://linuxfr.org/board/index.xml | while read -r id time info login message; do
if test "$login" = "$BOTNAME"; then
CLOCK=$(echo $time | sed 's/^........\(..\)\(..\)\(..\)/\1:\2:\3/')
echo $CLOCK
fi
done
}
MYCLOCKS=$(find_my_clocks)
function answer() {
LASTTIME=00:00
LASTUSER=Anonyme
TTL=$4
test -z "$TTL" && TTL=3
USECLOCK=$5
test -z "$USECLOCK" && USECLOCK=1
if [ -e "$STATEFILE" ]; then
read LASTTIME LASTUSER < "$STATEFILE"
fi
NOW=$(echo $1 | tr -d :)
LAST=$(echo $LASTTIME | tr -d :)
let GAP=$NOW-$LAST
if [ "$LASTUSER" != "$3" -o "$GAP" -gt "11" ]; then
REPONSE=$(echo $2 | $PYBORG)
test -z "$REPONSE" && continue
if test "$USECLOCK" -gt 0; then
CLOCK=$(echo $1 | sed 's/^........\(..\)\(..\)\(..\)/\1:\2:\3/')
else
CLOCK=""
fi
post "$CLOCK $REPONSE" "\\o/ $TTL"
echo "$1 $3" > "$STATEFILE"
fi
}
while read -r id time info login message; do
if test "$login" = "$BOTNAME"; then
continue
fi
if test "$login" = "pyplop"; then
continue
fi
if test "$login" = "gle"; then
continue
fi
message=$(echo "$message" | sed "s/<?>//g" | sed "s/<\/?>//g")
if echo $message | fgrep "$BOTNAME&lt;" &>/dev/null; then
message=$(echo "$message" | sed "s/$BOTNAME&lt;//")
answer "$time" "$message" "$login"
continue
fi
if echo $message | fgrep "moules&lt;" &>/dev/null; then
message=$(echo "$message" | sed "s/$BOTNAME&lt;//")
answer "$time" "$message" "$login"
continue
fi
let i=0
for clock in $MYCLOCKS; do
let i++
if test "$i" -gt 3; then
continue
fi
if echo $message | fgrep "$clock" &>/dev/null; then
# une fois sur 500, ne pas répondre
if test $(($RANDOM%500)) -gt 1; then
message=$(echo "$message" | sed "s/$BOTNAME&lt;//")
answer "$time" "$message" "$login"
continue
fi
fi
done
# répondre au hasard à à peu près un post sur cinq cent
if test $(($RANDOM%500)) -eq 1; then
message=$(echo "$message" | sed "s/$BOTNAME&lt;//")
answer "$time" "$message" "$login"
continue
fi
# répondre au hasard à un peu moins d'un post sur deux cent sans horloge
if test $(($RANDOM%200)) -eq 1; then
message=$(echo "$message" | sed "s/$BOTNAME&lt;//")
answer "$time" "$message" "$login" 3 0
continue
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.