2018-02-16 14:17:52 +01:00
|
|
|
/**
|
|
|
|
* Module name: kill_namespam
|
|
|
|
* Description: destroy those wot hilight too many nicks at once . usually
|
|
|
|
* advertising their rubbish irc server (do not)
|
|
|
|
*/
|
|
|
|
|
|
|
|
var _ = require('underscore')._;
|
|
|
|
|
|
|
|
var kill_namespam = function(dbot) {
|
2018-03-01 15:15:35 +01:00
|
|
|
this.saveConfig = function() { // eugh
|
2018-03-01 15:21:09 +01:00
|
|
|
dbot.customConfig.modules.kill_namespam = this.config;
|
2018-03-01 15:15:35 +01:00
|
|
|
dbot.modules.admin.internalAPI.saveConfig();
|
|
|
|
}.bind(this);
|
2018-05-16 02:09:43 +02:00
|
|
|
|
|
|
|
this.matchedKill = {};
|
2018-03-01 15:15:35 +01:00
|
|
|
|
2018-02-16 14:17:52 +01:00
|
|
|
this.listener = function(event) {
|
2018-05-16 02:09:43 +02:00
|
|
|
if(event.action == 'PRIVMSG') {
|
2018-03-01 14:41:59 +01:00
|
|
|
// Here we listen for atropos
|
|
|
|
if(event.channel == this.config.cliconn_channel) {
|
|
|
|
if(event.message.match('▶')) {
|
2018-05-16 02:09:43 +02:00
|
|
|
var matchedPattern = _.find(this.config.cliconn_patterns, function(p) { return event.message.match(p); })
|
2018-03-01 14:41:59 +01:00
|
|
|
if(matchedPattern) {
|
2018-05-01 22:47:25 +02:00
|
|
|
var nick = event.message.split(' ')[2];
|
|
|
|
dbot.api.nickserv.getUserHost(event.server, nick, function(host) {
|
|
|
|
var userIsAuthenticated = host && host.startsWith('tripsit/');
|
|
|
|
if (userIsAuthenticated) {
|
|
|
|
event.reply(dbot.t('clikill_spared', {
|
|
|
|
'user': nick,
|
|
|
|
'pattern': matchedPattern
|
|
|
|
}));
|
|
|
|
} else {
|
2018-05-16 02:09:43 +02:00
|
|
|
if(!this.matchedKill[host]) {
|
|
|
|
// Defer killing this connection until after they join a non-exempted channel
|
|
|
|
this.matchedKill[host] = {
|
|
|
|
ip: event.message.split(' ')[1],
|
|
|
|
server: event.server,
|
|
|
|
matchedPattern: matchedPattern,
|
|
|
|
rUser: event.rUser
|
|
|
|
};
|
|
|
|
}
|
2018-05-01 22:47:25 +02:00
|
|
|
}
|
|
|
|
}, true);
|
2018-03-01 14:41:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is the namespam
|
2018-02-16 14:17:52 +01:00
|
|
|
if(event.channel == event.user) return; // return if pm
|
2018-02-16 14:44:47 +01:00
|
|
|
if(_.includes(this.config.exempt, event.user)) return;
|
2018-02-16 15:22:16 +01:00
|
|
|
|
|
|
|
var message;
|
2018-02-16 15:36:56 +01:00
|
|
|
var naughty = false;
|
2018-02-16 15:22:16 +01:00
|
|
|
|
|
|
|
// Check distinctive spam content match
|
2018-02-16 15:29:17 +01:00
|
|
|
if(_.any(this.config.advert_content, function(spam) { return event.message.indexOf(spam) != -1; })) {
|
2018-02-16 15:22:16 +01:00
|
|
|
message = dbot.t('spamcont_act', {
|
|
|
|
'user': event.user,
|
|
|
|
'channel': event.channel,
|
|
|
|
'action': this.config.action
|
|
|
|
});
|
2018-02-16 15:29:17 +01:00
|
|
|
naughty = true;
|
2018-02-16 15:22:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Name highlight spam
|
2018-02-16 14:37:26 +01:00
|
|
|
if(_.filter(event.message.split(' '), function(word) { return _.has(event.channel.nicks, word); }).length > this.config.sensitivity) {
|
2018-02-16 15:22:16 +01:00
|
|
|
message = dbot.t('namespam_act', {
|
2018-02-16 14:17:52 +01:00
|
|
|
'user': event.user,
|
|
|
|
'channel': event.channel,
|
|
|
|
'action': this.config.action,
|
|
|
|
'sensitivity': this.config.sensitivity
|
|
|
|
});
|
2018-02-16 15:29:17 +01:00
|
|
|
naughty = true;
|
2018-02-16 15:22:16 +01:00
|
|
|
}
|
2018-02-16 14:17:52 +01:00
|
|
|
|
2018-02-16 15:22:16 +01:00
|
|
|
if(naughty) {
|
2018-02-16 14:17:52 +01:00
|
|
|
switch(this.config.action) {
|
2018-05-16 02:09:43 +02:00
|
|
|
case 'kickban':
|
2018-02-16 14:19:12 +01:00
|
|
|
dbot.api.kick.ban(event.server, event.host, event.channel);
|
|
|
|
dbot.api.kick.kick(event.server, event.user, message);
|
2018-02-16 14:17:52 +01:00
|
|
|
break;
|
2018-02-16 14:30:56 +01:00
|
|
|
case 'kill':
|
2018-02-16 14:17:52 +01:00
|
|
|
dbot.api.kick.kill(event.server, event.user, message);
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dbot.api.report.notify('spam', event.server, event.user, event.channel, message, event.host, event.user);
|
|
|
|
}
|
2018-05-16 02:09:43 +02:00
|
|
|
} else if (event.action == 'JOIN') {
|
|
|
|
|
|
|
|
if(this.matchedKill[event.host]) {
|
|
|
|
if(this.config.exempt_channels.indexOf(event.channel) == -1) {
|
|
|
|
var kill = this.matchedKill[event.host];
|
|
|
|
delete this.matchedKill[event.host];
|
|
|
|
|
|
|
|
// Alternatively you can just do dbot.api.kick.kill(event.server, event.user, message);
|
|
|
|
dbot.say(event.server, 'operserv', 'akill add *@'+ kill.ip +' !P Naughty Nelly Auto-kill v6.2. Matched pattern: /'+ kill.matchedPattern +'/');
|
|
|
|
|
|
|
|
var msg = dbot.t('clikill_act', {
|
|
|
|
'ip': kill.ip,
|
|
|
|
'pattern': kill.matchedPattern
|
|
|
|
});
|
|
|
|
dbot.api.report.notify('autokill', kill.server, kill.rUser,
|
|
|
|
dbot.config.servers[kill.server].admin_channel, msg, kill.ip, kill.ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event.action == 'QUIT') {
|
|
|
|
if(this.matchedKill[event.host]) {
|
|
|
|
delete this.matchedKill[event.host];
|
|
|
|
}
|
|
|
|
}
|
2018-02-16 14:17:52 +01:00
|
|
|
}.bind(this);
|
2018-05-16 02:09:43 +02:00
|
|
|
this.on = ['PRIVMSG', 'JOIN', 'QUIT'];
|
2018-02-16 15:36:56 +01:00
|
|
|
|
|
|
|
this.commands = {
|
|
|
|
'~add_spamkill': function(event) {
|
|
|
|
this.config.advert_content.push(event.params.slice(1).join(' '))
|
2018-03-01 15:15:35 +01:00
|
|
|
this.saveConfig();
|
2018-02-16 15:36:56 +01:00
|
|
|
event.reply('Users daring to utter the above to be classified as spam.');
|
|
|
|
},
|
|
|
|
|
|
|
|
'~del_spamkill': function(event) {
|
|
|
|
this.config.advert_content = _.without(this.config.advert_content, event.params.slice(1).join(' '));
|
2018-03-01 15:15:35 +01:00
|
|
|
this.saveConfig();
|
2018-02-16 15:36:56 +01:00
|
|
|
event.reply('Users will no longer be killed for this utterance.');
|
2018-03-01 14:41:59 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
'~add_clikill': function(event) {
|
|
|
|
var pattern = event.params.slice(1).join(' ');
|
|
|
|
this.config.cliconn_patterns.push(pattern);
|
2018-03-01 15:15:35 +01:00
|
|
|
this.saveConfig();
|
2018-03-01 14:41:59 +01:00
|
|
|
event.reply('Client connection notices matching pattern /'+ pattern +'/ shall henceforth get rekt.');
|
|
|
|
},
|
|
|
|
|
|
|
|
'~del_clikill': function(event) {
|
|
|
|
var pattern = event.params.slice(1).join(' ');
|
|
|
|
this.config.cliconn_patterns = _.without(this.config.cliconn_patterns, pattern);
|
2018-03-01 15:15:35 +01:00
|
|
|
this.saveConfig();
|
2018-03-01 14:41:59 +01:00
|
|
|
event.reply('Client connection notices matching pattern /'+ pattern +'/ will no longer get rekt.');
|
|
|
|
},
|
|
|
|
|
|
|
|
'~list_clikill': function(event) {
|
2018-03-01 15:01:00 +01:00
|
|
|
event.reply('Currently active "cliconn" kills (to use add/del, provide the pattern, not the index, and do not include the surrounding //');
|
2018-03-01 14:41:59 +01:00
|
|
|
_.each(this.config.cliconn_patterns, function(pattern, i) {
|
|
|
|
event.reply('['+i+'] /' + pattern + '/');
|
|
|
|
});
|
2018-02-16 15:36:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
_.each(this.commands, function(c) {
|
|
|
|
c.access = 'moderator';
|
|
|
|
});
|
2018-02-16 14:17:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
|
|
|
return new kill_namespam(dbot);
|
|
|
|
};
|