From fb3ddf2da8fd5bff23dec08474746f002de3ac42 Mon Sep 17 00:00:00 2001 From: Luke Slater Date: Sun, 28 Sep 2014 18:48:36 +0100 Subject: [PATCH 1/2] Update commands.js --- modules/quotes/commands.js | 51 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/modules/quotes/commands.js b/modules/quotes/commands.js index 3821a82..8448ba2 100644 --- a/modules/quotes/commands.js +++ b/modules/quotes/commands.js @@ -14,11 +14,18 @@ var commands = function(dbot) { this.api.addQuote(key, quote, event.user, function(newCount) { if(newCount) { dbot.api.event.emit('~qadd', [ key, quote ]); - event.reply(dbot.t('quote_saved', { - 'category': key, - 'count': newCount, - 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) - })); + if(_.has(dbot.modules, 'web')) { + event.reply(dbot.t('quote_saved', { + 'category': key, + 'count': newCount, + 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) + })); + } else { + event.reply(dbot.t('quote_saved', { + 'category': key, + 'count': newCount + })); + } } else { event.reply(dbot.t('quote_exists')); } @@ -103,11 +110,18 @@ var commands = function(dbot) { removedQuote; var quoteRemoved = function(err) { this.internalAPI.resetRemoveTimer(event, key, removedQuote); - event.reply(dbot.t('removed_from', { - 'quote': removedQuote, - 'category': key, - 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) - })); + if(_.has(dbot.modules, 'web')) { + event.reply(dbot.t('removed_from', { + 'quote': removedQuote, + 'category': key, + 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) + })); + } else { + event.reply(dbot.t('removed_from', { + 'quote': removedQuote, + 'category': key + })); + } }.bind(this); this.db.search('quote_category', { 'name': key }, function(result) { @@ -137,11 +151,18 @@ var commands = function(dbot) { category = false; var quoteRemoved = function(err) { this.internalAPI.resetRemoveTimer(event, key, quote); - event.reply(dbot.t('removed_from', { - 'category': key, - 'quote': quote, - 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) - })); + if(_.has(dbot.modules, 'web')) { + event.reply(dbot.t('removed_from', { + 'category': key, + 'quote': quote, + 'link': dbot.api.web.getUrl('quotes/' + encodeURIComponent(key)) + })); + } else { + event.reply(dbot.t('removed_from', { + 'category': key, + 'quote': quote + })); + } }.bind(this); this.db.search('quote_category', { 'name': key }, function(result) { From 6d8224bdf12240160a40f64e767dff7b4afe5799 Mon Sep 17 00:00:00 2001 From: reality Date: Wed, 1 Oct 2014 00:28:32 +0000 Subject: [PATCH 2/2] leafly --- modules/leafly/config.json | 5 ++++ modules/leafly/leafly.js | 47 +++++++++++++++++++++++++++++++++++++ modules/leafly/strings.json | 8 +++++++ 3 files changed, 60 insertions(+) create mode 100644 modules/leafly/config.json create mode 100644 modules/leafly/leafly.js create mode 100644 modules/leafly/strings.json diff --git a/modules/leafly/config.json b/modules/leafly/config.json new file mode 100644 index 0000000..8cbabb5 --- /dev/null +++ b/modules/leafly/config.json @@ -0,0 +1,5 @@ +{ + "outputPrefix": "\u00033weed\u000f", + "app_key": "", + "app_id": "" +} diff --git a/modules/leafly/leafly.js b/modules/leafly/leafly.js new file mode 100644 index 0000000..22c4929 --- /dev/null +++ b/modules/leafly/leafly.js @@ -0,0 +1,47 @@ +/** + * Module name: Leafly + * Description: Information from leafly + */ + +var _ = require('underscore')._, + request = require('request'); + +var leafly = function(dbot) { + var ApiRoot = 'http://data.leafly.com/'; + + this.commands = { + '~strain': function(event) { + request.post(ApiRoot + 'strains', { + 'headers': { + 'app_key': this.config.app_key, + 'app_id': this.config.app_id + }, + 'body': { + 'page': 0, + 'take': 1, + 'sort': 'rating', + 'search': event.input[1] + }, + 'json': true + }, function(error, response, body) { + if(_.isObject(body) && _.has(body, 'Strains') && body.Strains.length > 0) { + var strain = body.Strains[0], + flavours = _.pluck(strain.Flavors, 'Name').join(', '); + + event.reply(dbot.t('strain', { + 'name': strain.Name, + 'flavours': flavours, + 'link': strain.permalink + })); + } else { + event.reply(dbot.t('no_strains')); + } + }.bind(this)); + } + }; + this.commands['~strain'].regex = [/^strain (.+)$/, 2]; +}; + +exports.fetch = function(dbot) { + return new leafly(dbot); +}; diff --git a/modules/leafly/strings.json b/modules/leafly/strings.json new file mode 100644 index 0000000..9494b80 --- /dev/null +++ b/modules/leafly/strings.json @@ -0,0 +1,8 @@ +{ + "strain": { + "en": "{name} tastes of {flavours} - {link}" + }, + "no_strains": { + "en": "No strains found :(" + } +}