Module: Chatterbot::DirectMessages
- Included in:
- Bot
- Defined in:
- lib/chatterbot/direct_messages.rb
Overview
handle Twitter DMs
Instance Method Summary collapse
-
#direct_message(txt, user = nil) ⇒ Object
send a direct message.
-
#direct_messages(opts = {}, &block) ⇒ Object
check direct messages for the bot.
Instance Method Details
#direct_message(txt, user = nil) ⇒ Object
send a direct message
8 9 10 11 12 13 14 15 |
# File 'lib/chatterbot/direct_messages.rb', line 8 def (txt, user=nil) return unless require_login if user.nil? user = current_user end client.(user, txt) end |
#direct_messages(opts = {}, &block) ⇒ Object
check direct messages for the bot
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/chatterbot/direct_messages.rb', line 20 def (opts = {}, &block) return unless require_login debug "check for DMs since #{since_id_dm}" # # search twitter # @current_tweet = nil client.(since_id:since_id_dm, count:200).each { |s| update_since_id_dm(s) debug s.text if has_safelist? && !on_safelist?(s.sender) debug "skipping because user not on safelist" elsif block_given? && !on_blocklist?(s.sender) && !skip_me?(s) @current_tweet = s yield s end } @current_tweet = nil rescue Twitter::Error::Forbidden => e puts "sorry, looks like we're not allowed to check DMs for this account" end |