3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-25 04:02:39 +01:00

provisional poll thing. only commiting so i can switch branch w/e [#272]

This commit is contained in:
reality 2013-02-16 17:37:23 +00:00
parent b288487f23
commit 07f8a129d5
3 changed files with 38 additions and 26 deletions

View File

@ -1,7 +1,6 @@
var databank = require('databank'), var databank = require('databank'),
Databank = databank.Databank, Databank = databank.Databank,
DatabankObject = databank.DatabankObject; DatabankObject = databank.DatabankObject;
//DatabankStore = require('connect-databank')(express);
/** /**
* Multiplex databank objects * Multiplex databank objects
@ -15,10 +14,13 @@ var DatabaseDriver = function() {
*/ */
DatabaseDriver.prototype.createDB = function(name, driver, callback, schema) { DatabaseDriver.prototype.createDB = function(name, driver, callback, schema) {
var params = { 'schema': schema }; var params = { 'schema': schema };
if(driver == 'disk') params.dir = 'db';
this.databanks[name] = Databank.get(driver, params); this.databanks[name] = Databank.get(driver, params);
this.databanks[name].connect({}, function(err) { this.databanks[name].connect({}, function(err) {
if(err) { if(err) {
console.log('Didn\'t manage to connect to the data source.'); console.log('Didn\'t manage to connect to the data source - ' + err);
} else { } else {
callback(this.databanks[name]); callback(this.databanks[name]);
} }

View File

@ -8,19 +8,19 @@ var commands = function(dbot) {
options = event.input[2].toLowerCase().split(','), options = event.input[2].toLowerCase().split(','),
description = event.input[3]; description = event.input[3];
if(_.has(polls, name)) { var votes = {};
event.reply(dbot.t('poll_exists', { 'name': name })); for(var i=0;i<options.length;i++) {
} else { votes[options[i]] = 0;
polls[name] = { }
'name': name,
this.db.create(poll, name, {
'description': description, 'description': description,
'owner': dbot.api.users.resolveUser(event.server, event.user), 'owner': dbot.api.users.resolveUser(event.server, event.user),
'votes': {}, 'votes': votes,
'votees': {} 'votees': {}
}; },
for(var i=0;i<options.length;i++) { function(err, value) {
polls[name]['votes'][options[i]] = 0; if(!err) {
}
event.reply(dbot.t('poll_created', { event.reply(dbot.t('poll_created', {
'name': name, 'name': name,
'description': description, 'description': description,
@ -30,7 +30,10 @@ var commands = function(dbot) {
'path': 'polls/' + name 'path': 'polls/' + name
}) })
})); }));
} else if(err instanceof AlreadyExistsError) {
event.reply(dbot.t('poll_exists', { 'name': name }));
} }
});
}, },
'~addoption': function(event) { '~addoption': function(event) {

View File

@ -1,6 +1,13 @@
{ {
"help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md", "help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md",
"dbType": "disk",
"dbKeys": [ "polls" ], "dbKeys": [ "polls" ],
"ignorable": true, "ignorable": true,
"dependencies": [ "users", "command" ] "dependencies": [ "users", "command" ],
"schema": {
"poll": {
"pkey": "name",
"fields": [ "description", "owner", "votes", "votees" ]
}
}
} }