Last active
December 12, 2015 08:28
-
-
Save siyo/4743921 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
# okiro plugin | |
# | |
# event registration from tweet | |
# $ 20:00まで寝る | |
# $ 20:00に起きる | |
# $ 20:00に起こして | |
# | |
require 'time' | |
Earthquake.init do | |
output_filter do |item| | |
next unless item["user"] && item["text"] | |
words = [ "まで寝る", | |
"までねる", | |
"おきる", | |
"起きる", | |
"おこして", | |
"起こして" ] | |
account = item["user"]["screen_name"] | |
id = item["id"] | |
txt = item["text"] | |
if /(#{words.join('|')})/ =~ txt | |
txt = txt.tr('0-9','0-9').gsub("時半",":30").gsub("時",":00") | |
ary = txt.scan(/[0-2]?[0-9]:[0-6]?[0-9]/) | |
next unless ary.size > 0 | |
t = Time.parse(ary[0]) | |
now = Time.now | |
d = (t < now ? t + 3600 * 24 : t) - now | |
EM.run do | |
EM.add_timer(d){ | |
twitter.update( "@%s 起きろ %f" % [account, Time.now.to_f], | |
:in_reply_to_status_id =>id ) | |
} | |
end | |
puts "registered 起きろevent".c(:info) | |
end | |
true | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment