Module: Chatterbot::Blocklist
- Included in:
- Bot
- Defined in:
- lib/chatterbot/blocklist.rb
Overview
methods for preventing the bot from spamming people who don’t want to hear from it
Instance Attribute Summary collapse
-
#blocklist ⇒ 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
-
#blacklist ⇒ Object
Returns the value of attribute blocklist.
- #interact_with_user?(t) ⇒ Boolean
-
#on_blocklist?(s) ⇒ Boolean
Is this tweet from a user on our blocklist?.
-
#skip_me?(s) ⇒ Boolean
Based on the text of this tweet, should it be skipped?.
- #valid_tweet?(object) ⇒ Boolean
Instance Attribute Details
#blocklist ⇒ Object
A list of Twitter users that don’t want to hear from the bot.
17 18 19 |
# File 'lib/chatterbot/blocklist.rb', line 17 def blocklist @blocklist 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
12 13 14 |
# File 'lib/chatterbot/blocklist.rb', line 12 def exclude @exclude end |
Instance Method Details
#blacklist ⇒ Object
Returns the value of attribute blocklist.
8 9 10 |
# File 'lib/chatterbot/blocklist.rb', line 8 def blocklist @blocklist end |
#interact_with_user?(t) ⇒ Boolean
31 32 33 34 35 |
# 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) ⇒ Boolean
Is this tweet from a user on our blocklist?
48 49 50 51 52 53 54 55 56 57 58 |
# 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) ⇒ Boolean
Based on the text of this tweet, should it be skipped?
26 27 28 29 |
# 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) ⇒ Boolean
37 38 39 40 41 42 43 44 |
# 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 |