Class: Ebooks::Conversation
- Inherits:
-
Object
- Object
- Ebooks::Conversation
- Defined in:
- lib/twitter_ebooks/bot.rb
Overview
Represents a single reply tree of tweets
Instance Attribute Summary collapse
-
#last_update ⇒ Object
readonly
Returns the value of attribute last_update.
Instance Method Summary collapse
- #add(tweet) ⇒ Object
-
#can_include?(username) ⇒ Boolean
Figure out whether to keep this user in the reply prefix We want to avoid spamming non-participating users.
-
#initialize(bot) ⇒ Conversation
constructor
A new instance of Conversation.
-
#is_bot?(username) ⇒ Boolean
Make an informed guess as to whether a user is a bot based on their behavior in this conversation.
Constructor Details
#initialize(bot) ⇒ Conversation
Returns a new instance of Conversation.
22 23 24 25 26 |
# File 'lib/twitter_ebooks/bot.rb', line 22 def initialize(bot) @bot = bot @tweets = [] @last_update = Time.now end |
Instance Attribute Details
#last_update ⇒ Object (readonly)
Returns the value of attribute last_update.
19 20 21 |
# File 'lib/twitter_ebooks/bot.rb', line 19 def last_update @last_update end |
Instance Method Details
#add(tweet) ⇒ Object
29 30 31 32 |
# File 'lib/twitter_ebooks/bot.rb', line 29 def add(tweet) @tweets << tweet @last_update = Time.now end |
#can_include?(username) ⇒ Boolean
Figure out whether to keep this user in the reply prefix We want to avoid spamming non-participating users
48 49 50 51 |
# File 'lib/twitter_ebooks/bot.rb', line 48 def can_include?(username) @tweets.length <= 4 || !@tweets.select { |t| t.user.screen_name.downcase == username.downcase }.empty? end |
#is_bot?(username) ⇒ Boolean
Make an informed guess as to whether a user is a bot based on their behavior in this conversation
36 37 38 39 40 41 42 43 44 |
# File 'lib/twitter_ebooks/bot.rb', line 36 def is_bot?(username) usertweets = @tweets.select { |t| t.user.screen_name.downcase == username.downcase } if usertweets.length > 2 if username.include?('ebooks') || (usertweets[-1].created_at - usertweets[-3].created_at) < 12 return true end end end |