Last active
December 26, 2015 21:19
-
-
Save babie/7215590 to your computer and use it in GitHub Desktop.
This file contains 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
# Earthquake.config[:event_chain] = { | |
# :favorite => [':retweet %{id}'], | |
# :favorited => [':update @%{him} thx 4 ur fav!'], | |
# :followed => ['unblock %{him}', ':follow %{him}'], | |
# } | |
module Earthquake::Input | |
def passivise(str) | |
if str.end_with?("ed") | |
str | |
elsif str.end_with?("e") | |
str + "d" | |
else | |
str + "ed" | |
end | |
end | |
def parse_caller(at) | |
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at | |
{:file => $1, :line => $2.to_i, :method => $3} | |
else | |
{} | |
end | |
end | |
def from_this_file?(dup_caller) | |
dup_caller[1..-1].any? do |at| | |
parse_caller(at)[:file] == __FILE__ | |
end | |
end | |
def confirm_with_check_caller(message, type = config[:confirm_type]) | |
return true if from_this_file?(caller.dup) | |
confirm_without_check_caller(message, type) | |
end | |
alias_method_chain :confirm, :check_caller | |
end | |
Earthquake.init do | |
_ = config[:event_chain] ||= {} | |
_.deep_stringify_keys! | |
output_filter do |item| | |
next unless item["event"] | |
me = twitter.info["screen_name"] | |
if item["source"]["screen_name"] == me | |
event = item["event"].dup | |
it = item["target"]["screen_name"] | |
else | |
event = passivise(item["event"]) | |
it = item["source"]["screen_name"] | |
end | |
actions = config[:event_chain][event] | |
next if actions.blank? | |
h = { | |
:me => me, | |
:him => it, :her => it, :it => it, | |
:id => (id2var(item["target_object"]["id"]) rescue nil), | |
} | |
actions.each do |action| | |
action %= h | |
cmd = eval(%|"#{action.gsub('"', '\"')}"|) | |
input(cmd) | |
end | |
next | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment