-
Notifications
You must be signed in to change notification settings - Fork 1
/
frontend.sh
executable file
·129 lines (98 loc) · 2.78 KB
/
frontend.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
# Probably works with other shells too, not tested
#
# Weekybot v0.1 frontend
#
# Copyright William Hales 2014
#
# This file is part of Weekybot
#
# Weekybot is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Weekybot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Weekybot. If not, see <http://www.gnu.org/licenses/>.
# Very hacky:
# * written by someone with little IRC protocol knowledge
# * uses lots of sleeps
# * probably doesn't handle IRC events/problems
port=6667
server="irc.freenode.net"
channel="unvanquished-dev"
nick="regnarg"
which ii &> /dev/null
if [ $? -ne 0 ]
then
echo "Can't find ii. http://tools.suckless.org/ii/"
echo "ii is the irc backend for the python middle-end"
exit 1
fi
execdir="$(pwd)"
if ( ls | grep -q 'middleend.py' )
then
# All good
:
else
echo "Can't find middleend.py"
echo "Please execute me from my dir"
exit 2
fi
workingdir="/tmp/Weekybot${RANDOM}"
mkdir $workingdir
cd $workingdir
# IRC backend
ii -s $server -n $nick -p $port -i . &
iipid=$!
cleanup()
{
echo
echo "Recieved a signal. Leaving server and cleaning up"
echo '/quit' > ${workingdir}/*/in
sleep 5
rm -r "${workingdir}"
exit 0
}
trap 'cleanup' 1 2 3 6 # TODO: refine signal list
## Main block
echo -n "Connecting to ${server}... "
while [ $(ls | wc -l) -eq 0 ]; do sleep 1; done
echo 'done'
cd $server
#sleep 1 # Neccesary?
echo -n 'Waiting for +i... '
until ( grep -q 'End of /MOTD command' out ) do sleep 1; done # freenode specific?
echo "recieved"
echo "/join #${channel}" > in
echo -n 'Waiting to confirm channel join... '
until ( ls | grep -q "$channel" ); do sleep 1; done
cd "#${channel}"
until ( grep -q "has joined" out ); do sleep 1; done
echo 'done'
echo -e '(Running the middleend script)'
${execdir}/middleend.py > in &
# Rudimentary response capability
tail -f -n1 out | while read line
do
if ( echo $line | grep -qi "<${nick}>" )
then
# Don't respond to my own chat!
# This could end in infinite loops
:
elif ( echo $line | grep -qi "${nick}:")
then
if ( echo $line | grep -qi "force")
then
${execdir}/middleend.py once > in
else
echo "\"${nick}\" is weekybot, an IRC bot that periodically scrapes mediawiki atom feeds for changes." > in
echo "Ask me to 'force' if you want an update right now. See https://github.com/Veyrdite/weekybot for more details" > in
fi
fi
done