module Chatterbot::Blocklist

methods for preventing the bot from spamming people who don't want to hear from it

Attributes

blacklist[RW]
blocklist[RW]
exclude[RW]

Public Instance Methods

blocklist=(b) click to toggle source
# File lib/chatterbot/blocklist.rb, line 20
def blocklist=(b)
  @blocklist = b
end
interact_with_user?(t) click to toggle source
# File lib/chatterbot/blocklist.rb, line 31
def interact_with_user?(t)
  return true unless only_interact_with_followers?
  u = t.respond_to?(:user) ? t.user : t
  client.friendship?(u, authenticated_user)
end
on_blocklist?(s) click to toggle source

Is this tweet from a user on our blocklist?

# File lib/chatterbot/blocklist.rb, line 48
def on_blocklist?(s)
  search = if s.is_a?(Twitter::User)
             s.name
           elsif s.respond_to?(:user) && !s.is_a?(Twitter::NullObject)
             from_user(s)
           else
             s
           end.downcase

  blocklist.any? { |b| search.include?(b.downcase) }
end
skip_me?(s) click to toggle source

Based on the text of this tweet, should it be skipped?

# File lib/chatterbot/blocklist.rb, line 26
def skip_me?(s)
  search = s.respond_to?(:text) ? s.text : s
  exclude.detect { |e| search.downcase.include?(e) } != nil
end
valid_tweet?(object) click to toggle source
# File lib/chatterbot/blocklist.rb, line 37
def valid_tweet?(object)
  if has_safelist? && ! on_safelist?(object)
    debug "skipping because user not on safelist"
    return false
  end

  !skippable_retweet?(object) && ! on_blocklist?(object) && ! skip_me?(object) && interact_with_user?(object)
end