Skip to content

Instantly share code, notes, and snippets.

@siyo
Last active December 12, 2015 02:09
Show Gist options
  • Save siyo/4696814 to your computer and use it in GitHub Desktop.
Save siyo/4696814 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
# honki dase plugin
#
# e.g.:
# event registration from tweet
# $ 20:00に本気だす
#
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