]> Pileus Git - ~andy/rhawk/blob - rhawk
Add login and create settings file
[~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 FROM == OWNER && TO == NICK && /^die in a fire/ {
32         say("Ack, argh, barasdjf..")
33         quit()
34 }
35
36 FROM == OWNER && TO == NICK && /^reload/ {
37         say("Reloading..")
38         reload()
39 }
40
41 FROM == OWNER && TO == NICK && /^rejoin/ {
42         reply("joining..")
43         join("#rhnoise")
44         next
45 }
46
47 FROM == 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 FROM == 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 == "TOPIC"   && systime()-lastpoll > 60*60*24) ||
107 (CMD == "PING"    && systime()-lastpoll > 60*60*24) ||
108 (CMD == "PRIVMSG" && /^\.poll/) {
109         if (!topics[pollchan]) {
110                 debug("Unknown topic for " pollchan);
111                 send("TOPIC " pollchan)
112                 next
113         }
114         _curl     = "curl -s http://sfvlug.org/"
115         _day      = "(Sun|Mon|Tue|Wed|Thu|Fri|Sat)"
116         _web_tba  = "next meeting is: TBA"
117         _web_ptrn = "next meeting.*" _day "\\w+[, ]+([A-Z]\\w+) +([0-9]+)[, ]+([0-9]+)"
118         _irc_ptrn = _day "\\w*[, ]+([A-Z]\\w+) +([0-9]+)"
119         while (_curl | getline _line) {
120                 #if (match(_line, _web_tba))
121                 #       email("Brian <brian@zimage.com>");
122                 if (match(_line, _web_ptrn, _parts)) {
123                         _date  = _parts[1] " " _parts[2] " " _parts[3]
124                         _topic = topics[pollchan]
125                         sub(_irc_ptrn, _date, _topic)
126                         if (_topic != topics[pollchan])
127                                 topic(pollchan, topics[pollchan] = _topic)
128                         else
129                                 debug("topic is already correct")
130                         break
131                 }
132         }
133         lastpoll = systime()
134         close(_curl)
135 }
136
137 # Versin/Uptime
138 function uptime(time,  fmt) {
139         fmt = "%d:%02d:%02d:%02d"
140         fmt = "%d days %02d:%02d:%02d"
141         return sprintf(fmt,
142                 time / (60*60*24),
143                 time / (60*60   ) % 24,
144                 time / (60      ) % 60,
145                 time / (1       ) % 60)
146 }
147 BEGIN {
148         _cmd = "git describe --always --dirty";
149         _cmd | getline up_version;
150         close(_cmd);
151         up_reload = systime();
152 }
153 /^\.version/ {
154         say("version: " up_version)
155 }
156 /^\.uptime/ {
157         _now = systime();
158         say("uptime: " uptime(_now - START) ", " \
159             "reload: " uptime(_now - up_reload))
160 }
161
162 # Fortune
163 TO == NICK && /^/               { extra = ""   }
164 TO == NICK && /^\.?fortune.*-o/ { extra = "-o" }
165 TO == NICK && /^\.?fortune/     {
166         gsub(/.*\.?fortune *|-[a-z]* *|[^a-zA-Z0-9 ]/, "", MSG)
167         cmd = "fortune " extra " " (MSG ? "-m '" MSG "'" : "-s")
168         _lines = 0
169         while (cmd | getline _fortune && _lines < 5) {
170                 say(_fortune)
171                 _lines++
172         }
173         close(cmd)
174         next
175 }
176
177 # Noise
178 FROM ~ OWNER && /^go go gadget woop/ {
179         for (i=20; i>0; i--)
180                 say(".delay " i " seconds; .woop " i)
181 }
182
183 function woop(msg) {
184         gsub(/[^Oo]/, "", $1)
185         _len = length($1)
186         if (_len == 2)
187                 _len = 10
188         if ($2)
189                 _len = $2
190         _woop = msg
191         for (i=1; i<_len; i++)
192                 _woop = _woop " " msg
193         say(_woop)
194 }
195
196 TO == NICK && /^[Ww][Oo]+[Pp] *([0-9]*)/ {
197         woop("WOOP")
198 }
199
200 /^~WOOP *([0-9]*)/ {
201         woop("(00/")
202 }
203
204 /^~woop *([0-9]*)/ {
205         woop("^H^P^P^O")
206 }
207
208 TO == NICK && DST ~ /^#/ {
209         #say("Hello, " FROM)
210 }
211
212 #DST != "#sfvlug" &&
213 !(FROM in bots) &&
214 CMD == "PRIVMSG" &&
215 MSG !~ /^\./ &&
216 /awk/ {
217         say("Awk, awk, awk! I'm a bird!")
218 }
219
220 !(FROM in bots) &&
221 ((TO == NICK && /(help|halp)/) ||
222  /^[^.](help|halp)/) {
223         reply("Nothing can help you now..")
224 }
225
226 /(\<[Hh][Oo]\>.*){3}/ {
227         say("\00309Merry \00304Christmas!")
228 }
229
230 !(FROM in bots) &&
231 tolower($0) ~ /\<cloud\>/ {
232         _cmd = "shuf clouds.txt"
233         _cmd | getline _cloud
234         close(_cmd)
235         say(_cloud)
236 }
237
238 /^headshot [Cc]hristmas/ {
239         say(".load Christmas")
240         say(".jingle")
241         say(".unload Christmas")
242 }
243
244 FROM == "rhnoise" && $2 == "slaps" && $3 == NICK {
245         say(".spin")
246 }
247
248 /^[Aa]nd now[.,]/ {
249         say("And now...");
250         say("THE LARCH");
251 }
252
253 # God damn commands
254 FROM == "rhnoise" && load_mod {
255         say(".load " load_mod)
256         say("rhnoise: You slag!")
257 }
258 // {
259         load_mod = ""
260 }
261 (TO  ==  "rhnoise" && /^load \w+/) ||
262 (DST == "#rhniose" && /^\.load [a-z]\w+/) {
263         gsub(/[^a-zA-Z0-9_]/, " ")
264         load_mod = toupper(substr($2,1,1)) substr($2,2);
265 }
266
267 (DST == "#rhnoise" && /^\.line /) {
268         sub(/\./, "!");
269         say($0);
270         say("scalawag: You slag!")
271 }
272
273 (DST == "#rhnoise" && /^\.qdb 268$/) {
274         say(".diediedie");
275         next
276 }
277 (DST == "#rhnoise" && /\.qdb *268/) {
278         say(".slap " FROM);
279         next
280 }
281
282 # Decrementer
283 #BEGIN {
284 #       user_scores[0] = 1
285 #}
286 #
287 #FROM == "rhnoise" && !length(user_scores) {
288 #       if (split(MSG, _parts, /, /)) {
289 #               for (_i=1; _i<=length(_parts); _i++) {
290 #                       split(_parts[_i], _tmp, ": ");
291 #                       user_scores[_i]["user"]  = _tmp[1];
292 #                       user_scores[_i]["score"] = _tmp[2];
293 #               }
294 #       }
295 #}
296 #
297 #FROM == "rhnoise" && /^User Scores:$/ {
298 #       delete user_scores
299 #}
300 #
301 #FROM == OWNER && length(user_scores) &&
302 #tolower($0) ~ /\<nuclear launch detected\>/ {
303 #       for (_i=1; _i<=length(user_scores); _i++)
304 #               say(user_scores[_i]["user"] "--");
305 #}
306
307 # Misc
308 { fflush("") }
309
310 # vim: ft=awk