Skip to content

Commit

Permalink
Filter retweets, clarify some corner cases
Browse files Browse the repository at this point in the history
Related: #9
  • Loading branch information
carstene1ns committed Jul 31, 2018
1 parent f0cb197 commit 8d42743
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions EV0002.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
}

config.plugins.options[Cinch::TwitterWebhooks] = {
:user => "EasyRPG",
:secret => $secrets["twitter_hooks"]["secret"]
}

Expand Down
25 changes: 24 additions & 1 deletion plugins/twitter_webhooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,31 @@ class Cinch::TwitterWebhooks

when "mention"

template = "New tweet by %s (https://twitter.com/%s/status/%s):"
# FIXME: all fields sent by zapier are strings

# ignore normal retweets
retweet = data["retweet_count"]
halt 202 if retweet != "0"

type = "tweet"

# retweet with added message
type = "quoted tweet" if data["is_quote"] == "True"

if data.has_key?('in_reply_to')

type = "tweet in conversation"

# replied to us?
if data["in_reply_to"] == bot.config.plugins.options[Cinch::TwitterWebhooks][:user]
type = "reply"
end

end

template = "New %s by %s (https://twitter.com/%s/status/%s):"
message = sprintf(template,
type,
data["name"],
user,
data["id"])
Expand Down

0 comments on commit 8d42743

Please sign in to comment.