Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# -*- 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