Class: Ebooks::Conversation

Inherits:
Object
  • Object
show all
Defined in:
lib/twitter_ebooks/bot.rb

Overview

Represents a single reply tree of tweets

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot) ⇒ Conversation

Returns a new instance of Conversation.

Parameters:



14
15
16
17
18
# File 'lib/twitter_ebooks/bot.rb', line 14

def initialize(bot)
  @bot = bot
  @tweets = []
  @last_update = Time.now
end

Instance Attribute Details

#last_updateObject (readonly)

Returns the value of attribute last_update.



11
12
13
# File 'lib/twitter_ebooks/bot.rb', line 11

def last_update
  @last_update
end

Instance Method Details

#add(tweet) ⇒ Object

Parameters:

  • tweet (Twitter::Tweet)

    tweet to add



21
22
23
24
# File 'lib/twitter_ebooks/bot.rb', line 21

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

Returns:

  • (Boolean)


42
43
44
45
# File 'lib/twitter_ebooks/bot.rb', line 42

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

Returns:

  • (Boolean)


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/twitter_ebooks/bot.rb', line 28

def is_bot?(username)
  usertweets = @tweets.select { |t| t.user.screen_name.downcase == username.downcase }

  if usertweets.length > 2
    if (usertweets[-1].created_at - usertweets[-3].created_at) < 10
      return true
    end
  end

  username.include?("ebooks")
end