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:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:
384:
385:
386:
387:
388:
389:
390:
391:
|
'AZBOT - the IRC bot made in D++!
'by Azure (www.pagemac.com)
'I've been working on AzBot for some time now. He is by
'no means complete, but works pretty well as it is.
'All who idle on the IRC channel know AzBot well. :)
newvar botNick = "AzBot";
newvar server = "pm.irc.infiniteray.com";
newvar channel = "#pagemac";
newvar port = 6667;
newvar owner = "Azure";
newvar configFile = "C:\Visual Basic\azbot_config.dat", configLoaded;
newvar configData[];
newvar isConnected;
newvar beStupid=1, stupidStuff[];
newvar insults[], greets[];
function main()
{
title botNick;
winsock irc;
newvar command;
screenput "D++ IRC BOT - Written by AzureIce"; screen;
screenput "Now running as " & botNick; screen; screen;
loadConfig();
loadArrays();
sock[irc].connect(server, port);
addtextinput("<*Info> Connecting to " & server & ":" & port & "...");
do until command="exit";
screenput "<" & botNick & "> ";
screenin command; screen;
processInput(command);
loop
sock[irc].close();
}
function ~main()
{
saveConfig();
}
function processInput(input)
{
newvar noSend;
if left(input, 4) = "/me " then
input = "PRIVMSG " & channel & " :ACTION " & mid(input, 5) & "";
elseif left(input, 7) = "/rehash" then
loadConfig(); noSend = true;
elseif left(input, 1) = "/" then
input = mid(input , 2);
else
input = "PRIVMSG " & channel & " :" & input;
endif
if ! noSend then
sock[irc].Send(input & dpp.crlf);
endif
doevents;
}
function loadConfig()
{
'note this config file format:
'TYPE|KEYWORD|TEXT TO SEND
'example:
'JOIN|Azure|All hail Azure, programming master!
'This will give me a nice little greet.
'types:
'JOIN - channel join
'PART - channel part
'CHAT - command, accessd via `keyword %1 %2 (and any other arguments)
'CMSG - general channel message
newvar fdata;
screenput "Loading conifguration file..."; screen;
if ! fileexist(configFile) then
screenput "Couldn't find config file - options won't be used."; screen;
return;
endif
fdata = readfile(configFile);
configData = split(fdata, dpp.crlf);
configLoaded = true;
screenput "Configuration loaded successfully."; screen;
}
function saveConfig()
{
newvar f, i;
if !configLoaded then return; endif
cancel_input; screen;
screenput "Saving configuration file... ";
f = f_open(configFile, "w");
for i = 0 to ubound(configData);
if trim(configData[i]) <> "" then
f_out(f, configData[i]);
endif
next i;
f_close(f);
screenput "done.";
}
function loadArrays()
{
resize stupidStuff, 2;
stupidStuff[0] = "Right....";
stupidStuff[1] = "Er, okay...";
stupidStuff[2] = "huh?";
resize insults, 3;
insults[0] = "shut up bot";
insults[1] = "shut up, bot";
insults[2] = "shut up azbot";
insults[3] = "shut up, azbot";
resize greets, 6;
greets[0] = "hi";
greets[1] = "hey";
greets[2] = "hello";
greets[3] = "hey bot";
greets[4] = "hi bot";
greets[5] = "hey azbot";
greets[6] = "hi azbot";
}
function irc_connect()
{
addtextinput("<*Info> Connected!");
pause 1;
SendData("user " & botNick & " azure.irc.pagemac.com irc :yeah");
SendData("nick " & botNick & "");
title botNick & " - " & server;
isConnected = true;
}
function irc_error(number, description)
{
addtextinput("<*Error> " & description);
irc_close();
}
function irc_close()
{
isConnected = false;
addtextinput("* Disconnected");
title botNick;
}
function irc_incoming(data, bytesTotal)
{
newvar string[];
newvar z, y, displayed;
newvar user, msg, pre;
string = split(data, " ");
z = instr(1, string[0], "!");
if z <> 0 then user = mid(string[0], 2, z-2); endif
if string[1] = "PRIVMSG" then
y = instr(2, data, ":");
if y <> 0 then msg = mid(data, y+1, len(data)-y-1); endif
if string[2] = botNick then
pre = "[MSG] "; endif
if left(msg, 7) = "ACTION" then
msg = mid(msg, 8, len(msg) - 9);
addtextinput("* " & user & msg);
else
addtextinput("<" & user &"> " & pre & msg);
endif
doParse(user, msg);
displayed = true;
elseif string[1] = "NOTICE" then
y = instr(2, data, ":");
if y <> 0 then msg = mid(data, y+1, len(data)-y-1); endif
addtextinput("--: NOTICE: <" & user & "> " & msg);
elseif string[1] = "MODE" then
pre = instr(1, lcase(data), lcase(channel));
if pre <> 0 then pre = mid(data, pre + len(channel) + 1); pre = mid(pre, 1, len(pre) -2); endif
addtextinput("--: MODE: " & user & " sets mode " & pre);
displayed = true;
elseif string[1] = "NICK" then
addtextinput("--: NICK: " & user & " is now known as " & mid(string[2], 2, len(string[2])-3));
displayed = true;
elseif string[1] = "JOIN" then
addtextinput("--> JOIN: " & user); ' & "(" & mid(string[0], z+1) & ")");
doConfig("JOIN", user, user);
displayed = true;
elseif string[1] = "PART" then
addtextinput("<-- PART: " & user); ' & "(" & mid(string[0], z+1) & ")");
doConfig("PART", user, user);
displayed = true;
elseif string[1] = "QUIT" then
pre = instr(3, lcase(data), ":");
if pre <> 0 then pre = mid(data, pre + 1); pre = mid(pre, 1, len(pre) -2); endif
addtextinput("<-- QUIT: " & user & " (" & pre & ")");
displayed = true;
endif
z = instr(1, data, "PING");
if z <> 0 then
sock[irc].send("PONG :" & mid(data, z+6));
doevents;
'addtextinput("[" & dpp.time & "] Ping? Pong!");
elseif ! displayed then
addtextinput("<*Server> " & trimReturns(data));
endif
z = instr(1, data, "End of /MOTD command.");
if z <> 0 then doevents; sendData("JOIN " & channel); endif
}
function doParse(user, msg)
{
newvar z, arr[];
msg = left(msg, len(msg) - 1);
if left(lcase(msg), 7) = "azbot, " then msg = "`" & mid(msg, 8); endif
if left(msg, 1) = "`" then
arr = split(msg, " ");
doConfig("CHAT", user, mid(msg,2));
else
doConfig("CMSG", user, msg);
endif
if instr(1, lcase(msg), "stfu") <> 0 then
sendChat(user & ", you're one to talk...");
elseif left(lcase(msg), 5) = "`say " then
sendChat(mid(msg, 6));
elseif left(lcase(msg), 5) = "`die " then
if lcase(user) != lcase(owner) then sendChat(user & ", you can't just boss me around... screw you."); return; endif
sendChat(user & " has told me to quit: " & mid(msg, 6));
sock[irc].Send("QUIT " & mid(msg, 6) & dpp.crlf);
elseif left(lcase(msg), 10) = "`bestupid " && user = owner then
bestupid = mid(msg, 11);
sendChat("Roger roger.");
elseif left(lcase(msg), 9) = "`destroy " then
if lcase(user) != lcase(owner) then sendChat(user & ", you can't just boss me around... screw you."); return; endif
z = mid(msg, 10);
sendChat("Attention! " & z & " has been flagged for an ass-kicking!");
pause 2;
sendChat("Suck it, " & z & "!");
sock[irc].send("KICK " & channel & " " & z & " Got an ass-kicking!" & dpp.crlf);
elseif inarray(insults, msg) then
sendchat(":(");
elseif inarray(greets, msg) then
sendchat("Hi " & user & "!");s
else
if ! beStupid then return; endif
z = rndnum(50) + 1;
if z = 32 && len(msg) > 10 then
sendChat("To clarify what " & user & " just said: " & msg);
elseif z = 6 then
sendChat(stupidStuff[rnd_element(stupidStuff)]);
endif
endif
}
function doConfig(cmd, user, string)
{
newvar line[],args[], i, noWildcards = false;
newvar sArg[]; sArg = split(string, " ");
for i = 0 to ubound(configdata);
if lcase(left(configdata[i], len(cmd))) = lcase(cmd) then
line = split(configdata[i], "|");
args = split(line[1], ",");
if inarray(args, sArg[0]) then
processInput(escapeChars(line[2], user, sArg));
return;
elseif line[1] = "*" then
processInput(escapeChars(line[2], user, sArg));
return;
endif
endif
next i;
}
function AddText(text)
{
text = trimReturns(text);
screenput text; screen; doevents;
}
function trimReturns(text);
{
if right(text, 2) = dpp.crlf then
text = left(text, len(text) - 2));
text = trimReturns(text);
endif
return text;
}
function SendData(data)
{
sock[irc].Send(data & dpp.crlf);
addtextinput("<" & botNick & "> " & data);
doevents;
}
function sendChat(msg)
{
newvar i, arr[];
if trim(msg) = "" then return; endif
arr = split(msg, dpp.crlf);
for i = 0 to ubound(arr);
msg = "PRIVMSG " & channel & " :" & arr[i];
sock[irc].Send(msg & dpp.crlf);
msg = arr[i];
if left(msg, 7) = "ACTION" then
msg = mid(msg, 8, len(msg) - 9);
addtextinput("* " & botNick & msg);
else
addtextinput("<" & botNick & "> " & msg);
endif
doevents;
next i;
}
function escapeChars(text, user, arr[])
{
newvar j;
text = replace(text, "%crlf", dpp.crlf);
text = replace(text, "%n", user);
text = replace(text, "%c", channel);
text = replace(text, "%s", server);
text = replace(text, "%o", owner);
for j = 0 to ubound(arr);
text = replace(text, "%" & j, arr[j]);
next j;
return text;
}
function addtextinput(text)
{
'this adds text on the second to last line... so your input does't mess up
newvar i, n;
newvar var1, var2;
for i = conlen() to 1 step -1;
if mid(getconsole(), i, 2) = dpp.crlf then
i = i + 2;
var1 = mid(getconsole(), 1, i-1);
var2 = mid(getconsole(), i);
call setconsole(var1 & text & dpp.crlf & var2);
call setstart(conlen());
doevents;
return;
endif
next i;
call AddText(text);
}
function error(type, text, proc, char)
{
sendchat(type & ": " & replace(text, dpp.crlf, " // ") & " (" & char & ")");
}
|