-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.awk
77 lines (64 loc) · 2.09 KB
/
client.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@include "commands.awk";
BEGIN {
RS = ORS = "\r\n"
IRCService = "/inet/tcp/0/irc.freenode.net/6667"
PROCINFO["/inet/tcp/0/irc.freenode.net/6667", "READ_TIMEOUT"] = 1000
PROCINFO["/inet/tcp/0/irc.freenode.net/6667", "RETRY"] = 1
login(IRCService);
while(1==1) {
checkIrcForInput(IRCService);
}
close(HttpService)
}
function login(service) {
print "PASS " |& service;
print "NICK bananenbot" |& service;
print "USER bananenbot irc.freenode.net bla : bananenbot" |& service;
}
function registerCommand(name, functionName) {
print "trying to register command " name;
commands[name] = functionName;
}
function registerListener(listenerName) {
print "trying to register a listener " listenerName;
listeners[listenerName] = listenerName;
}
function checkIrcForInput(service, banaan, line, parts, i, cmdStart) {
if (banaan = (service |& getline line) > 0) {
print line;
split(line, parts);
if (parts[1] == "PING") {
print "We've received a PING request";
print "PONG" |& service;
return;
}
if (parts[2] == "001") {
print "JOIN \#bananentaart" |& service;
return;
}
if (parts[2] == "PRIVMSG") {
for(i in listeners) {
if(@i(service, parts) == "stop") {
return;
}
}
}
cmdStart="^:!";
if (parts[2] == "PRIVMSG" && parts[4] ~ cmdStart) {
print "We've got a command";
command = parts[4];
sub(":!", "", command);
if (command in commands) {
print "we have found an existing command";
functionName = commands[command];
@functionName(service, parts);
return;
}
print "PRIVMSG " parts[3] " :Unknown command" |& service;
}
return;
}
}
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
function trim(s) { return rtrim(ltrim(s)); }