From e3074d8054af0a37e267774b7e1c8bdd57937671 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 01:37:28 +0000 Subject: [PATCH 1/2] implement xkcd functionality The strings.json file is extensible; other fields that can be placed in the xkcd string include the {year}, {month} and {day} of the comic; the {alt} text; and links to the {img}. A {transcript} is also available. --- modules/link/link.js | 18 ++++++++++++++++++ modules/link/strings.json | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/modules/link/link.js b/modules/link/link.js index dfe5f70..201d364 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -32,6 +32,24 @@ var link = function(dbot) { } this.fetchTitle(event, link); }, + + '~xkcd': function(event) { + var comicId = event.params[1]; + if(comicId){ + comicId = comicId + "/"; + } else { + comicId = ""; + } + var link = "http://xkcd.com/"+comicId+"info.0.json"; + request(link, function(error, response, body) { + if (response.statusCode == "200") { + data = JSON.parse(body); + event.reply(dbot.t("xkcd",data)); + } else { + event.reply(dbot.t("no-hits")); + } + }); + }, '~ud': function(event) { var query = event.input[1]; diff --git a/modules/link/strings.json b/modules/link/strings.json index 2709f1d..935e635 100644 --- a/modules/link/strings.json +++ b/modules/link/strings.json @@ -2,5 +2,11 @@ "title_not_found": { "english": "No page title found.", "na'vi": "Oel ke tsun run 'upxare atxin." + }, + "xkcd": { + "english": "xkcd {num}: {title} https://xkcd.com/{num}" + }, + "no-hits": { + "english": "No hits." } } From 4f24e6db4a6398b2227c6ad5410a97f141c69089 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Wed, 30 Jan 2013 01:39:50 +0000 Subject: [PATCH 2/2] update documentation --- modules/link/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/link/README.md b/modules/link/README.md index 24c52d0..21de8ef 100644 --- a/modules/link/README.md +++ b/modules/link/README.md @@ -21,3 +21,5 @@ page. If called without a link, the bot will attempt the same on the last link which was posted in the current channel. #### ~ud [headword] Returns the first [Urban Dictionary](http://www.urbandictionary.com) definition for the headword provided. +#### ~xkcd +Returns a link to the [xkcd](http://xkcd.com) comic specified, or the latest one if a comic is not given.