-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
680 lines (564 loc) · 24.6 KB
/
index.js
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
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
process.on('uncaughtException', function (err) {
// This should not happen
console.log(err);
process.exit(1);
});
/* ENUMERATORS \o/ */
const PERMISSION_ERROR = "Elevated privileges required for command $com";
const NOT_ENOUGH_ARGS = "Not enough arguments for command $com";
const INVALID_ARGUMENTS = "Invalid arguments";
const ABOUT_BARK = "Bark 3.0 is a nodejs powered modular IRCv3 bot created by duckgoose. https://github.com/haxednet/Bark";
/* ************* */
const fs = require('fs');
if( !fs.existsSync("config.json") ) return console.log("ERROR: You must have a config.json file to use this program");
const http = require('http');
const https = require('https');
const tls = require('tls');
const irc = require('./irc.js');
const homoglyph = require('./homoglyph.js');
const config = require('./config.json');
const keys = require('./apiKeys.json');
const chatLog = require('./log.json');
const plugins = {};
const whoCache = {};
const whoList = [];
const banHammer = [];
console.log(" __\r\n (___()'`; BARK v3!\r\n /, /`\r\n \\\"--\\");
function loadPlugins(){
/* Load all the .js files from /plugins/ and put them in the plugins variable */
const files = fs.readdirSync('./plugins');
files.forEach(file => {
if(file.slice(-3) == ".js"){
try{
console.log("Loading plugin " + file + "...");
delete(require.cache[require.resolve("./plugins/" + file)]);
delete(plugins[file]);
const mod = require("./plugins/" + file);
plugins[file] = mod;
const e = {config: config, bot: bot, dataStore: dataStore, whoCache: whoCache, keys: keys, httpGet: httpGet, chatLog: chatLog};
if(mod.init != undefined) mod.init(e);
}catch(err){
console.log("The plugin " + file + " has caused an error and will not be loaded.");
delete(plugins[file]);
throw(err);
}
}
});
}
/* Create the bot and begin the connection to IRC */
const bot = new irc( config.bot );
/* Load the plugins */
loadPlugins();
/* send the bot variable to the plugins */
for(let i in plugins){
plugins[i].bot = bot;
plugins[i].keys = keys;
}
let opTimer = 0;
bot.on('data', (e) => {
const args = e.split(" ");
let nick = "";
console.log(e);
switch(args[1]){
case "MODE":
const chanConfig = config.channels[args[2].replace(/^(\@|\+)/,"")];
if(e.toLowerCase().indexOf("+o time-warp") > 1 && chanConfig && chanConfig.deopTimewarp){
bot.sendData("MODE ##defocus -o time-warp");
}
if(e.toLowerCase().indexOf("-o bark") > 1 && e.toLowerCase().indexOf("##defocus") > 1){
clearTimeout(opTimer);
opTimer = setTimeout(function(){
bot.sendData("PRIVMSG ChanServ :op ##defocus bark");
bot.sendData("PRIVMSG ##defocus :Don't do that.");
},2000);
}
break;
case "ACCOUNT":
nick = args[0].substr(1).split("!")[0].toLowerCase();
if(whoCache[nick] != undefined && args[2] != "*"){
whoCache[nick][0] = args[2];
}
break;
case "NICK":
nick = args[0].substr(1).split("!")[0].toLowerCase();
if(whoCache[nick] != undefined){
whoCache[nick][1] = args[2].replace(":", "") + "!" + whoCache[nick][1].split("!")[1];
whoCache[args[2].replace(":", "")] = whoCache[nick];
delete whoCache[nick];
}
break;
}
for(let i in plugins){
if(plugins[i].onData) plugins[i].onData(e);
}
});
bot.on('join', (e) => {
let chanConfig = config.channels[e.channel.toLowerCase().replace(/^(\@|\+)/,"")];
if(chanConfig == undefined){
config.channels[e.channel.toLowerCase().replace(/^(\@|\+)/,"")] = config.channels["-new-"];
chanConfig = config.channels["-new-"];
}
if(config.bot.nick.toLowerCase() == e.user.nick.toLowerCase()){
/* We've joined a new channel */
if(chanConfig.opOnJoin) bot.sendPrivmsg("chanserv", "op " + e.channel.toLowerCase());
}else{
console.log(e.user.mask);
for(let i in chanConfig.autoOp){
const urex = userAsRegex(chanConfig.autoOp[i]);
if(e.user.mask.match(urex) != null) bot.sendData("MODE " + e.channel + " +o " + e.user.nick);
}
/*
if we have too many users in the whoCache then
we shouldn't add more, to prevent running out of memory.
This is unlikely to happen because whoCache is repolled
every hour.
*/
if(Object.keys(whoCache).length < 10000){
const bits = e.data.split(" ");
if(bits[3] == "*"){
whoCache[e.user.nick.toLowerCase()] = [e.user.nick.toLowerCase(), e.user.mask, false];
}else{
whoCache[e.user.nick.toLowerCase()] = [bits[3], e.user.mask, true];
}
}
}
e.config = config;
e.chanConfig = chanConfig;
for(let i in plugins){
if(plugins[i].onJoin) plugins[i].onJoin(e);
}
});
bot.on('kick', (e) => {
if(e.kicked.toLowerCase() == config.bot.nick.toLowerCase()){
const chanConfig = config.channels[e.channel.toLowerCase().replace(/^(\@|\+)/,"")];
if(chanConfig && chanConfig["autoRejoin"]){
bot.sendData("JOIN " + e.channel);
setTimeout(function(){
bot.sendData("PRIVMSG " + e.channel + " :" + e.kicker + " that's rude...");
},500);
}
}
});
bot.on('numeric', (e) => {
const args = e.data.split(" ");
if(e.number == "1"){
/* numeric 1 means we're connected to IRC */
console.log("Logged in to IRC, joining channels...");
setTimeout(()=>{
for(let i in config.channels){
bot.sendData("JOIN " + (i + " " + (config.channels[i.replace(/^(\@|\+)/,"")].key || "")));
whoList.push(i);
//bot.sendData("WHO " + i + " %uhna");
}
bot.sendData("WHO " + whoList[0] + " %uhna");
whoList.splice(0,1);
}, 3000);
}
if(e.number == "999"){
bot.sendData("NICK Bark34857389");
setTimeout(function(){
bot.sendData("PRIVMSG nickserv :ghost bark");
},2000);
setTimeout(function(){
bot.sendData("nick Bark");
},4000);
}
if(e.number == "353"){
const nicks = e.data.substr(e.data.indexOf(" :") + 2).split(" ");
for(let i in nicks){
const fnick = nicks[i].replace(/\!|\@/g, " ").split(" ");
whoCache[fnick[0].toLowerCase()] = [fnick[0].toLowerCase(), nicks[i], false];
}
}
if(e.number == "354"){
/* WHO reply */
if(args[6] == "0") args[6] = args[5];
whoCache[args[5].toLowerCase()] = [args[6], args[5] + "!" + args[3] + "@" + args[4], true];
}
if(e.number == "315"){
if(whoList.length > 0){
setTimeout(function(){
bot.sendData("WHO " + whoList[0] + " %uhna");
whoList.splice(0,1);
}, 2000);
}
}
for(let i in plugins){
if(plugins[i].onNumeric) plugins[i].onNumeric(e);
}
});
bot.on('quit', (e) => {
delete whoCache[e.user.nick.toLowerCase()];
for(let i in plugins){
if(plugins[i].onQuit) plugins[i].onQuit(e);
}
});
bot.on('part', (e) => {
if(e.user.nick.toLowerCase() == config.bot.nick.toLowerCase()){
const chanConfig = config.channels[e.channel.toLowerCase().replace(/^(\@|\+)/,"")];
if(chanConfig && chanConfig["autoRejoin"]){
bot.sendData("JOIN " + e.channel);
setTimeout(function(){
if(e.message.indexOf("requested by") > -1){
bot.sendData("PRIVMSG " + e.channel + " :" + e.message.split(" ")[2] + " that's rude...");
}
},500);
}
}
});
bot.on('notice', (e) => {
for(let i in plugins){
if(plugins[i].onNotice) plugins[i].onNotice(e);
}
});
bot.on('privmsg', (e) => {
//console.log(e);
if(e.to.substr(0,1).match(/\+|\@/) != null){
e.to = e.to.substr(1);
}
if(e.message.substr(0,2) == config.globalSettings.commandPrefix + " ") return;
/* allow commands in PMs */
if(e.to.substr(0,1) != "#"){
if(e.message.substr(0,1) == "#"){
if(config.channels[e.message.split(" ")[0].replace(/^(\@|\+)/,"")] != undefined){
if(config.channels[e.message.split(" ")[0].replace(/^(\@|\+)/,"")].allowCommandsInPM && e.message.toLowerCase().indexOf(".tell") < 1){
e.to = e.message.split(" ")[0];
e.message = e.message.substr(e.message.indexOf(" ") + 1);
}else{
return e.reply("Commands in PM are disabled for this channel");
}
}
}else{
return e.reply("To use commands in PM you must first supply the channel in your message to which the command will be ran, e.g.: #channel .help");
}
}
if(e.isPM == false){
/* chatLog is a small log of chat messages for diagnostic usage */
chatLog.push([Date.now(), e.from.mask, e.to, e.message]);
if(chatLog.length > 10000) chatLog.splice(0,1);
}
const input = e.message.substr(1).replace(/\s\s/g, " ").trim();
const _input = e.message.substr(e.message.indexOf(" ") + 1);
const args = input.split(" ");
const chanConfig = config.channels[e.to.toLowerCase().replace(/^(\@|\+)/,"")];
/* some things need to be added to e. this gives plugins added functionality by passing e to them. */
e.command = args[0].toLowerCase();
e.input = input;
e._input = _input;
e.args = args;
e.admin = isAdmin(e.from.mask,e.to.toLowerCase());
e.isAdmin = isAdmin;
e.botMaster = isAdmin(e.from.mask);
e.dataStore = dataStore;
e.whoCache = whoCache;
e.bot = bot;
e.channel = e.to.replace(/^(\@|\+)/,"");
e.chanConfig = chanConfig;
e.config = config;
e.kick = kick;
e.ban = ban;
e.kickBan = kickBan;
e.chatLog = chatLog;
e.httpGet = httpGet;
e.voice = voice;
e.username = (whoCache[e.from.nick.toLowerCase()] && whoCache[e.from.nick.toLowerCase()][2]) ? whoCache[e.from.nick.toLowerCase()][0] : e.from.nick;
console.log(e.channel);
if(e.botMaster == true) e.admin = true;
if(chanConfig == undefined) return;
/* ignore messages containing banned parameters */
for(let i in chanConfig.bannedParams){
if(e.message.toLowerCase().indexOf(chanConfig.bannedParams[i].toLowerCase()) > -1 && !e.admin) return;
if(homoglyph.stringify(e.message.toLowerCase()).indexOf(chanConfig.bannedParams[i].toLowerCase()) > -1 && !e.admin) return;
}
/* check for ban words and kick words if they're not admin */
let regexArgs = "ig";
let regexStr = "nothing";
if(chanConfig && !e.admin){
for(let i in chanConfig.kickWords){
if(chanConfig.kickWords[i].substr(0,1) == "/"){
regexArgs = chanConfig.kickWords[i].substr(1).substr(chanConfig.kickWords[i].lastIndexOf("/"));
regexStr = chanConfig.kickWords[i].substr(1).substr(0,chanConfig.kickWords[i].lastIndexOf("/")-1);
let re = new RegExp(regexStr, regexArgs);
console.log(e.message.match(re));
console.log(regexStr);
console.log(regexArgs);
if(e.message.match(re) != null) kick(e.to, e.from.nick, "Please mind the language");
}else{
console.log(chanConfig.kickWords[i]);
if(e.message.toLowerCase().indexOf(chanConfig.kickWords[i].toLowerCase()) > -1){
kick(e.to, e.from.nick, "Please mind the language");
}
}
}
for(let i in chanConfig.banWords){
if(chanConfig.banWords[i].substr(0,1) == "/"){
regexArgs = chanConfig.kickWords[i].substr(1).substr(chanConfig.kickWords[i].lastIndexOf("/"));
regexStr = chanConfig.kickWords[i].substr(1).substr(0,chanConfig.kickWords[i].lastIndexOf("/")-1);
let re = new RegExp(regexStr, regexArgs);
if(e.message.match(re) != null) kickBan(e.to, e.from.nick, "Please mind the language");
}else{
if(e.message.toLowerCase().indexOf(chanConfig.banWords[i].toLowerCase()) > -1){
kickBan(e.to, e.from.nick, "Please mind the language");
}
}
}
for(let i in chanConfig.ignore){
if(e.from.mask.match(userAsRegex(chanConfig.ignore[i])) != null) return;
}
}
/* Below is the main functionality for commands */
if(e.message.substr(0,1) == config.globalSettings.commandPrefix){
fs.appendFileSync("ccom.log", Date.now() + " " + e.to + " " + e.from.mask + ": " + e.message + "\r\n");
switch(e.command){
case "ignore":
if(!e.admin) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
if(e.args.length == 1){
return e.reply("ignore (add|remove) (hostmask), ignore (list|clear)");
}else{
if(e.args.length == 3){
if(e.args[1].toLowerCase() == "add"){
if(chanConfig.ignore.includes(e.args[2])) return e.reply("Item is already in ignore list");
if(e.args[2].indexOf("@") < 0) e.args[2] = e.args[2] + "!*@*";
chanConfig.ignore.push(e.args[2]);
return e.reply(e.args[2] + " has been added to the ignore list");
}else if(e.args[1].toLowerCase() == "remove"){
if(!chanConfig.ignore.includes(e.args[2])) return e.reply("Item was not found in ignore list");
chanConfig.ignore.splice(chanConfig.ignore.indexOf(e.args[2]), 1);
return e.reply(e.args[2] + " has been removed from the ignore list");
}
}else if(e.args.length == 2){
if(e.args[1].toLowerCase() == "list"){
return e.reply(JSON.stringify(chanConfig.ignore));
}else if(e.args[1].toLowerCase() == "clear"){
chanConfig.ignore = [];
return e.reply("operation completed successfully");
}
}
}
break;
case "raw":
if(!isAdmin(e.from.mask)) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
bot.sendData(e.message.split(".raw ")[1]);
break;
case "kill":
if(!isAdmin(e.from.mask)) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
process.exit(1);
break;
case "save":
if(!e.admin) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
if(fs.existsSync('config.json.bak')) fs.unlinkSync("config.json.bak");
fs.rename('config.json', 'config.json.bak', (err) => {
fs.writeFile("config.json", JSON.stringify(config, null, 4), function(err) {
return e.reply("config has been saved to disk");
});
});
break;
case "plugin":
if(args.length < 2) return e.reply(NOT_ENOUGH_ARGS.replace(/\$com/g, e.command));
const pComs = {config: config, bot: bot, dataStore: dataStore, whoCache: whoCache, keys: keys, httpGet: httpGet, chatLog: chatLog};
if(args[1] == "load"){
/* Check for botmaster access */
if(!isAdmin(e.from.mask)) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
if(args.length < 3) return e.reply(NOT_ENOUGH_ARGS.replace(/\$com/g, args[1]));
if(!fs.existsSync("./plugins/" + args[2])) return e.reply( args[2] + " was not found");
for(let i in plugins){
if(i == args[2]) return e.reply("Plugin " + args[2] + " is already loaded");
}
delete require.cache[require.resolve("./plugins/" + args[2])];
let mod = require("./plugins/" + args[2]);
plugins[args[2]] = mod;
if(mod.init != undefined) mod.init(pComs);
return e.reply("Plugin " + args[2] + " was loaded");
}else if(args[1] == "unload"){
/* Check for botmaster access */
if(!isAdmin(e.from.mask)) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
if(args.length < 3) return e.reply(NOT_ENOUGH_ARGS.replace(/\$com/g, args[1]));
for(let i in plugins){
if(i == args[2]){
delete require.cache[require.resolve("./plugins/" + args[2])];
delete plugins[i];
return e.reply("Plugin " + args[2] + " has been unloaded");
}
}
return e.reply("Plugin " + args[2] + " is not loaded");
}else if(args[1] == "reload"){
/* Check for botmaster access */
if(!isAdmin(e.from.mask)) return e.reply(PERMISSION_ERROR.replace(/\$com/g, e.command));
if(args.length < 3) return e.reply(NOT_ENOUGH_ARGS.replace(/\$com/g, args[1]));
if(!fs.existsSync("./plugins/" + args[2])) return e.reply( args[2] + " was not found");
for(let i in plugins){
if(i == args[2]){
delete require.cache[require.resolve("./plugins/" + args[2])];
delete plugins[i];
}
}
let mod = require("./plugins/" + args[2]);
plugins[args[2]] = mod;
if(mod.init != undefined) mod.init(pComs);
return e.reply("Plugin " + args[2] + " was reloaded");
}else{
return e.reply(INVALID_ARGUMENTS);
}
break;
case "about":
return e.reply(ABOUT_BARK);
break;
case "help":
if(args.length > 1){
if(args[1].toLowerCase() == "about") return e.reply(ABOUT_BARK);
for(let i in plugins){
for(let a in plugins[i].commands){
if(plugins[i].commands[a].command == e._input){
e.reply("[.\\plugins\\" + i + "] " + plugins[i].commands[a].usage.replace(/\$/g, config.globalSettings.commandPrefix));
return;
}
}
}
return e.reply("Command " + e.command + " was not found.");
}else{
e.reply("To get help for a specific command do: " + config.globalSettings.commandPrefix + "help [command]");
let commands = "";
for(let i in plugins){
for(let a in plugins[i].commands){
commands += plugins[i].commands[a].command + ", ";
}
}
return e.reply("Commands: " + commands + " about");
}
break;
case "whoiss":
if(args.length < 2) return e.reply("Not enough parameters");
if(whoCache[_input.toLowerCase()] == undefined){
e.reply("I don't know who " + _input + " is");
}else{
e.reply("I think " + _input + " is " + whoCache[_input.toLowerCase()][0] + (isAdmin(whoCache[_input.toLowerCase()][1], e.to.toLowerCase()) ? ". I also think they're an admin" : ""));
}
break;
default:
/* since no main bot commands matched we pass the command on to plugins */
for(let i in plugins){
for(let j in plugins[i].commands){
if(plugins[i].commands[j].command == e.command){
try{
let result = plugins[i].commands[j].callback(e);
if(result) return;
}catch(err){
console.log(err);
e.reply("Plugin " + i + " has caused an error and will now be unloaded (" + err.message + ") Check the logs for more details");
delete require.cache[require.resolve("./plugins/" + i)];
delete plugins[i];
}
}
}
}
break;
}
}
for(let i in plugins){
if(plugins[i].onPrivmsg){
if(plugins[i].onPrivmsg(e)) return;
}
}
});
/* Extra commands to help unify functionality */
function isAdmin(mask, channel){
if(channel == undefined){
for(let i in config.globalSettings.botMasters){
if( mask.match(userAsRegex(config.globalSettings.botMasters[i])) != null ) return true;
}
}else{
if( config.channels[channel.replace(/^(\@|\+)/,"")] == undefined ) return false;
for(let i in config.channels[channel.replace(/^(\@|\+)/,"")].admins){
if( mask.match(userAsRegex(config.channels[channel.replace(/^(\@|\+)/,"")].admins[i])) != null ) return true;
}
}
return false;
}
function userAsRegex( e ){
let returnStr = "";
for( let i in e ) {
returnStr += e[i].replace( /[^a-zA-Z\d\s\*:\/\@]/, "\\" + e[i] );
}
returnStr = returnStr.replace( /\s/g, "\\s" );
returnStr = returnStr.replace( /\*/g, "(.*)" );
return new RegExp("^" + returnStr + "$", "ig");
}
function httpGet(e, callback){
let httpo = http;
if(e.substr(0,5) == "https") httpo = https;
const host = e.split("/")[2].split(":")[0];
let port = 80;
if(e.indexOf("https://") > -1) port = 443;
if(e.split("/")[2].indexOf(":") > -1) port = e.split("/")[2].split(":")[1];
console.log(host);
const options ={
host: host,
port: port,
path: e.substr(e.indexOf("://" + host) + host + 3)
};
const cb = function(response) {
let str = '';
//another chunk of data has been received, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been received, so we just print it out here
response.on('end', function () {
callback(str);
});
response.on('error', function (e) {
});
}
try{
httpo.request(options, cb).end();
}catch(e){
}
}
function dataStore(a,b){
const file = "./datastore/" + a + ".json";
let returnData = {};
if (fs.existsSync(file)){
returnData = JSON.parse(fs.readFileSync(file));
}
if(b != undefined){
returnData = b;
fs.writeFileSync(file, JSON.stringify(b,null,4));
}
return returnData;
}
function voice(channel, user){
console.log("MODE " + channel + " +v " + user);
bot.sendData("MODE " + channel + " +v " + user);
}
function kick(channel, user, reason){
bot.sendData("KICK " + channel + " " + user + " :" + reason);
}
function kickBan(channel, user, reason){
ban(channel, user);
bot.sendData("KICK " + channel + " " + user + " :" + reason);
}
function ban(channel, user){
let banUser = whoCache[user.toLowerCase()];
if(banUser == undefined){
bot.sendData("MODE " + channel + " +b " + user);
}else{
if(banUser[2]){
bot.sendData("MODE " + channel + " +b $a:" + banUser[0]);
}else{
bot.sendData("MODE " + channel + " +b *!" + banUser[1].split("!")[1]);
}
}
}
/* ************************ */
/* re poll WHO every hour to prevent memory leaks */
setInterval(()=>{
for(let i in whoCache){
delete whoCache[i];
}
for(let i in config.channels){
whoList.push(i);
}
bot.sendData("WHO " + whoList[0] + " %uhna");
whoList.splice(0,1);
fs.writeFileSync("./log.json", JSON.stringify(chatLog));
},3.6e+6);