Skip to content

Instantly share code, notes, and snippets.

@siyo
Created January 10, 2014 17:08
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 siyo/8358260 to your computer and use it in GitHub Desktop.
Save siyo/8358260 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# Auto haiku
haikus ||= [];
Earthquake.init do
output_filter do |item|
next if item.nil? || item["text"].nil? || item["retweeted_status"]
id = item["id"]
screen_name = item["user"] ? item["user"]["screen_name"] : nil
myname = twitter.info["screen_name"]
next if screen_name.nil? || screen_name == myname
text = item["text"]
if text =~ /ここで一句/i
begin
haiku = open("http://haiku.jgate.de/"){|f| f.read}
rescue => e
p e
return true
end
case text
when /^@#{myname}\s+/i
henjis = ['了解しました','はい']
twitter.update( "@%s %s ここで一句、 %s" % [screen_name, henjis.sample, haiku],
:in_reply_to_status_id =>id)
when /^\s*[^@]/
haikus << ("ここで一句、 " + haiku)
if haikus.length > (rand(5) + 1)
EM.run do
EM.add_timer(5 + rand(60)){
twitter.update haikus.sample
haikus = [];
}
end
end
end
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment