3
0
mirror of https://github.com/reality/dbot.git synced 2024-11-27 22:39:26 +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,16 +1,9 @@
var _ = require('underscore')._; var _ = require('underscore')._;
var report = function(dbot) { var report = function(dbot) {
var commands = { this.api = {
'~report': function(event) { 'notify': function(server, channel, reporter, reported, message) {
var channelName = event.input[1]; var channel = dbot.instance.connections[server].channels[channel];
var nick = event.input[2];
var reason = event.input[3];
if(_.has(event.allChannels, channelName)) {
var channel = event.allChannels[channelName];
if(dbot.api.users.isChannelUser(event.server, nick, channelName, true)) {
var nick = dbot.api.users.resolveUser(event.server, nick, true);
var ops = _.filter(channel.nicks, function(user) { var ops = _.filter(channel.nicks, function(user) {
if(this.config.notifyVoice) { if(this.config.notifyVoice) {
return user.op || user.voice; return user.op || user.voice;
@ -20,18 +13,32 @@ var report = function(dbot) {
}, this); }, this);
_.each(ops, function(user) { _.each(ops, function(user) {
dbot.say(event.server, user.name, dbot.t('report', { dbot.say(server, user.name, message);
}, this);
}
};
var commands = {
'~report': function(event) {
var channelName = event.input[1];
var nick = event.input[2];
var reason = event.input[3];
if(_.has(event.allChannels, channelName)) {
if(dbot.api.users.isChannelUser(event.server, nick, channelName, true)) {
nick = dbot.api.users.resolveUser(event.server, nick, true);
this.api.notify(event.server, channelName, event.user, nick, dbot.t('report', {
'reporter': event.user, 'reporter': event.user,
'reported': nick, 'reported': nick,
'channel': channelName, 'channel': channelName,
'reason': reason '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 }));