Last active
August 29, 2015 14:14
-
-
Save kakajika/08efafb64427cda8ce13 to your computer and use it in GitHub Desktop.
SlackにLINEスタンプを検索&投稿するHubotスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# linestamp.coffee | |
# | |
# Description: | |
# Search & post LINE stamps for Hubot. | |
# | |
# Commands: | |
# hubot stamp | |
client = require 'cheerio-httpcli' | |
class StampSearcher | |
urlBase = 'http://www.stampick.com/?s=' | |
constructor: -> | |
search: (query, callback) -> | |
url = "#{urlBase}#{query}" | |
console.log url | |
client.fetch url, (err, $, res) -> | |
if err | |
return console.log(err) | |
stampUrls = Array() | |
stampBoxes = $('.stampBox').each -> | |
stampUrls.push $(@).find('img').attr('data-original') | |
callback(stampUrls) | |
module.exports = (robot) -> | |
robot.respond /stamp (.+)/i, (msg) -> | |
query = msg.match[1] | |
new StampSearcher().search query, (results) -> | |
if results && results.length > 0 | |
index = Math.floor(Math.random() * results.length) | |
url = results[index] | |
msg.send "スタンプ「#{query}」No.#{index+1}\n#{url}" | |
else | |
msg.send "スタンプ「#{query}」 見つからないな…" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment