forked from GitHub/dbot
provisional poll thing. only commiting so i can switch branch w/e [#272]
This commit is contained in:
parent
b288487f23
commit
07f8a129d5
@ -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]);
|
||||
}
|
||||
|
@ -7,30 +7,33 @@ var commands = function(dbot) {
|
||||
var name = event.input[1].toLowerCase(),
|
||||
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,
|
||||
'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;
|
||||
|
||||
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,
|
||||
'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 }));
|
||||
}
|
||||
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
|
||||
})
|
||||
}));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
'~addoption': function(event) {
|
||||
|
@ -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" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user