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