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'),
|
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]);
|
||||||
}
|
}
|
||||||
|
@ -7,30 +7,33 @@ var commands = function(dbot) {
|
|||||||
var name = event.input[1].toLowerCase(),
|
var name = event.input[1].toLowerCase(),
|
||||||
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,
|
this.db.create(poll, name, {
|
||||||
'owner': dbot.api.users.resolveUser(event.server, event.user),
|
'description': description,
|
||||||
'votes': {},
|
'owner': dbot.api.users.resolveUser(event.server, event.user),
|
||||||
'votees': {}
|
'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,
|
||||||
|
'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) {
|
'~addoption': function(event) {
|
||||||
|
@ -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" ]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user