From a6f32fda6e0e53d559b05ae183d4ed15e79350aa Mon Sep 17 00:00:00 2001 From: Hiramiya Date: Sat, 17 May 2014 15:40:58 +0100 Subject: [PATCH] Prevent double-favourite on special tweets Tweets determined as 'special' to the bot could (under a 50% chance) accidentally attempt to be favourited twice, causing a crash due to Twitter returning a Forbidden response. In this example, we add an assertion to check whether the earlier favourite has occurred, to prevent it happening again. --- bots.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bots.rb b/bots.rb index ac26cb4..80b7c49 100644 --- a/bots.rb +++ b/bots.rb @@ -67,6 +67,7 @@ class GenBot if special favorite(tweet) + favd = true # Mark this tweet as favorited bot.delay DELAY do bot.follow tweet[:user][:screen_name] @@ -79,7 +80,7 @@ class GenBot $have_talked[tweet[:user][:screen_name]] = true if very_interesting || special - favorite(tweet) if rand < 0.5 + favorite(tweet) if (rand < 0.5 && !favd) # Don't fav the tweet if we did earlier retweet(tweet) if rand < 0.1 reply(tweet, meta) if rand < 0.1 elsif interesting