2013-01-10 18:44:01 +01:00
|
|
|
var request = require('request');
|
2013-01-14 14:10:16 +01:00
|
|
|
_ = require('underscore')._;
|
2013-01-10 18:44:01 +01:00
|
|
|
|
|
|
|
var dent = function(dbot) {
|
2013-03-11 20:30:00 +01:00
|
|
|
this.StatusRegex = {
|
|
|
|
identica: /\bhttps?:\/\/identi\.ca\/notice\/(\d+)\b/ig,
|
|
|
|
twitter: /\bhttps?:\/\/twitter\.com\/\w+\/status\/(\d+)\b/ig
|
|
|
|
};
|
|
|
|
|
|
|
|
this.StatusAPI = {
|
|
|
|
identica: "http://identi.ca/api/statuses/show.json",
|
|
|
|
twitter: "https://api.twitter.com/1/statuses/show.json"
|
|
|
|
};
|
2013-01-14 18:45:53 +01:00
|
|
|
|
|
|
|
this.api = {
|
2013-01-14 14:10:16 +01:00
|
|
|
'post': function(content) {
|
2013-06-04 01:00:23 +02:00
|
|
|
var username = this.config.username,
|
|
|
|
password = this.config.password,
|
2013-01-14 14:10:16 +01:00
|
|
|
info,
|
2013-01-30 23:13:08 +01:00
|
|
|
auth = "Basic " +
|
2013-01-10 18:44:01 +01:00
|
|
|
new Buffer(username + ":" + password).toString("base64");
|
2013-01-14 14:10:16 +01:00
|
|
|
|
2013-01-10 18:44:01 +01:00
|
|
|
request.post({
|
2013-10-30 18:13:36 +01:00
|
|
|
'url': this.config.api + '/statuses/update.json?status=' +
|
2013-01-30 23:13:08 +01:00
|
|
|
escape(content),
|
2013-01-10 18:44:01 +01:00
|
|
|
'headers': {
|
|
|
|
'Authorization': auth
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function(error, response, body) {
|
2013-01-14 14:10:16 +01:00
|
|
|
console.log(body);
|
|
|
|
}.bind(this));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-25 23:56:44 +02:00
|
|
|
this.lookup = function(id, service, callback) {
|
2013-03-11 20:30:00 +01:00
|
|
|
request({
|
|
|
|
url: this.StatusAPI[service],
|
|
|
|
qs: {"id": id},
|
|
|
|
json: true
|
|
|
|
}, function(error, response, body) {
|
|
|
|
if (!error && response.statusCode == 200) {
|
|
|
|
if (_.has(body, 'text')) {
|
2013-07-25 23:56:44 +02:00
|
|
|
callback(service + " [" + body.user.screen_name + '] ' + body.text);
|
2013-03-11 20:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-01-14 18:45:53 +01:00
|
|
|
this.commands = {
|
2013-01-14 14:10:16 +01:00
|
|
|
'~dent': function(event) {
|
2013-01-14 18:45:53 +01:00
|
|
|
this.api.post(event.input[1]);
|
2013-01-14 14:10:16 +01:00
|
|
|
event.reply('Dent posted (probably).');
|
2013-01-10 18:44:01 +01:00
|
|
|
}
|
|
|
|
};
|
2013-12-29 19:38:24 +01:00
|
|
|
this.commands['~dent'].regex = [/^dent (.+)$/, 2];
|
2013-01-15 18:23:14 +01:00
|
|
|
|
|
|
|
this.onLoad = function() {
|
2013-06-04 01:00:23 +02:00
|
|
|
if(this.config.dentQuotes === true && _.has(dbot.modules, 'quotes')) {
|
2013-12-29 19:38:24 +01:00
|
|
|
dbot.api.event.addHook('qadd', function(key, text) {
|
2013-04-09 01:51:28 +02:00
|
|
|
if(text.indexOf('~~') == -1) {
|
|
|
|
this.api.post(key + ': ' + text);
|
|
|
|
}
|
2013-01-21 20:07:25 +01:00
|
|
|
}.bind(this));
|
2013-01-20 17:35:17 +01:00
|
|
|
}
|
2013-04-12 21:03:01 +02:00
|
|
|
|
|
|
|
for(s in this.StatusRegex) {
|
2013-07-25 23:56:44 +02:00
|
|
|
dbot.api.link.addHandler(s, this.StatusRegex[s], function(matches, name, callback) {
|
|
|
|
this.lookup(matches[1], name, callback);
|
2013-04-12 21:03:01 +02:00
|
|
|
}.bind(this));
|
2013-03-11 20:30:00 +01:00
|
|
|
}
|
|
|
|
}.bind(this);
|
2013-01-10 18:44:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.fetch = function(dbot) {
|
2013-01-14 18:45:53 +01:00
|
|
|
return new dent(dbot);
|
2013-01-10 18:44:01 +01:00
|
|
|
};
|