3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-30 07:59:25 +01:00
dbot/modules/kill_namespam/kill_namespam.js

160 lines
5.9 KiB
JavaScript
Raw Normal View History

/**
* 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);
this.matchedKill = {};
2018-03-01 15:15:35 +01:00
this.listener = function(event) {
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-04-20 23:01:11 +02:00
var matchedPattern = _.find(this.config.cliconn_patterns,
2018-05-16 02:12:40 +02:00
function(p) { try { return event.message.match(p); } catch(e) {}; }); // ok.jpg
2018-03-01 14:41:59 +01:00
if(matchedPattern) {
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 {
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
};
}
}
}, true);
2018-03-01 14:41:59 +01:00
}
}
}
// This is the namespam
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;
var message;
2018-02-16 15:36:56 +01:00
var naughty = false;
// 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; })) {
message = dbot.t('spamcont_act', {
'user': event.user,
'channel': event.channel,
'action': this.config.action
2018-05-28 16:35:11 +02:00
}) + ' ' + dbot.t('sasl_hint');
2018-02-16 15:29:17 +01:00
naughty = true;
}
// Name highlight spam
if(_.filter(event.message.split(' '), function(word) { return _.has(event.channel.nicks, word); }).length > this.config.sensitivity) {
message = dbot.t('namespam_act', {
'user': event.user,
'channel': event.channel,
'action': this.config.action,
'sensitivity': this.config.sensitivity
2018-05-28 16:35:11 +02:00
}) + ' ' + dbot.t('sasl_hint');
2018-02-16 15:29:17 +01:00
naughty = true;
}
if(naughty) {
switch(this.config.action) {
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);
break;
2018-02-16 14:30:56 +01:00
case 'kill':
dbot.api.kick.kill(event.server, event.user, message);
default: break;
}
2018-05-28 16:35:11 +02:00
dbot.api.report.notify('spam', event.server, event.user, event.channel, message, event.host, event.user);
}
} 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];
}
}
}.bind(this);
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';
});
};
exports.fetch = function(dbot) {
return new kill_namespam(dbot);
};