forked from GitHub/dbot
Provisional/example ~ignore functionality using databank [#331]
This commit is contained in:
parent
c1224a8f2c
commit
14e03313ec
@ -2,5 +2,6 @@
|
|||||||
"ignorable": false,
|
"ignorable": false,
|
||||||
"dependencies": [ "command" ],
|
"dependencies": [ "command" ],
|
||||||
"dbKeys": [ "ignores", "bans" ],
|
"dbKeys": [ "ignores", "bans" ],
|
||||||
|
"dbType": "memory",
|
||||||
"help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md"
|
"help": "http://github.com/reality/depressionbot/blob/master/modules/ignore/README.md"
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,9 @@
|
|||||||
* this information, since that actually performs the ignorance. Also provides
|
* this information, since that actually performs the ignorance. Also provides
|
||||||
* commands for moderators to choose the bot to ignore certain channels.
|
* commands for moderators to choose the bot to ignore certain channels.
|
||||||
*/
|
*/
|
||||||
var _ = require('underscore')._;
|
var _ = require('underscore')._,
|
||||||
|
databank = require('databank'),
|
||||||
|
NoSuchThingError = databank.NoSuchThingError;
|
||||||
|
|
||||||
var ignore = function(dbot) {
|
var ignore = function(dbot) {
|
||||||
var commands = {
|
var commands = {
|
||||||
@ -25,21 +27,39 @@ var ignore = function(dbot) {
|
|||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
if(module == '*' || _.include(ignorableModules, module)) {
|
if(module == '*' || _.include(ignorableModules, module)) {
|
||||||
if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) {
|
dbot.api.users.resolveUser(event.server, event.user, function(user) {
|
||||||
event.reply(dbot.t('already_ignoring', { 'user': event.user }));
|
this.db.read('ignores', user.id, function(err, ignores) {
|
||||||
} else {
|
if(err == NoSuchThingError) {
|
||||||
if(_.has(dbot.db.ignores, module)) {
|
this.db.create('ignores', user.id, {
|
||||||
dbot.db.ignores[event.user].push(module);
|
'id': user.id,
|
||||||
} else {
|
'ignores': [ module ]
|
||||||
dbot.db.ignores[event.user] = [module];
|
}, function(err, result) {
|
||||||
}
|
if(!err) {
|
||||||
|
dbot.instance.ignoreTag(event.user, module);
|
||||||
dbot.instance.ignoreTag(event.user, module);
|
event.reply(dbot.t('ignored', {
|
||||||
event.reply(dbot.t('ignored', {
|
'user': event.user,
|
||||||
'user': event.user,
|
'module': module
|
||||||
'module': module
|
}));
|
||||||
}));
|
}
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
if(!_.include(ignores.ignores, module)) {
|
||||||
|
ignores.ignores.push(module);
|
||||||
|
this.db.save('ignores', user.id, 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 {
|
} else {
|
||||||
event.reply(dbot.t('invalid_ignore', { 'user': event.user }));
|
event.reply(dbot.t('invalid_ignore', { 'user': event.user }));
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ var users = function(dbot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user.currentNick = event.user;
|
user.currentNick = event.user;
|
||||||
this.db.save(users, user.id, user, function(err) {
|
this.db.save('users', user.id, user, function(err) {
|
||||||
if(err) {
|
if(err) {
|
||||||
// QQ
|
// QQ
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user