mirror of
				https://github.com/reality/dbot.git
				synced 2025-10-31 03:07:38 +01:00 
			
		
		
		
	Merge branch 'betterusers' of https://github.com/reality/depressionbot into betterusers
This commit is contained in:
		
						commit
						80cd9ab9d6
					
				
							
								
								
									
										5
									
								
								modules/leafly/config.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								modules/leafly/config.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| { | ||||
|     "outputPrefix": "\u00033weed\u000f", | ||||
|     "app_key": "", | ||||
|     "app_id": "" | ||||
| } | ||||
							
								
								
									
										47
									
								
								modules/leafly/leafly.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								modules/leafly/leafly.js
									
									
									
									
									
										Normal file
									
								
							| @ -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); | ||||
| }; | ||||
							
								
								
									
										8
									
								
								modules/leafly/strings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								modules/leafly/strings.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,8 @@ | ||||
| { | ||||
|     "strain": { | ||||
|         "en": "{name} tastes of {flavours} - {link}" | ||||
|     }, | ||||
|     "no_strains": { | ||||
|         "en": "No strains found :(" | ||||
|     } | ||||
| } | ||||
| @ -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) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Luke Slater
						Luke Slater