3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-28 05:32:50 +01:00

~ignorechannel and ~unignorechannel now databankerised. Fixed bug with not initialising chan ignores onLoad. Ignore now fully databankerised. [#331]

This commit is contained in:
reality 2013-04-11 21:21:12 +00:00
parent 96a339a8d4
commit 6bae0f47bf
3 changed files with 91 additions and 33 deletions

View File

@ -20,7 +20,7 @@ var command = function(dbot) {
return;
}
}
dbot.api.ignore.isUserIgnoring(event.server, event.user, commandName, function(isIgnoring) {
dbot.api.ignore.isUserBanned(event.server, event.user, commandName, function(isBanned) {
if(isBanned) {

View File

@ -12,6 +12,25 @@ var api = function(dbot) {
this.internalAPI.isUserImpeded(server, user, item, 'bans', callback);
},
// Is channel ignoring module?
// TODO: Command support
'isChannelIgnoring': function(server, channelName, item, callback) {
var isIgnoring = false,
channel = false;
this.db.search('channel_ignores', {
'server': server,
'name': channel
}, function(result) {
channel = result;
}, function(err) {
if(!err && channel && _.include(channel.ignores, item)) {
isIgnoring = true;
}
callback(isIgnoring);
});
},
// Resolve a nick and return their user and ignores object
'getUserIgnores': function(server, user, callback) {
dbot.api.users.resolveUser(server, user, function(user) {

View File

@ -7,6 +7,7 @@
*/
var _ = require('underscore')._,
databank = require('databank'),
uuid = require('node-uuid'),
NoSuchThingError = databank.NoSuchThingError;
var ignore = function(dbot) {
@ -176,53 +177,85 @@ var ignore = function(dbot) {
},
'~ignorechannel': function(event) {
var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]);
var module = event.params[2];
var channelName = event.input[1],
module = event.input[2];
var ignoringChannel = function(err, result) {
dbot.instance.ignoreTag(channel, module);
event.reply(dbot.t('ignoring_channel', {
'module': module,
'channel': channelName
}));
};
// Ignoring the value of 'ignorable' at the moment
if(module == '*' || _.include(dbot.config.moduleNames, module)) {
if(!_.has(dbot.db.ignores, channel)) dbot.db.ignores[channel] = [];
if(!_.include(dbot.db.ignores[channel], module)) {
dbot.db.ignores[channel].push(module);
dbot.instance.ignoreTag(channel, module);
event.reply(dbot.t('ignoring_channel', {
'module': module,
'channel': channel
}));
} else {
event.reply(dbot.t('already_ignoring_channel', {
'module': module,
'channel': channel
}));
}
var channel = false;
this.db.search('channel_ignores', {
'server': event.server,
'name': channelName
}, function(result) {
channel = result;
}, function(err) {
if(!channel) {
var id = uuid.v4();
this.db.create('channel_ignores', id, {
'id': id,
'server': event.server,
'name': channelName,
'ignores': [ module ]
}, ignoringChannel);
} else {
if(!_.include(channel.ignores, module)) {
channel.ignores.push(module);
this.db.save('channel_ignores', channel.id, channel, ignoringChannel);
} else {
event.reply(dbot.t('already_ignoring_channel', {
'module': module,
'channel': channelName
}));
}
}
}.bind(this));
} else {
event.reply(dbot.t('module_not_exist', { 'module': module }));
}
},
'~unignorechannel': function(event) {
var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]);
var module = event.params[2];
var channelName = event.input[1],
module = event.input[2],
channel = false;
if(!_.has(dbot.db.ignores, channel)) dbot.db.ignores[channel] = [];
if(_.include(dbot.db.ignores[channel], module)) {
dbot.db.ignores[channel] = _.without(dbot.db.ignores[channel], module);
dbot.instance.removeIgnore(channel, module);
event.reply(dbot.t('unignoring_channel', {
'module': module,
'channel': channel
}));
} else {
event.reply(dbot.t('not_ignoring_channel', {
'module': module,
'channel': channel
}));
}
this.db.search('channel_ignores', {
'server': event.server,
'name': channelName
}, function(result) {
channel = result;
}, function(err) {
if(channel && _.include(channel.ignores, module)) {
channel.ignores = _.without(channel.ignores, module);
this.db.save('channel_ignores', channel.id, channel, function(err) {
dbot.instance.removeIgnore(channel, module);
event.reply(dbot.t('unignoring_channel', {
'module': module,
'channel': channelName
}));
});
} else {
event.reply(dbot.t('not_ignoring_channel', {
'module': module,
'channel': channelName
}));
}
}.bind(this));
}
};
commands['~ban'].regex = [/^~ban ([^ ]+) ([^ ]+)$/, 3];
commands['~unban'].regex = [/^~unban ([^ ]+) ([^ ]+)$/, 3];
commands['~ignorechannel'].regex = [/^~ignorechannel ([^ ]+) ([^ ]+)$/, 3];
commands['~unignorechannel'].regex = [/^~unignorechannel ([^ ]+) ([^ ]+)$/, 3];
commands['~ban'].access = 'moderator';
commands['~unban'].access = 'moderator';
@ -243,6 +276,12 @@ var ignore = function(dbot) {
}
});
}, function(err) { });
this.db.scan('channel_ignores', function(channel) {
_.each(channel.ignores, function(module) {
dbot.instance.ignoreTag(channel, module);
});
}, function(err) { });
};
};