3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-27 13:12:44 +01:00
dbot/modules/kick/kick.js

157 lines
5.8 KiB
JavaScript
Raw Normal View History

2013-01-12 23:53:13 +01:00
var _ = require('underscore')._;
2014-02-27 00:24:56 +01:00
var kick = function(dbot) {
this.api = {
2013-08-26 01:20:14 +02:00
'ban': function(server, host, channel) {
2013-08-28 14:25:33 +02:00
dbot.instance.connections[server].send('MODE ' + channel + ' +b *!*@' + host);
},
'quiet': function(server, host, channel) {
dbot.instance.connections[server].send('MODE ' + channel + ' +q *!*@' + host);
2013-04-14 17:41:40 +02:00
},
'unquiet': function(server, host, channel) {
dbot.instance.connections[server].send('MODE ' + channel + ' -q *!*@' + host);
2013-07-01 19:38:25 +02:00
},
2014-07-23 18:08:05 +02:00
'devoice': function(server, nick, channel) {
dbot.instance.connections[server].send('MODE ' + channel + ' -v ' +nick);
},
'voice': function(server, nick, channel) {
dbot.instance.connections[server].send('MODE ' + channel + ' +v ' +nick);
},
'kick': function(server, user, channel, msg) {
2013-02-05 20:26:29 +01:00
dbot.instance.connections[server].send('KICK ' + channel + ' ' + user + ' :' + msg);
2013-06-10 00:50:11 +02:00
},
'unban': function(server, host, channel) {
// TODO: Wrest control from chanserv
2015-01-29 23:24:45 +01:00
//dbot.say(server, this.config.chanserv, 'unban ' + channel + ' *!*@' + host);
dbot.instance.connections[server].send('MODE ' + channel + ' -b *!*@' + host);
},
'networkUnban': function(server, unbanee, unbanner, callback) {
var channels = dbot.config.servers[server].channels,
network = this.config.network_name[server] || server,
adminChannel = dbot.config.servers[server].admin_channel;
if(_.has(this.hosts, server) && _.has(this.hosts[server], unbanee)) {
var host = this.hosts[server][unbanee];
// Notify Staff
if(_.isUndefined(adminChannel)) {
adminChannel = event.channel.name;
}
var notifyString = dbot.t('nunbanned', {
'network': network,
'unbanee': unbanee,
2013-09-08 01:02:04 +02:00
'unbanner': unbanner.currentNick
});
2013-09-08 01:02:04 +02:00
dbot.api.report.notify('unban', server, unbanner, adminChannel, notifyString);
dbot.say(server, adminChannel, notifyString);
// Notify Unbanee
dbot.say(server, unbanee, dbot.t('nunban_notify', {
'network': network,
'unbanee': unbanee,
2013-09-08 01:02:04 +02:00
'unbanner': unbanner.currentNick
}));
// Unban
var i = 0;
var unbanChannel = function(channels) {
if(i >= channels.length) return;
var channel = channels[i];
this.api.unban(server, host, channel);
setTimeout(function() {
i++; unbanChannel(channels);
}, 1000);
}.bind(this);
unbanChannel(channels);
2014-02-07 21:45:14 +01:00
dbot.say(server, 'NickServ', 'FREEZE ' + unbanee + ' OFF');
callback(null); // Success
} else {
// Attempt to look up the host on-the-fly
2013-09-08 01:02:04 +02:00
dbot.api.nickserv.getUserHost(server, unbanee, unbanner, function(host) {
if(host) {
if(!_.has(this.hosts, server)) this.hosts[server] = {};
this.hosts[server][unbanee] = host;
this.api.networkUnban(server, unbanee, unbanner);
} else {
callback(true); // No host could be found
}
2013-07-06 20:00:34 +02:00
}.bind(this));
}
}
};
this.internalAPI = {
'addTempBan': function(server, banee, timeout) {
dbot.api.timers.addTimeout(timeout, function() {
this.api.networkUnban(server, banee, dbot.config.name, function(err) {});
delete this.tempBans[server][banee];
}.bind(this));
}.bind(this)
};
2013-01-15 00:00:16 +01:00
this.listener = function(event) {
if(event.kickee == dbot.config.name) {
2014-01-11 00:49:33 +01:00
dbot.instance.join(event, event.channel.name);
2013-01-15 00:00:16 +01:00
event.reply(dbot.t('kicked_dbot', { 'botname': dbot.config.name }));
dbot.db.kicks[dbot.config.name] += 1;
} else {
if(!_.has(dbot.db.kicks, event.kickee)) {
dbot.db.kicks[event.kickee] = 1;
} else {
2013-01-15 00:00:16 +01:00
dbot.db.kicks[event.kickee] += 1;
}
2013-01-15 00:00:16 +01:00
if(!_.has(dbot.db.kickers, event.user)) {
dbot.db.kickers[event.user] = 1;
} else {
dbot.db.kickers[event.user] += 1;
}
2013-01-15 00:00:16 +01:00
if(!this.config.countSilently) {
event.reply(event.kickee + '-- (' + dbot.t('user_kicks', {
'user': event.kickee,
'kicks': dbot.db.kicks[event.kickee],
'kicked': dbot.db.kickers[event.kickee]
}) + ')');
}
2013-01-15 00:00:16 +01:00
}
}.bind(this);
2013-01-15 00:00:16 +01:00
this.on = 'KICK';
2013-06-10 19:10:57 +02:00
this.onLoad = function() {
_.each(this.tempBans, function(bans, server) {
_.each(bans, function(timeout, nick) {
timeout = new Date(timeout);
2013-06-10 19:10:57 +02:00
this.internalAPI.addTempBan(server, nick, timeout);
}, this);
}, this);
if(_.has(dbot.modules, 'web')) {
dbot.api.web.addIndexLink('/bans', 'Ban List');
}
2014-02-27 00:24:56 +01:00
if(!_.has(dbot.db, 'hosts')) {
dbot.db.hosts = {};
_.each(dbot.config.servers, function(v, k) {
dbot.db.hosts[k] = {};
}, this);
}
if(!_.has(dbot.db, 'tempBans')) dbot.db.tempBans = {};
this.hosts = dbot.db.hosts;
this.tempBans = dbot.db.tempBans;
2013-06-10 19:10:57 +02:00
}.bind(this);
};
exports.fetch = function(dbot) {
2013-01-15 00:00:16 +01:00
return new kick(dbot);
};