Skip to content

Instantly share code, notes, and snippets.

@june29
Last active August 29, 2015 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save june29/6408a9c8810da8b0d278 to your computer and use it in GitHub Desktop.
Save june29/6408a9c8810da8b0d278 to your computer and use it in GitHub Desktop.
Gem::Specification.new do |spec|
spec.name = "ruboty-horesase"
spec.version = "0.0.2"
spec.authors = ["Jun OHWADA"]
spec.email = ["june29.jp@gmail.com"]
spec.summary = "Random Horesase Meigen"
spec.files = ["ruboty-horesase.rb"]
spec.require_path = "."
end
require "json"
require "open-uri"
module Ruboty
module Handlers
class Horesase < Base
HORESASE_MEIGENS_URL = "http://horesase-boys.herokuapp.com/meigens.json"
on(
/horesase\s*(?<keyword>.*)/i,
name: "horesase",
description: "Random Horesase Meigen"
)
def horesase(message)
keyword = message[:keyword]
meigens = JSON.parse(open(HORESASE_MEIGENS_URL).read)
if keyword.length > 0
matched = meigens.select { |m|
m["title"].match(keyword) ||
m["character"].match(keyword) ||
m["body"].to_s.match(keyword)
}
meigen = matched.size > 0 ? matched.sample : meigens.sample
else
meigen = meigens.sample
end
message.reply(meigen["image"])
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment