Merge pull request #677 from Scritches/master

'kick' and 'kill_namespam' module changes
This commit is contained in:
Luke Slater 2018-05-16 10:34:38 +01:00 committed by GitHub
commit ab6cb80ea2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 795 additions and 711 deletions

View File

@ -39,7 +39,8 @@ var commands = function(dbot) {
if (this.recentTimeouts[user.id] == 0) { if (this.recentTimeouts[user.id] == 0) {
delete this.recentTimeouts[user.id]; delete this.recentTimeouts[user.id];
} }
}.bind(this), 3600000); }
.bind(this), 3600000);
if (this.recentTimeouts[user.id] == 3) { if (this.recentTimeouts[user.id] == 3) {
duration = null; duration = null;
@ -51,7 +52,8 @@ var commands = function(dbot) {
event.reply(response); event.reply(response);
}); });
} }
}.bind(this)); }
.bind(this));
}, },
'~unquiet': function (event) { '~unquiet': function (event) {
@ -66,7 +68,9 @@ var commands = function(dbot) {
} else { } else {
this.api.unquiet(server, this.hosts[server][quietee], channel); this.api.unquiet(server, this.hosts[server][quietee], channel);
} }
event.reply(dbot.t('unquieted', { 'quietee': quietee })); event.reply(dbot.t('unquieted', {
'quietee': quietee
}));
dbot.api.report.notify('unquiet', server, event.rUser, channel, dbot.api.report.notify('unquiet', server, event.rUser, channel,
dbot.t('unquiet_notify', { dbot.t('unquiet_notify', {
'unquieter': quieter, 'unquieter': quieter,
@ -98,7 +102,8 @@ var commands = function(dbot) {
// Kick and ban from all channels on the network. // Kick and ban from all channels on the network.
'~nban': function (event) { '~nban': function (event) {
if(!event.input) return; if (!event.input)
return;
var server = event.server, var server = event.server,
banner = event.user, banner = event.user,
@ -116,7 +121,10 @@ var commands = function(dbot) {
dbot.api.nickserv.getUserHost(event.server, banee, function (host) { dbot.api.nickserv.getUserHost(event.server, banee, function (host) {
// Add host record entry // Add host record entry
if (host) { if (host) {
var didKill = false;
if ((reason.match('#line') || reason.match('#specialk') || reason.match('#kline')) && _.include(dbot.access.moderator(), event.rUser.primaryNick)) { if ((reason.match('#line') || reason.match('#specialk') || reason.match('#kline')) && _.include(dbot.access.moderator(), event.rUser.primaryNick)) {
didKill = true;
var t = ' !P '; var t = ' !P ';
if (timeout) { if (timeout) {
t = ' !T ' + (timeout * 60); t = ' !T ' + (timeout * 60);
@ -124,6 +132,8 @@ var commands = function(dbot) {
dbot.say(event.server, 'operserv', 'akill add ' + banee + t + banee + ' banned by ' + banner + ': ' + reason); dbot.say(event.server, 'operserv', 'akill add ' + banee + t + banee + ' banned by ' + banner + ': ' + reason);
} }
// Do not ban if user was killed - redundant
if(!didKill) {
// Ban from current channel first // Ban from current channel first
this.api.ban(server, host, event.channel); this.api.ban(server, host, event.channel);
this.api.kick(server, banee, event.channel, reason + this.api.kick(server, banee, event.channel, reason +
@ -138,14 +148,18 @@ var commands = function(dbot) {
// Ban the user from all channels // Ban the user from all channels
var i = 0; var i = 0;
var banChannel = function (channels) { var banChannel = function (channels) {
if(i >= channels.length) return; if (i >= channels.length)
return;
var channel = channels[i]; var channel = channels[i];
this.api.ban(server, host, channel); this.api.ban(server, host, channel);
this.api.kick(server, banee, channel, reason + this.api.kick(server, banee, channel, reason +
' (network-wide ban)'); ' (network-wide ban)');
i++; banChannel(channels); i++;
}.bind(this);
banChannel(channels); banChannel(channels);
}
.bind(this);
banChannel(channels);
}
this.hosts[event.server][banee] = host; this.hosts[event.server][banee] = host;
@ -164,9 +178,13 @@ var commands = function(dbot) {
timeout += ' hours'; timeout += ' hours';
} }
if(!_.has(this.tempBans, event.server)) this.tempBans[event.server] = {}; // Do not schedule unbans if the user was killed as no ban was put in place
if(!didKill) {
if (!_.has(this.tempBans, event.server))
this.tempBans[event.server] = {};
this.tempBans[event.server][banee] = msTimeout; this.tempBans[event.server][banee] = msTimeout;
this.internalAPI.addTempBan(event.server, banee, msTimeout); this.internalAPI.addTempBan(event.server, banee, msTimeout);
}
var notifyString = dbot.t('tbanned', { var notifyString = dbot.t('tbanned', {
'network': network, 'network': network,
@ -232,9 +250,12 @@ var commands = function(dbot) {
// err // err
dbot.say(event.server, 'NickServ', 'FREEZE ' + banee + ' ON ' + reason); dbot.say(event.server, 'NickServ', 'FREEZE ' + banee + ' ON ' + reason);
} else { } else {
event.reply(dbot.t('no_user', { 'user': banee })); event.reply(dbot.t('no_user', {
'user': banee
}));
} }
}.bind(this)); }
.bind(this));
}, },
'~nunban': function (event) { '~nunban': function (event) {
@ -244,7 +265,9 @@ var commands = function(dbot) {
this.api.networkUnban(event.server, unbanee, unbanner, host, function (err) { this.api.networkUnban(event.server, unbanee, unbanner, host, function (err) {
if (err) { if (err) {
event.reply(dbot.t('nunban_error', { 'unbanee': unbanee })); event.reply(dbot.t('nunban_error', {
'unbanee': unbanee
}));
} }
}); });
}, },
@ -281,7 +304,9 @@ var commands = function(dbot) {
var orderedKickLeague = function (list, topWhat) { var orderedKickLeague = function (list, topWhat) {
var kickArr = _.chain(list) var kickArr = _.chain(list)
.pairs() .pairs()
.sortBy(function(kick) { return kick[1] }) .sortBy(function (kick) {
return kick[1]
})
.reverse() .reverse()
.first(10) .first(10)
.value(); .value();
@ -310,7 +335,13 @@ var commands = function(dbot) {
} }
if (!_.has(this.voteQuiets, user.id)) { if (!_.has(this.voteQuiets, user.id)) {
this.voteQuiets[user.id] = { 'user': user.id, 'reason': reason, 'channel': event.channel, 'yes': [event.rUser.primaryNick], 'no': [] }; this.voteQuiets[user.id] = {
'user': user.id,
'reason': reason,
'channel': event.channel,
'yes': [event.rUser.primaryNick],
'no': []
};
event.reply(event.user + ' has started a vote to quiet ' + target + ' for "' + reason + '." Type either "~voteyes ' + target + '" or "~voteno ' + target + '" in the next 90 seconds.'); event.reply(event.user + ' has started a vote to quiet ' + target + ' for "' + reason + '." Type either "~voteyes ' + target + '" or "~voteno ' + target + '" in the next 90 seconds.');
this.voteQuiets[user.id].timer = setTimeout(function () { this.voteQuiets[user.id].timer = setTimeout(function () {
@ -337,8 +368,10 @@ var commands = function(dbot) {
setTimeout(function () { setTimeout(function () {
delete this.voteQuiets[user.id]; delete this.voteQuiets[user.id];
}.bind(this), 600000); }
}.bind(this), 90000); .bind(this), 600000);
}
.bind(this), 90000);
} else { } else {
if (this.voteQuiets[user.id].spent) { if (this.voteQuiets[user.id].spent) {
event.reply('A votequiet attempt has already been made on this user in the last 10 minutes.'); event.reply('A votequiet attempt has already been made on this user in the last 10 minutes.');
@ -357,7 +390,8 @@ var commands = function(dbot) {
vq.spent = true; vq.spent = true;
setTimeout(function () { setTimeout(function () {
delete this.voteQuiets[user.id]; delete this.voteQuiets[user.id];
}.bind(this), 600000); }
.bind(this), 600000);
event.reply(response); event.reply(response);
}); });
} }
@ -369,7 +403,8 @@ var commands = function(dbot) {
} else { } else {
event.reply('Target does not seem to be in the channel.'); event.reply('Target does not seem to be in the channel.');
} }
}.bind(this)); }
.bind(this));
} else { } else {
event.reply('Target does not seem to be in the channel.'); event.reply('Target does not seem to be in the channel.');
} }
@ -399,7 +434,8 @@ var commands = function(dbot) {
vq.spent = true; vq.spent = true;
setTimeout(function () { setTimeout(function () {
delete this.voteQuiets[user.id]; delete this.voteQuiets[user.id];
}.bind(this), 600000); }
.bind(this), 600000);
event.reply(response); event.reply(response);
}); });
} }
@ -412,7 +448,8 @@ var commands = function(dbot) {
} else { } else {
event.reply('No idea who that is m8'); event.reply('No idea who that is m8');
} }
}.bind(this)); }
.bind(this));
}, },
'~voteno': function (event) { '~voteno': function (event) {
@ -440,7 +477,8 @@ var commands = function(dbot) {
} else { } else {
event.reply('No idea who that is m8'); event.reply('No idea who that is m8');
} }
}.bind(this)); }
.bind(this));
} }
}; };

