Class: Slappy::Client
- Inherits:
-
Object
- Object
- Slappy::Client
- Includes:
- Debuggable
- Defined in:
- lib/slappy/client.rb
Instance Attribute Summary collapse
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #client ⇒ Object
- #goodnight(&block) ⇒ Object
- #hear(pattern, options = {}, &block) ⇒ Object
- #hello(&block) ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #monitor(type, options = {}, &block) ⇒ Object
- #respond(pattern, options = {}, &block) ⇒ Object
- #say(text, options = {}) ⇒ Object
- #schedule(pattern, options = {}, &block) ⇒ Object
- #start ⇒ Object
Methods included from Debuggable
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
7 8 9 10 |
# File 'lib/slappy/client.rb', line 7 def initialize Slack.configure { |slack| slack.token = config.token } @callbacks = {} end |
Instance Attribute Details
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/slappy/client.rb', line 5 def start_time @start_time end |
Instance Method Details
#client ⇒ Object
12 13 14 |
# File 'lib/slappy/client.rb', line 12 def client @client ||= Slack.realtime end |
#goodnight(&block) ⇒ Object
35 36 37 |
# File 'lib/slappy/client.rb', line 35 def goodnight(&block) register_callback(:goodnight, :goodnight, block) end |
#hear(pattern, options = {}, &block) ⇒ Object
39 40 41 |
# File 'lib/slappy/client.rb', line 39 def hear(pattern, = {}, &block) register_callback(:hear, :message, Listener::TextListener.new(pattern, , &block)) end |
#hello(&block) ⇒ Object
31 32 33 |
# File 'lib/slappy/client.rb', line 31 def hello(&block) register_callback(:hello, :hello, block) end |
#monitor(type, options = {}, &block) ⇒ Object
50 51 52 |
# File 'lib/slappy/client.rb', line 50 def monitor(type, = {}, &block) register_callback(:monitor, type.to_sym, Listener::TypeListener.new(type, , &block)) end |
#respond(pattern, options = {}, &block) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/slappy/client.rb', line 43 def respond(pattern, = {}, &block) bot_name = [:bot_name] || config.robot.botname || config.robot.username pattern = "^#{bot_name}[[:blank:]]#{pattern}" register_callback(:respond, :message, Listener::TextListener.new(pattern, , &block)) end |
#say(text, options = {}) ⇒ Object
54 55 56 57 |
# File 'lib/slappy/client.rb', line 54 def say(text, = {}) [:text] = text Messenger.new(). end |
#schedule(pattern, options = {}, &block) ⇒ Object
59 60 61 62 63 |
# File 'lib/slappy/client.rb', line 59 def schedule(pattern, = {}, &block) @schedule ||= Schedule.new @schedule.register pattern, , &block Debug.log "Add schedule event(#{@schedule.list.size}): #{pattern}" end |
#start ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/slappy/client.rb', line 16 def start setup Debug.log 'Slappy start' begin client.start rescue StandardError => e @callbacks[:goodnight].each(&:call) if @callbacks[:goodnight] STDERR.puts e.backtrace.slice!(0) + ': ' + e. STDERR.puts "\tfrom " + e.backtrace.join("\n\tfrom ") exit 1 if config.stop_with_error end end |