From 4ae10a2b26523fe313b517d1bc7c4131cd9e9ee1 Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 25 Jul 2013 21:56:44 +0000 Subject: [PATCH] link handlers callback result instead of event.reply it[Close #536] --- modules/dent/dent.js | 8 +++---- modules/imgur/imgur.js | 4 ++-- modules/link/link.js | 37 +++++++++++++++++++++----------- modules/reddit/reddit.js | 8 +++---- modules/soundcloud/soundcloud.js | 4 ++-- modules/spotify/spotify.js | 12 +++++------ modules/youtube/youtube.js | 4 ++-- 7 files changed, 44 insertions(+), 33 deletions(-) diff --git a/modules/dent/dent.js b/modules/dent/dent.js index 9b03b45..2935edc 100644 --- a/modules/dent/dent.js +++ b/modules/dent/dent.js @@ -33,7 +33,7 @@ var dent = function(dbot) { } }; - this.lookup = function(event, id, service) { + this.lookup = function(id, service, callback) { request({ url: this.StatusAPI[service], qs: {"id": id}, @@ -41,7 +41,7 @@ var dent = function(dbot) { }, function(error, response, body) { if (!error && response.statusCode == 200) { if (_.has(body, 'text')) { - event.reply(service + " [" + body.user.screen_name + '] ' + body.text); + callback(service + " [" + body.user.screen_name + '] ' + body.text); } } }); @@ -65,8 +65,8 @@ var dent = function(dbot) { } for(s in this.StatusRegex) { - dbot.api.link.addHandler(s, this.StatusRegex[s], function(event, matches, name) { - this.lookup(event, matches[1], name); + dbot.api.link.addHandler(s, this.StatusRegex[s], function(matches, name, callback) { + this.lookup(matches[1], name, callback); }.bind(this)); } }.bind(this); diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index 0482748..f7e7854 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -163,7 +163,7 @@ var imgur = function(dbot) { } this.onLoad = function() { - var imgurHandler = function(event, matches, name) { + var imgurHandler = function(matches, name, callback) { if(matches[1]) { var dataCallback = function(data) { var info; @@ -175,7 +175,7 @@ var imgur = function(dbot) { info = this.internalAPI.galleryInfoString(data); } - if(info) event.reply(dbot.t('imgurinfo', { 'info': info })); + if(info) callback(dbot.t('imgurinfo', { 'info': info })); }.bind(this); if(name == 'imgurimage') { diff --git a/modules/link/link.js b/modules/link/link.js index 4d27ef9..2d346a0 100644 --- a/modules/link/link.js +++ b/modules/link/link.js @@ -57,6 +57,27 @@ var link = function(dbot) { } catch(err) { callback(false); } }); + }, + + 'parseLink': function(link, callback) { + var handler = false; + for(var i=0;i