3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-26 04:32:37 +01:00

Merge pull request #304 from tmenari/master

Add entity decoding to link.js <title>
This commit is contained in:
reality 2013-03-11 06:53:24 -07:00
commit a3cd2bc3ea
2 changed files with 6 additions and 2 deletions

View File

@ -23,3 +23,6 @@ which was posted in the current channel.
Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided. Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided.
#### ~xkcd <comic ID> #### ~xkcd <comic ID>
Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given. Use '*' to return a link to a random comic. Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given. Use '*' to return a link to a random comic.
### Requirements
* [node-ent](https://github.com/substack/node-ent)

View File

@ -4,7 +4,8 @@
* information about links. * information about links.
*/ */
var request = require('request'), var request = require('request'),
_ = require('underscore')._; _ = require('underscore')._,
ent = require('ent');
var link = function(dbot) { var link = function(dbot) {
this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; this.urlRegex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
@ -15,7 +16,7 @@ var link = function(dbot) {
body = body.replace(/(\r\n|\n\r|\n)/gm, " "); body = body.replace(/(\r\n|\n\r|\n)/gm, " ");
var title = body.valMatch(/<title>(.*)<\/title>/, 2); var title = body.valMatch(/<title>(.*)<\/title>/, 2);
if(title && title.length < 140) { if(title && title.length < 140) {
event.reply(title[1]); event.reply(ent.decode(title[1]));
} }
} }
}); });