]> Pileus Git - ~andy/rhawk/blob - rhawk
Fix topic parsing and cleanup globals
[~andy/rhawk] / rhawk
1 #!awk -f
2
3 @include "irc.awk"
4 @include "json.awk"
5 @include "spades.awk"
6 #@include "email.awk"
7
8 # Initialization
9 BEGIN {
10         json_load("var/login.json", login);
11         json_load("var/plain.json", plain);
12
13         OWNER = login["owner"];
14
15         connect(login["server"],  \
16                 login["nick"],    \
17                 login["channel"], \
18                 login["auth"],    \
19                 login["pass"])
20
21         delete login
22
23         if (FIRST) {
24                 join("#rhnoise")
25                 join("#rhspades")
26                 join("#sfvlug")
27         }
28 }
29
30 # Admin
31 AUTH == OWNER && TO == NICK && /^die in a fire/ {
32         say("Ack, argh, barasdjf..")
33         quit()
34 }
35
36 AUTH == OWNER && TO == NICK && /^reload/ {
37         say("Reloading..")
38         reload()
39 }
40
41 AUTH == OWNER && TO == NICK && /^rejoin/ {
42         reply("joining..")
43         join("#rhnoise")
44         next
45 }
46
47 AUTH == OWNER && TO == NICK && /^(join|part)/ {
48         match(MSG, /(join|part) +(#+\w+)/, arr)
49         if (arr[1] && arr[2]) {
50                 send(toupper(arr[1]) " " arr[2]);
51                 next
52         }
53 }
54
55 AUTH == OWNER && TO == NICK && /^\.msg/ {
56         match(MSG, /.*\.msg +(#*\w+) +(.*)/, arr)
57         send("PRIVMSG " arr[1] " :" arr[2])
58 }
59
60 # Kick handling
61 CMD == "KICK" && ARG[2] == NICK {
62         kick_delay = (kick_delay + 2) * 2
63         system("sleep " kick_delay)
64         join(DST)
65         reply("I feel happy!")
66 }
67
68 # Identify bots
69 FROM ~ /bo+t$|rhnoise/ {
70         bots[FROM] = 1
71 }
72
73 CMD == "NICK" && FROM in bots {
74         bots[MSG] = FROM
75 }
76
77
78 # Unicode
79 /[Uu]nicode :-?\(/ {
80         plain[FROM] = 1
81         json_save("var/plain.json", plain);
82 }
83
84 /[Uu]nicode :-?\)/ {
85         delete plain[FROM]
86         json_save("var/plain.json", plain);
87 }
88
89 # SFV Lug
90 function email(to, from, subj, body, sendmail)
91 {
92         from     = NICK "<andy@pileus.org>"
93         subj     = "Update sfvlug.org!"
94         body     = "The next SFVLUG meeting is TBA!"
95         sendmail = "/usr/sbin/sendmail '" to "'"
96         print "To: " to        | sendmail
97         print "From: " from    | sendmail
98         print "Subject: " subj | sendmail
99         print ""               | sendmail
100         print body             | sendmail
101         say("Topic out of date, emailing " to);
102         close(sendmail)
103 }
104
105 BEGIN { pollchan = "#sfvlug" }
106 (CMD == "PING"    && systime()-lastpoll > 60*60*24) ||
107 (CMD == "PRIVMSG" && /^\.poll/) {
108         if (!TOPICS[pollchan]) {
109                 debug("Unknown topic for " pollchan);
110                 send("TOPIC " pollchan)
111                 next
112         }
113         _curl     = "curl -s http://sfvlug.org/"
114         _day      = "(Sun|Mon|Tue|Wed|Thu|Fri|Sat)"
115         _web_tba  = "next meeting is: TBA"
116         _web_ptrn = "next meeting.*" _day "\\w+[, ]+([A-Z]\\w+) +([0-9]+)[, ]+([0-9]+)"
117         _irc_ptrn = _day "\\w*[, ]+([A-Z]\\w+) +([0-9]+)"
118         while (_curl | getline _line) {
119                 #if (match(_line, _web_tba))
120                 #       email("Brian <brian@zimage.com>");
121                 if (match(_line, _web_ptrn, _parts)) {
122                         _date  = _parts[1] " " _parts[2] " " _parts[3]
123                         _topic = TOPICS[pollchan]
124                         sub(_irc_ptrn, _date, _topic)
125                         if (_topic != TOPICS[pollchan])
126                                 topic(pollchan, TOPICS[pollchan] = _topic)
127                         else
128                                 debug("topic is already correct")
129                         break
130                 }
131         }
132         lastpoll = systime()
133         close(_curl)
134 }
135
136 # Versin/Uptime
137 function uptime(time,  fmt) {
138         fmt = "%d:%02d:%02d:%02d"
139         fmt = "%d days %02d:%02d:%02d"
140         return sprintf(fmt,
141                 time / (60*60*24),
142                 time / (60*60   ) % 24,
143                 time / (60      ) % 60,
144                 time / (1       ) % 60)
145 }
146 BEGIN {
147         _cmd = "git describe --always --dirty";
148         _cmd | getline up_version;
149         close(_cmd);
150         up_reload = systime();
151 }
152 /^\.version/ {
153         say("version: " up_version)
154 }
155 /^\.uptime/ {
156         _now = systime();
157         say("uptime: " uptime(_now - START) ", " \
158             "reload: " uptime(_now - up_reload))
159 }
160
161 # Auth info
162 /^\.auth/ {
163         _who = $2 ? $2 : FROM
164         if (_who in USERS)
165                 say("nick=" USERS[_who]["nick"] " " \
166                     "user=" USERS[_who]["user"] " " \
167                     "auth=" USERS[_who]["auth"] " " \
168                     "real=" USERS[_who]["real"] " " \
169                     "host=" USERS[_who]["host"])
170         else
171                 say("no auth info for " _who)
172 }
173
174 # Fortune
175 TO == NICK && /^/               { extra = ""   }
176 TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }
177 TO == NICK && /^\.?fortune/     {
178         gsub(/.*\.?fortune *|-[a-z]* *|[^a-zA-Z0-9 ]/, "", MSG)
179         cmd = "fortune " extra " " (MSG ? "-m '" MSG "'" : "-s")
180         _lines = 0
181         while (cmd | getline _fortune && _lines < 5) {
182                 say(_fortune)
183                 _lines++
184         }
185         close(cmd)
186         next
187 }
188
189 # Noise
190 AUTH == OWNER && /^go go gadget woop/ {
191         for (i=20; i>0; i--)
192                 say(".delay " i " seconds; .woop " i)
193 }
194
195 function woop(msg) {
196         gsub(/[^Oo]/, "", $1)
197         _len = length($1)
198         if (_len == 2)
199                 _len = 10
200         if ($2)
201                 _len = $2
202         _woop = msg
203         for (i=1; i<_len; i++)
204                 _woop = _woop " " msg
205         say(_woop)
206 }
207
208 TO == NICK && /^[Ww][Oo]+[Pp] *([0-9]*)/ {
209         woop("WOOP")
210 }
211
212 /^~WOOP *([0-9]*)/ {
213         woop("(00/")
214 }
215
216 /^~woop *([0-9]*)/ {
217         woop("^H^P^P^O")
218 }
219
220 TO == NICK && DST ~ /^#/ {
221         #say("Hello, " FROM)
222 }
223
224 #DST != "#sfvlug" &&
225 !(FROM in bots) &&
226 CMD == "PRIVMSG" &&
227 MSG !~ /^\./ &&
228 /awk/ {
229         say("Awk, awk, awk! I'm a bird!")
230 }
231
232 !(FROM in bots) &&
233 ((TO == NICK && /(help|halp)/) ||
234  /^[^.](help|halp)/) {
235         reply("Nothing can help you now..")
236 }
237
238 /(\<[Hh][Oo]\>.*){3}/ {
239         say("\00309Merry \00304Christmas!")
240 }
241
242 !(FROM in bots) &&
243 tolower($0) ~ /\<cloud\>/ {
244         _cmd = "shuf clouds.txt"
245         _cmd | getline _cloud
246         close(_cmd)
247         say(_cloud)
248 }
249
250 /^headshot [Cc]hristmas/ {
251         say(".load Christmas")
252         say(".jingle")
253         say(".unload Christmas")
254 }
255
256 FROM == "rhnoise" && $2 == "slaps" && $3 == NICK {
257         say(".spin")
258 }
259
260 /^[Aa]nd now[.,]/ {
261         say("And now...");
262         say("THE LARCH");
263 }
264
265 # God damn commands
266 FROM == "rhnoise" && load_mod {
267         say(".load " load_mod)
268         say("rhnoise: You slag!")
269 }
270 // {
271         load_mod = ""
272 }
273 (TO  ==  "rhnoise" && /^load \w+/) ||
274 (DST == "#rhniose" && /^\.load [a-z]\w+/) {
275         gsub(/[^a-zA-Z0-9_]/, " ")
276         load_mod = toupper(substr($2,1,1)) substr($2,2);
277 }
278
279 (DST == "#rhnoise" && /^\.line /) {
280         sub(/\./, "!");
281         say($0);
282         say("scalawag: You slag!")
283 }
284
285 (DST == "#rhnoise" && /^\.qdb 268$/) {
286         say(".diediedie");
287         next
288 }
289 (DST == "#rhnoise" && /\.qdb *268/) {
290         say(".slap " FROM);
291         next
292 }
293
294 # Decrementer
295 #BEGIN {
296 #       user_scores[0] = 1
297 #}
298 #
299 #FROM == "rhnoise" && !length(user_scores) {
300 #       if (split(MSG, _parts, /, /)) {
301 #               for (_i=1; _i<=length(_parts); _i++) {
302 #                       split(_parts[_i], _tmp, ": ");
303 #                       user_scores[_i]["user"]  = _tmp[1];
304 #                       user_scores[_i]["score"] = _tmp[2];
305 #               }
306 #       }
307 #}
308 #
309 #FROM == "rhnoise" && /^User Scores:$/ {
310 #       delete user_scores
311 #}
312 #
313 #AUTH == OWNER && length(user_scores) &&
314 #tolower($0) ~ /\<nuclear launch detected\>/ {
315 #       for (_i=1; _i<=length(user_scores); _i++)
316 #               say(user_scores[_i]["user"] "--");
317 #}
318
319 # Misc
320 { fflush("") }
321
322 # vim: ft=awk