├── Gemfile ├── lib └── ruboty │ ├── irasutoya │ └── version.rb │ └── irasutoya.rb └── ruboty-irasutoya.gemspec /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gemspec 4 | -------------------------------------------------------------------------------- /lib/ruboty/irasutoya/version.rb: -------------------------------------------------------------------------------- 1 | module Ruboty 2 | module Irasutoya 3 | VERSION = "1.0.2" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /ruboty-irasutoya.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path('../lib', __FILE__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | 4 | require 'ruboty/irasutoya/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "ruboty-irasutoya" 8 | spec.version = Ruboty::Irasutoya::VERSION 9 | spec.authors = ["Jun OHWADA"] 10 | spec.email = ["june29.jp@gmail.com"] 11 | 12 | spec.summary = %q{A Ruboty plugin for Irasutoya} 13 | spec.homepage = "https://github.com/june29/ruboty-irasutoya" 14 | 15 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 16 | spec.require_paths = ["lib"] 17 | 18 | spec.add_dependency "ruboty" 19 | spec.add_development_dependency "bundler", "~> 1.12" 20 | spec.add_development_dependency "rake", "~> 10.0" 21 | end 22 | -------------------------------------------------------------------------------- /lib/ruboty/irasutoya.rb: -------------------------------------------------------------------------------- 1 | require "open-uri" 2 | require "json" 3 | 4 | module Ruboty 5 | module Handlers 6 | class Irasutoya < Base 7 | JSON_URL = 'https://june29.github.io/irasutoya-data/irasutoya.json' 8 | 9 | on( 10 | /irasutoya ?(?.+)?/, 11 | name: 'irasutoya', 12 | description: 'Search irasuto' 13 | ) 14 | 15 | def irasutoya(message) 16 | query = Regexp.compile(message[:keyword]) 17 | 18 | data = JSON.parse(open(JSON_URL).read) 19 | 20 | selected = data.select { |irasuto| 21 | %w(title description image_alt).any? { |element| 22 | irasuto[element] =~ query 23 | } 24 | }.sample 25 | 26 | if selected 27 | message.reply(selected['image_url']) 28 | else 29 | message.reply('No result') 30 | end 31 | end 32 | end 33 | end 34 | end 35 | --------------------------------------------------------------------------------