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"
30 #print "" > "/dev/stderr"
31 print " < " $0 > "/dev/stderr"
35 print " # " msg > "/dev/stderr"
40 debug("CMD: [" CMD "]")
41 debug("SRC: [" SRC "]")
42 debug("DST: [" DST "]")
43 debug("FROM: [" FROM "]")
45 debug("ARG: [" ARG "]")
46 debug("MSG: [" MSG "]")
51 function connect(server, nick, channel) {
56 "whoami" | getline _name
57 "hostname" | getline _host
58 send("USER " _name " " _host " " server " :" nick)
63 function say(to, msg) {
68 else if (DST == NICK && FROM)
73 send("PRIVMSG " to " :" msg)
76 function action(to, msg)
79 say(to, "\001ACTION " msg "\001")
81 say("\001ACTION " to "\001")
97 function topic(chan, msg) {
98 send("TOPIC " chan " :" msg)
104 debug("Starting server");
105 cmd = "awk -f rhawk" \
107 " -v START=" systime() \
109 status = system(cmd " -v FIRST=1");
111 status = system(cmd);
114 debug("Starting child:" \
135 match($0, /(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+) +)?(([^: ]+) +)?(:(.*))/, arr);
142 match(SRC, /([^! ]+)!/, arr);
145 match(MSG, /(([^ :,]*)[:,] *)?(.*)/, arr);
147 $0 = TO ? arr[3] : MSG
149 if (CMD == "PRIVMSG" && DST == NICK && FROM && !TO)
156 CMD == "001" && MSG ~ /Welcome/ {