├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── index.coffee ├── package.json ├── script ├── bootstrap └── test ├── src └── codinglove.coffee └── test └── codinglove_test.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "0.11" 4 | - "0.10" 5 | notifications: 6 | email: false 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 hubot-scripts 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hubot Codinglove script 2 | 3 | A little script to get meme from [the coding love](http://thecodinglove.com/) and [les joies du code](http://loesjoiesducode.tumblr.com), both the last and a random one. 4 | 5 | [![Build Status](https://travis-ci.org/eunomie/hubot-codinglove.png)](https://travis-ci.org/eunomie/hubot-codinglove) [![NPM version](https://badge.fury.io/js/hubot-codinglove.png)](http://badge.fury.io/js/hubot-codinglove) 6 | 7 | ## Usage 8 | 9 | Returns the comment and the gif in all cases. 10 | 11 | ### The coding love 12 | 13 | * `robot [give me some] joy [asshole]`: return a random 14 | * `robot [spread some] love`: return a random 15 | * `robot last joy`: return the last one 16 | * `robot last love`: return the last one 17 | 18 | ### Les joies du code [fr] 19 | 20 | * `robot [donne moi de la] joie [bordel]`: return a random 21 | * `robot {dernière|derniere} joie`: return the last one 22 | 23 | ## Dependencies 24 | 25 | * [cheerio](https://github.com/MatthewMueller/cheerio) 26 | * [he](https://github.com/mathiasbynens/he) 27 | 28 | ## Installation 29 | 30 | Add the package `hubot-codinglove` as a dependency in your Hubot `package.json` file. 31 | 32 | "dependencies": { 33 | "hubot-codinglove": "0.2.6" 34 | } 35 | 36 | Run the following command to make sure the module is installed. 37 | 38 | $ npm install hubot-codinglove 39 | 40 | To enable the script, add the `hubot-codinglove` entry to the `external-scripts.json` file (you may need to create this file). 41 | 42 | ["hubot-codinglove"] 43 | -------------------------------------------------------------------------------- /index.coffee: -------------------------------------------------------------------------------- 1 | fs = require 'fs' 2 | path = require 'path' 3 | 4 | module.exports = (robot, scripts) -> 5 | scriptsPath = path.resolve(__dirname, 'src') 6 | fs.exists scriptsPath, (exists) -> 7 | if exists 8 | for script in fs.readdirSync(scriptsPath) 9 | if scripts? and '*' not in scripts 10 | robot.loadFile(scriptsPath, script) if script in scripts 11 | else 12 | robot.loadFile(scriptsPath, script) 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hubot-codinglove", 3 | "description": "A script for Hubot to display meme from thecodinglove and lesjoiesducode.", 4 | "version": "0.2.6", 5 | "author": "Yves Brissaud " 3 | # or "les joies du code ". 4 | # 5 | # Dependencies: 6 | # "cheerio": "0.7.0" 7 | # "he": "0.4.1" 8 | # 9 | # Configuration: 10 | # None 11 | # 12 | # Commands: 13 | # hubot [give me some] joy [asshole] - Return a random meme (coding love) 14 | # hubot last joy - Returns last meme (coding love) 15 | # hubot [spread some] love - Return a random meme (coding love) 16 | # hubot last love - Returns last meme (coding love) 17 | # hubot [donne moi de la] joie [bordel] - Returns a random meme (text and image) 18 | # hubot {dernière|derniere} joie - Returns last meme (text and image). 19 | # 20 | # Author: 21 | # Eunomie 22 | # Based 9gag.coffee by EnriqueVidal 23 | 24 | cheerio = require('cheerio') 25 | he = require('he') 26 | 27 | module.exports = (robot)-> 28 | robot.respond /(donne moi de la )?joie( bordel)?/i, (message)-> 29 | send_new_meme message, 'http://lesjoiesducode.fr/random', (text)-> 30 | message.send text 31 | robot.respond /derni[èe]re joie/i, (message)-> 32 | send_new_meme message, 'http://lesjoiesducode.fr', (text)-> 33 | message.send text 34 | robot.respond /((give me|spread) some )?(joy|love)( asshole)?/i, (message)-> 35 | send_meme message, 'http://thecodinglove.com/random', (text)-> 36 | message.send text 37 | robot.respond /last (joy|love)/i, (message)-> 38 | send_meme message, 'http://thecodinglove.com', (text)-> 39 | message.send text 40 | 41 | send_new_meme = (message, location, response_handler)-> 42 | url = location 43 | 44 | message.http(url).get() (error, response, body)-> 45 | return response_handler "Sorry, something went wrong" if error 46 | 47 | if response.statusCode == 302 || response.statusCode == 301 48 | location = response.headers['location'] 49 | return send_new_meme(message, location, response_handler) 50 | 51 | img_src = get_meme_image(body, ".ljdc-posts .blog-post .blog-post-content img") 52 | 53 | txt = get_meme_txt(body, ".ljdc-posts .blog-post h1.blog-post-title a") 54 | if txt == '' 55 | txt = get_meme_txt(body, ".ljdc-posts .blog-post h1.blog-post-title") 56 | 57 | txt = txt.replace(/[\n\r]/g, '') 58 | 59 | response_handler "#{txt}" 60 | response_handler "#{img_src}" 61 | 62 | send_meme = (message, location, response_handler)-> 63 | url = location 64 | 65 | message.http(url).get() (error, response, body)-> 66 | return response_handler "Sorry, something went wrong" if error 67 | 68 | if response.statusCode == 302 || response.statusCode == 301 69 | location = response.headers['location'] 70 | return send_meme(message, location, response_handler) 71 | 72 | img_src = get_meme_image(body, ".post img") 73 | 74 | txt = get_meme_txt(body, ".post h3") 75 | 76 | response_handler "#{txt}" 77 | response_handler "#{img_src}" 78 | 79 | get_meme_image = (body, selector)-> 80 | $ = cheerio.load(body) 81 | $(selector).first().attr('src').replace(/\.jpe?g/i, '.gif') 82 | 83 | get_meme_txt = (body, selector)-> 84 | $ = cheerio.load(body) 85 | he.decode $(selector).first().text() 86 | -------------------------------------------------------------------------------- /test/codinglove_test.coffee: -------------------------------------------------------------------------------- 1 | chai = require 'chai' 2 | sinon = require 'sinon' 3 | chai.use require 'sinon-chai' 4 | 5 | expect = chai.expect 6 | 7 | describe 'codinglove', -> 8 | beforeEach -> 9 | @robot = 10 | respond: sinon.spy() 11 | 12 | require('../src/codinglove')(@robot) 13 | 14 | it 'registers respond listeners', -> 15 | expect(@robot.respond.args[0][0].toString()).to.equal("/(donne moi de la )?joie( bordel)?/i") 16 | expect(@robot.respond.args[1][0].toString()).to.equal("/derni[èe]re joie/i") 17 | expect(@robot.respond.args[4][0].toString()).to.equal("/((give me|spread) some )?(joy|love)( asshole)?/i") 18 | expect(@robot.respond.args[3][0].toString()).to.equal("/last (joy|love)/i") 19 | --------------------------------------------------------------------------------