3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-18 08:32:42 +01:00
dbot/modules/dent/dent.js
reality 921da917a4 Command hooks [#86]
* Command API function to addHook(command, callback)
* Commands open to callbacks must return information or indicate failed completion by return false
* Hooks to be added in module onLoad
* Command loop checks for available hooks and return state, then applies with module scope.
* onLoad running moved to end of all module loading to facilitate this without order problems
* Added example for ~qadd dent
2013-01-15 17:23:14 +00:00

46 lines
1.2 KiB
JavaScript

var request = require('request');
_ = require('underscore')._;
var dent = function(dbot) {
this.dbot = dbot;
this.api = {
'post': function(content) {
var username = dbot.config.dent.username,
password = dbot.config.dent.password,
info,
auth = "Basic " +
new Buffer(username + ":" + password).toString("base64");
request.post({
'url': 'http://identi.ca/api/statuses/update.json?status=' +
content,
'headers': {
'Authorization': auth
}
},
function(error, response, body) {
console.log(body);
}.bind(this));
}
};
this.commands = {
'~dent': function(event) {
this.api.post(event.input[1]);
event.reply('Dent posted (probably).');
}
};
this.commands['~dent'].regex = [/^~dent (.+)$/, 2];
this.onLoad = function() {
dbot.api.command.addHook('~qadd', function(key, text) {
this.api.post(key + ': ' + text);
}.bind(this));
}.bind(this);
};
exports.fetch = function(dbot) {
return new dent(dbot);
};