forked from GitHub/dbot
Merge github.com:reality/depressionbot into database
This commit is contained in:
commit
4e53a06e75
@ -7,6 +7,25 @@ Various imgur functionality.
|
||||
Posts information on imgur links which are pasted into the channel and provides
|
||||
functionality to generate a random imgur link.
|
||||
|
||||
### Config
|
||||
|
||||
#### imagelength: 5
|
||||
Length of slugs generated by the random imgur functionality.
|
||||
|
||||
#### nsfwwarn: true
|
||||
Warn that images generated by the ~ri command may be NSFW.
|
||||
|
||||
#### apikey
|
||||
Key to use with the imgur API.
|
||||
|
||||
#### highscore: ricount
|
||||
Quote category to use for a 'highscore;' used to run games with the web
|
||||
/random page, by storing a highscore based on some arbitrary rule in the
|
||||
chosen quote category (say, how far can you get before seeing a turtle). Then,
|
||||
on the imgur random page you can press 'c' to see a countdown towards the last
|
||||
stored value in the highscore quote category. If you beat the highscore, simply
|
||||
add the winning score to the quote category.
|
||||
|
||||
### Commands
|
||||
|
||||
#### ~ri
|
||||
@ -28,6 +47,18 @@ imgur API. Callback is called with one argument, the info string.
|
||||
Return data from the imgur API on an image with the given slug. Callback is
|
||||
called with one argument, the information returned by the API.
|
||||
|
||||
### Web
|
||||
|
||||
#### /imgur/random
|
||||
|
||||
A web page which loads a random image from imgur. You can press the space bar to
|
||||
load a new image, and information about the images are shown on the top-left of
|
||||
the page. You can press 'c' to view a highscore count (as documented above).
|
||||
|
||||
#### /imgur/stats
|
||||
|
||||
Show statistics on the total use of the imgur module.
|
||||
|
||||
### Hooks
|
||||
|
||||
#### link
|
||||
|
@ -11,7 +11,17 @@ var link = function(dbot) {
|
||||
this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
|
||||
this.links = {};
|
||||
this.handlers = [];
|
||||
this.fetchTitle = function(event, link) {
|
||||
|
||||
this.api = {
|
||||
'addHandler': function(name, regex, handler) {
|
||||
this.handlers.push({
|
||||
'name': name,
|
||||
'regex': regex,
|
||||
'callback': handler
|
||||
});
|
||||
},
|
||||
|
||||
'getTitle': function(link, callback) {
|
||||
var limit = 1000000,
|
||||
size = 0,
|
||||
page = request(link.replace('https', 'http'), function(error, response, body) {
|
||||
@ -19,7 +29,7 @@ var link = function(dbot) {
|
||||
body = body.replace(/(\r\n|\n\r|\n)/gm, " ");
|
||||
var title = body.valMatch(/<title>(.*)<\/title>/, 2);
|
||||
if(title && title.length < 140) {
|
||||
event.reply(ent.decode(title[1]).trim());
|
||||
callback(ent.decode(title[1]).trim());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -30,15 +40,6 @@ var link = function(dbot) {
|
||||
page.abort();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.api = {
|
||||
'addHandler': function(name, regex, handler) {
|
||||
this.handlers.push({
|
||||
'name': name,
|
||||
'regex': regex,
|
||||
'callback': handler
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@ -51,7 +52,9 @@ var link = function(dbot) {
|
||||
link = urlMatches[0];
|
||||
}
|
||||
}
|
||||
this.fetchTitle(event, link);
|
||||
this.fetchTitle(link, function(title) {
|
||||
event.reply(title);
|
||||
});
|
||||
},
|
||||
|
||||
'~xkcd': function(event) {
|
||||
@ -119,7 +122,11 @@ var link = function(dbot) {
|
||||
handlerFound = true; break;
|
||||
}
|
||||
}
|
||||
if(!handlerFound) this.fetchTitle(event, urlMatches[0]);
|
||||
if(!handlerFound) {
|
||||
this.fetchTitle(urlMatches[0], function(title) {
|
||||
event.reply(title);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}.bind(this);
|
||||
|
@ -13,6 +13,8 @@ var spotify = function(dbot) {
|
||||
this.spotifyRegex = /(\b(https?:\/\/open.spotify.com\/(artist|track|album)\/\w*|spotify:(artist|track|album):\w*)\b)/ig;
|
||||
this.spotifyLookup = 'http://ws.spotify.com/lookup/1/.json';
|
||||
this.spotifySearch = 'http://ws.spotify.com/search/1/track.json';
|
||||
this.youtubeRegex = /^http:\/\/(?:www\.)?youtube.com\/watch\?v=\w+(&\S*)?$/
|
||||
this.spotifyText = "\u00039spotify\u000f";
|
||||
|
||||
this.lookup = function(event, link) {
|
||||
request({
|
||||
@ -35,28 +37,75 @@ var spotify = function(dbot) {
|
||||
});
|
||||
};
|
||||
|
||||
var commands = {
|
||||
'~spotify': function(event) {
|
||||
var query = event.input[1];
|
||||
this.api = {
|
||||
'spotifySearch': function(query, callback) {
|
||||
request({
|
||||
url: this.spotifySearch,
|
||||
qs: {q: query},
|
||||
json: true
|
||||
}, function(error, response, body) {
|
||||
if (!error && response.statusCode == 200) {
|
||||
var spotify = "\u00039spotify\u000f";
|
||||
if (_.has(body, 'tracks') && body.tracks[0] && _.has(body.tracks[0], 'href')) {
|
||||
var t = body.tracks[0].href;
|
||||
t = t.replace(/:/g, '/');
|
||||
t = t.replace(/spotify/, 'http://open.spotify.com');
|
||||
event.reply(dbot.t("found", {s: spotify, artist: _.map(body.tracks[0].artists, function(a) { return a.name }).join(', '), album: body.tracks[0].album.name, track: body.tracks[0].name, url: t}));
|
||||
callback(body, t);
|
||||
} else {
|
||||
event.reply(dbot.t("not-found", {s: spotify}));
|
||||
callback(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var commands = {
|
||||
'~spotify': function(event) {
|
||||
var query = event.input[1];
|
||||
this.api.spotifySearch(query, function(body, t) {
|
||||
if(body) {
|
||||
event.reply(dbot.t("found", {
|
||||
s: this.spotifyText,
|
||||
artist: _.map(body.tracks[0].artists, function(a) {
|
||||
return a.name }).join(', '),
|
||||
album: body.tracks[0].album.name,
|
||||
track: body.tracks[0].name,
|
||||
url: t
|
||||
}));
|
||||
} else {
|
||||
event.reply(dbot.t("not-found", {s: spotify}));
|
||||
}
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
'~syt': function(event) {
|
||||
var lastLink = dbot.modules.link.links[event.channel.name];
|
||||
if(!_.isUndefined(event.params[1])) {
|
||||
lastLink = event.params[1];
|
||||
}
|
||||
|
||||
if(lastLink.match(this.youtubeRegex)) {
|
||||
dbot.api.link.getTitle(lastLink, function(title) {
|
||||
name = title.replace(' - YouTube', '');
|
||||
this.api.spotifySearch(name, function(body, t) {
|
||||
if(body) {
|
||||
event.reply(dbot.t("found", {
|
||||
s: this.spotifyText,
|
||||
artist: _.map(body.tracks[0].artists, function(a) {
|
||||
return a.name }).join(', '),
|
||||
album: body.tracks[0].album.name,
|
||||
track: body.tracks[0].name,
|
||||
url: t
|
||||
}));
|
||||
} else {
|
||||
event.reply('No results');
|
||||
}
|
||||
}.bind(this));
|
||||
}.bind(this));
|
||||
} else {
|
||||
event.reply("That's not a YouTube link");
|
||||
}
|
||||
}
|
||||
};
|
||||
commands['~spotify'].regex = [/^~spotify (.*)/, 2];
|
||||
this.commands = commands;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user