Last active
December 12, 2015 08:29
-
-
Save siyo/4744091 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 -*- | |
# nero plugin | |
# | |
# event registration from tweet | |
# $ 20:31に寝る | |
# $ 20時半に寝たい | |
# | |
require 'time' | |
Earthquake.init do | |
output_filter do |item| | |
next unless item["user"] && item["text"] | |
account = item["user"]["screen_name"] | |
id = item["id"] | |
txt = item["text"] | |
if /(?<!まで)(寝る|寝たい)/ =~ 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