update ignore to use save instead of save|create [#331]

This commit is contained in:
reality 2013-04-12 17:30:56 +00:00
parent b376a8fa54
commit 23dace4257

View File

@ -37,15 +37,6 @@ var ignore = function(dbot) {
}) })
.pluck('name') .pluck('name')
.value(); .value();
var ignoreCreated = function(err, result) {
if(!err) {
dbot.instance.ignoreTag(event.user, module);
event.reply(dbot.t('ignored', {
'user': event.user,
'module': module
}));
}
};
if(_.isUndefined(module)) { if(_.isUndefined(module)) {
event.reply(dbot.t('ignore_usage', { event.reply(dbot.t('ignore_usage', {
@ -57,19 +48,29 @@ var ignore = function(dbot) {
this.api.getUserIgnores(event.server, event.user, function(err, user, ignores) { this.api.getUserIgnores(event.server, event.user, function(err, user, ignores) {
if(!err) { if(!err) {
if(!ignores) { if(!ignores) {
this.db.create('ignores', user.id, { ignores = {
'id': user.id, 'id': user.id,
'ignores': [ module ], 'ignores': [],
'bans': [] 'bans': []
}, ignoreCreated); };
} else {
if(!_.include(ignores.ignores, module)) {
ignores.ignores.push(module);
this.db.save('ignores', user.id, ignores, ignoreCreated);
} else {
event.reply(dbot.t('already_ignoring', { 'user': event.user }));
}
} }
if(!_.include(ignores.ignores, module)) {
ignores.ignores.push(module);
this.db.save('ignores', user.id, ignores, function(err) {
if(!err) {
dbot.instance.ignoreTag(event.user, module);
event.reply(dbot.t('ignored', {
'user': event.user,
'module': module
}));
}
});
} else {
event.reply(dbot.t('already_ignoring', { 'user': event.user }));
}
} else {
// User doesn't exist
} }
}.bind(this)); }.bind(this));
} else { } else {
@ -107,37 +108,36 @@ var ignore = function(dbot) {
}, },
'~ban': function(event) { '~ban': function(event) {
var user = event.input[1], var nick = event.input[1],
item = event.input[2]; item = event.input[2];
var banCreated = function(err, result) {
if(!err) {
event.reply(dbot.t('banned_success', {
'user': event.user,
'banned': user,
'module': item
}));
}
};
if(module == '*' || _.include(dbot.config.moduleNames, item) || _.include(dbot.commands, item)) { if(module == '*' || _.include(dbot.config.moduleNames, item) || _.include(dbot.commands, item)) {
this.api.getUserIgnores(event.server, user, function(err, user, ignores) { this.api.getUserIgnores(event.server, nick, function(err, user, ignores) {
if(!err) { if(!err) {
if(!ignores) { if(!ignores) {
this.db.create('ignores', user.id, { ignores = {
'id': user.id, 'id': user.id,
'ignores': [], 'ignores': [],
'bans': [ item ] 'bans': []
}, banCreated); };
}
if(!_.include(ignores.bans, item)) {
ignores.bans.push(item);
this.db.save('ignores', user.id, ignores, function(err) {
if(!err) {
event.reply(dbot.t('banned_success', {
'user': event.user,
'banned': nick,
'module': item
}));
}
});
} else { } else {
if(!_.include(ignores.bans, item)) { event.reply(dbot.t('already_banned', {
ignores.bans.push(item); 'user': event.user,
this.db.save('ignores', user.id, ignores, banCreated); 'banned': nick
} else { }));
event.reply(dbot.t('already_banned', {
'user': event.user,
'banned': user
}));
}
} }
} }
}.bind(this)); }.bind(this));
@ -147,8 +147,8 @@ var ignore = function(dbot) {
}, },
'~unban': function(event) { '~unban': function(event) {
var nick = event.input[1]; var nick = event.input[1],
var item = event.input[2]; item = event.input[2];
this.api.getUserIgnores(event.server, nick, function(err, user, ignores) { this.api.getUserIgnores(event.server, nick, function(err, user, ignores) {
if(err || !ignores) { if(err || !ignores) {
@ -179,13 +179,6 @@ var ignore = function(dbot) {
'~ignorechannel': function(event) { '~ignorechannel': function(event) {
var channelName = event.input[1], var channelName = event.input[1],
module = event.input[2]; 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 // Ignoring the value of 'ignorable' at the moment
if(module == '*' || _.include(dbot.config.moduleNames, module)) { if(module == '*' || _.include(dbot.config.moduleNames, module)) {
@ -199,22 +192,28 @@ var ignore = function(dbot) {
}, function(err) { }, function(err) {
if(!channel) { if(!channel) {
var id = uuid.v4(); var id = uuid.v4();
this.db.create('channel_ignores', id, { channel = {
'id': id, 'id': id,
'server': event.server, 'server': event.server,
'name': channelName, 'name': channelName,
'ignores': [ module ] 'ignores': []
}, ignoringChannel); };
} else { }
if(!_.include(channel.ignores, module)) {
channel.ignores.push(module); if(!_.include(channel.ignores, module)) {
this.db.save('channel_ignores', channel.id, channel, ignoringChannel); channel.ignores.push(module);
} else { this.db.save('channel_ignores', channel.id, channel, function(err) {
event.reply(dbot.t('already_ignoring_channel', { dbot.instance.ignoreTag(channel, module);
event.reply(dbot.t('ignoring_channel', {
'module': module, 'module': module,
'channel': channelName 'channel': channelName
})); }));
} });
} else {
event.reply(dbot.t('already_ignoring_channel', {
'module': module,
'channel': channelName
}));
} }
}.bind(this)); }.bind(this));
} else { } else {