View File

@ -78,7 +78,8 @@ var kick = function(dbot) {
}), false, quietee); }), false, quietee);
}); });
} }
}.bind(this)); }
.bind(this));
callback(dbot.t('tquieted', { callback(dbot.t('tquieted', {
'quietee': quietee, 'quietee': quietee,
'minutes': duration 'minutes': duration
@ -89,10 +90,11 @@ var kick = function(dbot) {
'quieter': quieter.primaryNick, 'quieter': quieter.primaryNick,
'quietee': quietee, 'quietee': quietee,
'reason': reason 'reason': reason
}), false, quietee }), false, quietee);
);
} else { } else {
callback(dbot.t('quieted', { 'quietee': quietee })); callback(dbot.t('quieted', {
'quietee': quietee
}));
dbot.api.report.notify('quiet', server, quieter.primaryNick, channel, dbot.api.report.notify('quiet', server, quieter.primaryNick, channel,
dbot.t('quiet_notify', { dbot.t('quiet_notify', {
'quieter': quieter.primaryNick, 'quieter': quieter.primaryNick,
@ -115,9 +117,12 @@ var kick = function(dbot) {
function () {}); function () {});
} }
} else { } else {
event.reply(dbot.t('no_user', { 'user': quietee })); event.reply(dbot.t('no_user', {
'user': quietee
}));
} }
}.bind(this)); }
.bind(this));
}, },
'networkUnban': function (server, unbanee, unbanner, manualHost, callback) { 'networkUnban': function (server, unbanee, unbanner, manualHost, callback) {
@ -156,13 +161,16 @@ var kick = function(dbot) {
// Unban // Unban
var i = 0; var i = 0;
var unbanChannel = function (channels) { var unbanChannel = function (channels) {
if(i >= channels.length) return; if (i >= channels.length)
return;
var channel = channels[i]; var channel = channels[i];
this.api.unban(server, host, channel); this.api.unban(server, host, channel);
setTimeout(function () { setTimeout(function () {
i++; unbanChannel(channels); i++;
unbanChannel(channels);
}, 1000); }, 1000);
}.bind(this); }
.bind(this);
unbanChannel(channels); unbanChannel(channels);
dbot.say(server, 'NickServ', 'FREEZE ' + unbanee + ' OFF'); dbot.say(server, 'NickServ', 'FREEZE ' + unbanee + ' OFF');
@ -171,13 +179,15 @@ var kick = function(dbot) {
// Attempt to look up the host on-the-fly // Attempt to look up the host on-the-fly
dbot.api.nickserv.getUserHost(server, unbanee, unbanner, function (host) { dbot.api.nickserv.getUserHost(server, unbanee, unbanner, function (host) {
if (host) { if (host) {
if(!_.has(this.hosts, server)) this.hosts[server] = {}; if (!_.has(this.hosts, server))
this.hosts[server] = {};
this.hosts[server][unbanee] = host; this.hosts[server][unbanee] = host;
this.api.networkUnban(server, unbanee, unbanner); this.api.networkUnban(server, unbanee, unbanner);
} else { } else {
callback(true); // No host could be found callback(true); // No host could be found
} }
}.bind(this)); }
.bind(this));
} }
} }
}; };
@ -188,15 +198,20 @@ var kick = function(dbot) {
dbot.api.timers.addTimeout(timeout, function () { dbot.api.timers.addTimeout(timeout, function () {
this.api.networkUnban(server, banee, bot, undefined, function (err) {}); this.api.networkUnban(server, banee, bot, undefined, function (err) {});
delete this.tempBans[server][banee]; delete this.tempBans[server][banee];
}.bind(this)); }
}.bind(this)); .bind(this));
}.bind(this) }
.bind(this));
}
.bind(this)
}; };
this.listener = function (event) { this.listener = function (event) {
if (event.kickee == dbot.config.name) { if (event.kickee == dbot.config.name) {
dbot.instance.join(event, event.channel.name); dbot.instance.join(event, event.channel.name);
event.reply(dbot.t('kicked_dbot', { 'botname': dbot.config.name })); event.reply(dbot.t('kicked_dbot', {
'botname': dbot.config.name
}));
dbot.db.kicks[dbot.config.name] += 1; dbot.db.kicks[dbot.config.name] += 1;
} else { } else {
if (!_.has(dbot.db.kicks, event.kickee)) { if (!_.has(dbot.db.kicks, event.kickee)) {
@ -219,7 +234,8 @@ var kick = function(dbot) {
}) + ')'); }) + ')');
} }
} }
}.bind(this); }
.bind(this);
this.on = 'KICK'; this.on = 'KICK';
this.onLoad = function () { this.onLoad = function () {
@ -229,7 +245,8 @@ var kick = function(dbot) {
dbot.db.hosts[k] = {}; dbot.db.hosts[k] = {};
}, this); }, this);
} }
if(!_.has(dbot.db, 'tempBans')) dbot.db.tempBans = {}; if (!_.has(dbot.db, 'tempBans'))
dbot.db.tempBans = {};
this.hosts = dbot.db.hosts; this.hosts = dbot.db.hosts;
this.tempBans = dbot.db.tempBans; this.tempBans = dbot.db.tempBans;
this.voteQuiets = {}; this.voteQuiets = {};
@ -244,7 +261,8 @@ var kick = function(dbot) {
if (_.has(dbot.modules, 'web')) { if (_.has(dbot.modules, 'web')) {
dbot.api.web.addIndexLink('/bans', 'Ban List'); dbot.api.web.addIndexLink('/bans', 'Ban List');
} }
}.bind(this); }
.bind(this);
}; };
exports.fetch = function (dbot) { exports.fetch = function (dbot) {

View File

@ -9,7 +9,9 @@ var pages = function(dbot) {
}, },
'/underbans': function (req, res) { '/underbans': function (req, res) {
this.db.search('nbans', { 'server': server }, function(ban) { this.db.search('nbans', {
'server': server
}, function (ban) {
if (ban.reason.match('#underban')) { if (ban.reason.match('#underban')) {
bans.push(ban); bans.push(ban);
} }
@ -25,7 +27,9 @@ var pages = function(dbot) {
var server = req.params.server, var server = req.params.server,
bans = []; bans = [];
this.db.search('nbans', { 'server': server }, function(ban) { this.db.search('nbans', {
'server': server
}, function (ban) {
bans.push(ban); bans.push(ban);
}, function () { }, function () {
res.render('bans', { res.render('bans', {

View File

@ -6,5 +6,6 @@
"________ ______" "________ ______"
], ],
"cliconn_channel": "#dnsbl", "cliconn_channel": "#dnsbl",
"cliconn_patterns": [] "cliconn_patterns": [],
"exempt_channels": []
} }

View File

@ -12,7 +12,10 @@ var kill_namespam = function(dbot) {
dbot.modules.admin.internalAPI.saveConfig(); dbot.modules.admin.internalAPI.saveConfig();
}.bind(this); }.bind(this);
this.matchedKill = {};
this.listener = function(event) { this.listener = function(event) {
if(event.action == 'PRIVMSG') {
// Here we listen for atropos // Here we listen for atropos
if(event.channel == this.config.cliconn_channel) { if(event.channel == this.config.cliconn_channel) {
if(event.message.match('▶')) { if(event.message.match('▶')) {
@ -28,18 +31,15 @@ var kill_namespam = function(dbot) {
'pattern': matchedPattern 'pattern': matchedPattern
})); }));
} else { } else {
var ip = event.message.split(' ')[1] if(!this.matchedKill[host]) {
// Defer killing this connection until after they join a non-exempted channel
// Alternatively you can just do dbot.api.kick.kill(event.server, event.user, message); this.matchedKill[host] = {
dbot.say(event.server, 'operserv', 'akill add *@'+ ip +' !P Naughty Nelly Auto-kill v6.2. Matched pattern: /'+ matchedPattern +'/'); ip: event.message.split(' ')[1],
server: event.server,
var msg = dbot.t('clikill_act', { matchedPattern: matchedPattern,
'ip': ip, rUser: event.rUser
'pattern': matchedPattern };
}); }
event.reply(msg);
dbot.api.report.notify('autokill', event.server, event.rUser,
dbot.config.servers[event.server].admin_channel, msg, ip, ip);
} }
}, true); }, true);
} }
@ -87,8 +87,31 @@ var kill_namespam = function(dbot) {
dbot.api.report.notify('spam', event.server, event.user, event.channel, message, event.host, event.user); 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); }.bind(this);
this.on = 'PRIVMSG'; this.on = ['PRIVMSG', 'JOIN', 'QUIT'];
this.commands = { this.commands = {
'~add_spamkill': function(event) { '~add_spamkill': function(event) {