From 8d427438aa21229d1dd14e3df6d92a99620ba179 Mon Sep 17 00:00:00 2001 From: Carsten Teibes Date: Tue, 31 Jul 2018 23:37:30 +0200 Subject: [PATCH] Filter retweets, clarify some corner cases Related: #9 --- EV0002.rb | 1 + plugins/twitter_webhooks.rb | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/EV0002.rb b/EV0002.rb index cb1da48..9891b75 100755 --- a/EV0002.rb +++ b/EV0002.rb @@ -103,6 +103,7 @@ } config.plugins.options[Cinch::TwitterWebhooks] = { + :user => "EasyRPG", :secret => $secrets["twitter_hooks"]["secret"] } diff --git a/plugins/twitter_webhooks.rb b/plugins/twitter_webhooks.rb index 9b24722..5d3ebd4 100644 --- a/plugins/twitter_webhooks.rb +++ b/plugins/twitter_webhooks.rb @@ -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"])