mirror of
https://github.com/reality/dbot.git
synced 2025-02-02 15:44:33 +01:00
Basic Reddit module which posts info about Reddit links posted in the channel [#293]
This commit is contained in:
parent
8151122b80
commit
a881e60c81
46
modules/reddit/reddit.js
Normal file
46
modules/reddit/reddit.js
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Module Name: reddit
|
||||||
|
* Description: Various reddit functionality
|
||||||
|
*/
|
||||||
|
var _ = require('underscore')._,
|
||||||
|
request = require('request');
|
||||||
|
|
||||||
|
var reddit = function(dbot) {
|
||||||
|
this.ApiRoot = 'http://reddit.com/';
|
||||||
|
|
||||||
|
this.api = {
|
||||||
|
'getSubredditInfo': function(name, callback) {
|
||||||
|
request.get({
|
||||||
|
'url': this.ApiRoot + 'r/' + name + '/about.json',
|
||||||
|
'json': true,
|
||||||
|
'headers': {
|
||||||
|
'User-Agent': 'dbot by u/realitone'
|
||||||
|
}
|
||||||
|
}, function(err, response, body) {
|
||||||
|
callback(body);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.onLoad = function() {
|
||||||
|
var srHandler = function(event, matches, name) {
|
||||||
|
this.api.getSubredditInfo(matches[1], function(info) {
|
||||||
|
if(info.data) {
|
||||||
|
info = info.data;
|
||||||
|
var infoString = dbot.t('about_subreddit', {
|
||||||
|
'display_name': info.display_name,
|
||||||
|
'subscribers': info.subscribers,
|
||||||
|
'active': info.accounts_active
|
||||||
|
});
|
||||||
|
if(info.over18) infoString += ' [NSFW]';
|
||||||
|
event.reply(infoString);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}.bind(this);
|
||||||
|
dbot.api.link.addHandler(this.name, /https?:\/\/reddit\.com\/r\/([a-zA-Z0-9]+)/, srHandler);
|
||||||
|
}.bind(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.fetch = function(dbot) {
|
||||||
|
return new reddit(dbot);
|
||||||
|
}
|
5
modules/reddit/strings.json
Normal file
5
modules/reddit/strings.json
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"about_subreddit": {
|
||||||
|
"en": "[{display_name} has {subscribers} subscribers ({active} active)]"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user