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,29 +8,32 @@ 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,
'description': description,
'owner': dbot.api.users.resolveUser(event.server, event.user),
'votes': {},
'votees': {}
};
for(var i=0;i<options.length;i++) {
polls[name]['votes'][options[i]] = 0;
}
event.reply(dbot.t('poll_created', {
'name': name,
'description': description,
'url': dbot.t('url', {
'host': dbot.config.web.webHost,
'port': dbot.config.web.webPort,
'path': 'polls/' + name
})
}));
} }
this.db.create(poll, name, {
'description': description,
'owner': dbot.api.users.resolveUser(event.server, event.user),
'votes': votes,
'votees': {}
},
function(err, value) {
if(!err) {
event.reply(dbot.t('poll_created', {
'name': name,
'description': description,
'url': dbot.t('url', {
'host': dbot.config.web.webHost,
'port': dbot.config.web.webPort,
'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" ]
}
}
} }