Class: SlackRubyBot::Server
- Inherits:
-
Object
- Object
- SlackRubyBot::Server
- Includes:
- Hooks::Hello, Hooks::Message, Loggable
- Defined in:
- lib/slack-ruby-bot/server.rb
Direct Known Subclasses
Constant Summary collapse
- TRAPPED_SIGNALS =
%w(INT TERM).freeze
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#send_gifs ⇒ Object
Returns the value of attribute send_gifs.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #auth! ⇒ Object
-
#initialize(options = {}) ⇒ Server
constructor
A new instance of Server.
- #restart!(wait = 1) ⇒ Object
- #run ⇒ Object
- #start! ⇒ Object
- #start_async ⇒ Object
- #stop! ⇒ Object
Methods included from Hooks::Message
Methods included from Hooks::Base
Methods included from Hooks::Hello
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 |
# File 'lib/slack-ruby-bot/server.rb', line 12 def initialize( = {}) @token = [:token] @aliases = [:aliases] @send_gifs = .key?(:send_gifs) ? !![:send_gifs] : true end |
Instance Attribute Details
#aliases ⇒ Object
Returns the value of attribute aliases.
5 6 7 |
# File 'lib/slack-ruby-bot/server.rb', line 5 def aliases @aliases end |
#send_gifs ⇒ Object
Returns the value of attribute send_gifs.
5 6 7 |
# File 'lib/slack-ruby-bot/server.rb', line 5 def send_gifs @send_gifs end |
#token ⇒ Object
Returns the value of attribute token.
5 6 7 |
# File 'lib/slack-ruby-bot/server.rb', line 5 def token @token end |
Instance Method Details
#auth! ⇒ Object
28 29 30 31 |
# File 'lib/slack-ruby-bot/server.rb', line 28 def auth! client.auth = client.web_client.auth_test logger.info "Welcome '#{client.auth['user']}' to the '#{client.auth['team']}' team at #{client.auth['url']}." end |
#restart!(wait = 1) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/slack-ruby-bot/server.rb', line 50 def restart!(wait = 1) @async ? start_async : start! rescue StandardError => e sleep wait logger.error "#{e.message}, reconnecting in #{wait} second(s)." logger.debug e restart! [wait * 2, 60].min end |
#run ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/slack-ruby-bot/server.rb', line 18 def run auth! loop do handle_execeptions do handle_signals start! end end end |
#start! ⇒ Object
33 34 35 36 37 |
# File 'lib/slack-ruby-bot/server.rb', line 33 def start! @stopping = false @async = false client.start! end |
#start_async ⇒ Object
39 40 41 42 43 |
# File 'lib/slack-ruby-bot/server.rb', line 39 def start_async @stopping = false @async = true client.start_async end |
#stop! ⇒ Object
45 46 47 48 |
# File 'lib/slack-ruby-bot/server.rb', line 45 def stop! @stopping = true client.stop! if @client end |