2 # socat 'TCP:localhost:12345' 'EXEC:awk -f $0'
4 # Pre-defined variables:
7 # SERVER: IRC Server that is connected to
8 # NICK: Nickname given by the bot
9 # CHANNEL: Channel the bot is currently in
11 # When a messages is recieved:
12 # CMD: Message, e.g. PRIVMSG
13 # SRC: Source of the message
14 # DST: Destination of the message, e.g. the channel
15 # TO: Nickname the message was addressed to
16 # FROM: Nickname of the user who sent the message
22 print " > " msg > "/dev/stderr"
29 #print "" > "/dev/stderr"
30 print " < " $0 > "/dev/stderr"
34 print " # " msg > "/dev/stderr"
39 debug("CMD: [" CMD "]")
40 debug("SRC: [" SRC "]")
41 debug("DST: [" DST "]")
42 debug("FROM: [" FROM "]")
44 debug("ARG: [" ARG "]")
45 debug("MSG: [" MSG "]")
50 function connect(server, nick, channel) {
55 "whoami" | getline _name
56 "hostname" | getline _host
57 send("USER " _name " " _host " " server " :" nick)
62 function say(to, msg) {
67 else if (DST == NICK && FROM)
72 send("PRIVMSG " to " :" msg)
75 function action(to, msg)
78 say(to, "\001ACTION " msg "\001")
80 say("\001ACTION " to "\001")
96 function topic(chan, msg) {
97 send("TOPIC " chan " :" msg)
103 debug("Starting server");
104 cmd = "awk -f rhawk -v CHILD=1 -v START=" systime();
105 status = system(cmd " -v FIRST=1");
107 status = system(cmd);
110 debug("Starting child:" \
130 match($0, /(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+) +)?(([^: ]+) +)?(:(.*))/, arr);
137 match(SRC, /([^! ]+)!/, arr);
140 match(MSG, /(([^ :,]*)[:,] *)?(.*)/, arr);
142 $0 = TO ? arr[3] : MSG
144 if (CMD == "PRIVMSG" && DST == NICK && FROM && !TO)
151 CMD == "001" && MSG ~ /Welcome/ {