Module: Chatterbot::Blacklist
- Included in:
- Bot
- Defined in:
- lib/chatterbot/blacklist.rb
Overview
methods for preventing the bot from spamming people who don’t want to hear from it
Instance Attribute Summary collapse
-
#blacklist ⇒ Object
A list of Twitter users that don’t want to hear from the bot.
-
#exclude ⇒ Object
return a list of text strings which we will check for in incoming tweets.
Instance Method Summary collapse
-
#add_to_blacklist(user) ⇒ Object
add the specified user to the global blacklist.
-
#on_blacklist?(s) ⇒ Boolean
Is this tweet from a user on our blacklist?.
-
#on_global_blacklist?(user) ⇒ Boolean
Is this user on our global blacklist?.
-
#skip_me?(s) ⇒ Boolean
Based on the text of this tweet, should it be skipped?.
Instance Attribute Details
#blacklist ⇒ Object
A list of Twitter users that don’t want to hear from the bot.
15 16 17 |
# File 'lib/chatterbot/blacklist.rb', line 15 def blacklist @blacklist end |
#exclude ⇒ Object
return a list of text strings which we will check for in incoming tweets. If the text is listed, we won’t use this tweet
10 11 12 |
# File 'lib/chatterbot/blacklist.rb', line 10 def exclude @exclude end |
Instance Method Details
#add_to_blacklist(user) ⇒ Object
add the specified user to the global blacklist
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/chatterbot/blacklist.rb', line 46 def add_to_blacklist(user) user = user.is_a?(Hash) ? user[:from_user] : user # don't try and add if we don't have a DB connection, or if the # user is already on the list return if ! has_db? || on_global_blacklist?(user) # make sure we don't have an @ at the beginning of the username user.gsub!(/^@/, "") debug "adding #{user} to blacklist" db[:blacklist].insert({ :user => user, :created_at => Time.now }) # end |
#on_blacklist?(s) ⇒ Boolean
Is this tweet from a user on our blacklist?
31 32 33 34 35 |
# File 'lib/chatterbot/blacklist.rb', line 31 def on_blacklist?(s) search = (s.respond_to?(:user) ? from_user(s) : s).downcase blacklist.any? { |b| search.include?(b.downcase) } || on_global_blacklist?(search) end |