3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 14:29:29 +01:00

Add API function for notification in report module [#360]

This commit is contained in:
reality 2013-04-14 14:33:47 +00:00
parent b51f240061
commit d8267316ef

View File

@ -1,6 +1,23 @@
var _ = require('underscore')._; var _ = require('underscore')._;
var report = function(dbot) { var report = function(dbot) {
this.api = {
'notify': function(server, channel, reporter, reported, message) {
var channel = dbot.instance.connections[server].channels[channel];
var ops = _.filter(channel.nicks, function(user) {
if(this.config.notifyVoice) {
return user.op || user.voice;
} else {
return user.op;
}
}, this);
_.each(ops, function(user) {
dbot.say(server, user.name, message);
}, this);
}
};
var commands = { var commands = {
'~report': function(event) { '~report': function(event) {
var channelName = event.input[1]; var channelName = event.input[1];
@ -8,30 +25,20 @@ var report = function(dbot) {
var reason = event.input[3]; var reason = event.input[3];
if(_.has(event.allChannels, channelName)) { if(_.has(event.allChannels, channelName)) {
var channel = event.allChannels[channelName];
if(dbot.api.users.isChannelUser(event.server, nick, channelName, true)) { if(dbot.api.users.isChannelUser(event.server, nick, channelName, true)) {
var nick = dbot.api.users.resolveUser(event.server, nick, true); nick = dbot.api.users.resolveUser(event.server, nick, true);
var ops = _.filter(channel.nicks, function(user) { this.api.notify(event.server, channelName, event.user, nick, dbot.t('report', {
if(this.config.notifyVoice) { 'reporter': event.user,
return user.op || user.voice; 'reported': nick,
} else { 'channel': channelName,
return user.op; 'reason': reason
} }));
}, this);
_.each(ops, function(user) {
dbot.say(event.server, user.name, dbot.t('report', {
'reporter': event.user,
'reported': nick,
'channel': channelName,
'reason': reason
}));
}, this);
event.reply(dbot.t('reported', { 'reported': nick })); event.reply(dbot.t('reported', { 'reported': nick }));
} else { } else {
event.reply(dbot.t('user_not_found', { 'reported': nick, event.reply(dbot.t('user_not_found', {
'channel': channelName })); 'reported': nick,
'channel': channelName
}));
} }
} else { } else {
event.reply(dbot.t('not_in_channel', { 'channel': channelName })); event.reply(dbot.t('not_in_channel', { 'channel': channelName }));