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"
48 function connect(server, nick, channel) {
53 "whoami" | getline _name
54 "hostname" | getline _host
55 send("USER " _name " " _host " " server " :" nick)
59 function privmsg(to, msg) {
60 send("PRIVMSG " to " :" msg)
65 else if (DST == NICK && FROM)
86 debug("Starting server");
87 status = system("awk -f rhawk -v CHILD=1 -v FIRST=1");
89 status = system("awk -f rhawk -v CHILD=1");
92 debug("Starting child: CHILD=" CHILD " FIRST=" FIRST);
106 match($0, /(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+) +)?([^:]*:(.*))/, arr);
107 gsub(/\s+/, " ", arr[8])
108 gsub(/^ | $/, "", arr[8])
109 gsub(/\3[0-9]*/, "", arr[8])
115 match(SRC, /([^! ]+)!/, arr);
118 match(MSG, /(([^ :,]*)[:,] *)?(.*)/, arr);
120 $0 = TO == NICK ? arr[3] : MSG
122 if (CMD == "PRIVMSG" && DST == NICK && FROM)
127 CMD == "001" && MSG ~ /Welcome/ {