-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhungry-bot
executable file
·68 lines (56 loc) · 1.63 KB
/
hungry-bot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
# Args
CHANNEL=${CHANNEL:-"##pivo"}
SERVER=${SERVER:-"irc.freenode.org"}
NICK=${NICK:-"cobuduzrat"}
IRCDIR=${IRCDIR:-"ircdir"}
TMPFILE=$(mktemp)
WEBSERVER="http://vps2.blaskovic.sk:8099/?menu="
LOOP=true
trap "LOOP=false; echo '/quit' > $IRCDIR/$SERVER/in; sleep 2; exit 0" SIGINT
# ii
set -x
make -C ii
rm -rfv "$IRCDIR/$SERVER"
set +x
./ii/ii -i "$IRCDIR" -s "$SERVER" -n "$NICK" &
while [ ! -d "$IRCDIR/$SERVER" ]; do
echo "Server's still processing our connection..."
sleep 5
done
echo "/j $CHANNEL" > "$IRCDIR/$SERVER/in"
sleep 2
# Parser
while $LOOP; do
change="$(inotifywait -q -e create,modify --format "%e %w%f" -r "$IRCDIR/$SERVER")"
event=(${change})
if [[ "${event[1]}" =~ /out$ ]]; then
x="$(echo ${event[1]} | sed -r 's|^(.*?)/out$|\1|')"
event[1]="$x";
fi
cnt=0;
while read -r date time nick mesg; do
nick="${nick#<}"
nick="${nick%>}"
echo "$mesg" | grep -q -e ^menu -e "^$NICK:"
if [ $? -eq 0 ]
then
# We want menu! # strip whitespace needed!
menu=$(echo "$mesg" | sed "s/menu //" | sed "s/$NICK: //" | sed -e 's/[^-a-zA-Z0-9]//g')
out=$(curl "${WEBSERVER}$menu")
echo "$out"
i=0
while read -r line; do
((i++))
if [ $i -gt 11 ] && [[ $SERVER == *"freenode"* ]]; then # freenode anti-anti-spam
sleep 2
fi
echo "$line" > "${event[1]}/in"
done <<< "$out"
fi
((cnt++))
done < "${event[1]}/out"
sed -i'' "1,$cnt d" "${event[1]}/out"
done
# End
rm $TMPFILE