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'),
Databank = databank.Databank,
DatabankObject = databank.DatabankObject;
//DatabankStore = require('connect-databank')(express);
/**
* Multiplex databank objects
@ -15,10 +14,13 @@ var DatabaseDriver = function() {
*/
DatabaseDriver.prototype.createDB = function(name, driver, callback, schema) {
var params = { 'schema': schema };
if(driver == 'disk') params.dir = 'db';
this.databanks[name] = Databank.get(driver, params);
this.databanks[name].connect({}, function(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 {
callback(this.databanks[name]);
}

View File

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

View File

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