Class: Beeline::Bot
Constant Summary
Constants inherited from Client
Client::INITIAL_LATCH, Client::MAX_LATCH
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Attributes inherited from Client
Instance Method Summary collapse
- #command(name, options = {}, &block) ⇒ Object
- #message(pattern, options = {}, &block) ⇒ Object
- #process_chat_message(payload) ⇒ Object
- #process_friendship_requested(payload) ⇒ Object
- #process_status(payload) ⇒ Object
Methods inherited from Client
#initialize, #ping, #reset_session, #run, #run_loop
Methods included from Config
#friendships, #hive_account, #hive_posting_wif, #hive_public_key
Constructor Details
This class inherits a constructor from Beeline::Client
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
3 4 5 |
# File 'lib/beeline/bot.rb', line 3 def prefix @prefix end |
Instance Method Details
#command(name, options = {}, &block) ⇒ Object
5 6 7 |
# File 'lib/beeline/bot.rb', line 5 def command name, = {}, &block commands[name] = {options: , block: block} end |
#message(pattern, options = {}, &block) ⇒ Object
9 10 11 |
# File 'lib/beeline/bot.rb', line 9 def pattern, = {}, &block [pattern] = {options: , block: block} end |
#process_chat_message(payload) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/beeline/bot.rb', line 21 def (payload) from = payload['from'] cooldown(from) conversation_id = payload['conversation_id'] content = payload['content'].to_s command_key = content.split(' ').first.split(prefix).last.to_sym reply = if commands.keys.include? command_key args = (content.split(' ') - ["#{prefix}#{command_key}"]).join(' ') args = args.empty? ? nil : args commands[command_key][:block].call(args, from, conversation_id) elsif ( = .select{|k| Regexp.new(k).match?(content)}).any? = .values.first # match in order of declaration [:block].call(content, from, conversation_id) end if !!reply (conversation_id, from, reply) end end |
#process_friendship_requested(payload) ⇒ Object
45 46 47 48 49 |
# File 'lib/beeline/bot.rb', line 45 def process_friendship_requested(payload) return unless friendships[:accept] == 'auto' accept_pending_friend_requests end |
#process_status(payload) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/beeline/bot.rb', line 13 def process_status(payload) if payload['authenticated'] puts 'Got acknowledge authenticated.' else abort 'Unable to authenticate.' end end |