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:



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_updateObject (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

Parameters:

  • tweet (Twitter::Tweet)

    tweet to add



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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