Class: SlackRubyBot::Server
- Inherits:
-
Object
- Object
- SlackRubyBot::Server
- Includes:
- Hooks::HookSupport, 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
-
#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::HookSupport
#add_hook_handlers, #flush_hook_blocks, #hooks, included
Methods included from Loggable
Constructor Details
#initialize(options = {}) ⇒ Server
Returns a new instance of Server.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/slack-ruby-bot/server.rb', line 11 def initialize( = {}) @token = [:token] @aliases = [:aliases] @send_gifs = [:send_gifs] # Hook Handling flush_hook_blocks add_hook_handlers [:hook_handlers] || { hello: SlackRubyBot::Hooks::Hello.new(logger), message: SlackRubyBot::Hooks::Message.new } 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
#restart!(wait = 1) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/slack-ruby-bot/server.rb', line 51 def restart!(wait = 1) @async ? start_async : start! rescue StandardError => e case e. when 'account_inactive', 'invalid_auth' logger.error "#{token}: #{e.}, team will be deactivated." @stopping = true else sleep wait logger.error "#{e.}, reconnecting in #{wait} second(s)." logger.debug e restart! [wait * 2, 60].min end end |
#run ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/slack-ruby-bot/server.rb', line 25 def run loop do handle_exceptions do handle_signals start! end end end |
#start! ⇒ Object
34 35 36 37 38 |
# File 'lib/slack-ruby-bot/server.rb', line 34 def start! @stopping = false @async = false client.start! end |
#start_async ⇒ Object
40 41 42 43 44 |
# File 'lib/slack-ruby-bot/server.rb', line 40 def start_async @stopping = false @async = true client.start_async end |
#stop! ⇒ Object
46 47 48 49 |
# File 'lib/slack-ruby-bot/server.rb', line 46 def stop! @stopping = true client.stop! if @client end |