Class: Hipbot::Bot

Inherits:
Object
  • Object
show all
Extended by:
Reactable
Includes:
Adapter, Configurable, Matchable, Singleton
Defined in:
lib/hipbot/bot.rb

Instance Attribute Summary

Attributes included from Configurable

#configuration

Attributes included from Adapter

#connection

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Reactable

default, desc, on, on_presence, scope

Methods included from Cache

#_cache

Methods included from Matchable

#react, #react_to_presence, #reactions

Methods included from Configurable

#initialize

Methods included from Adapter

#invite_to_room, #join_room, #kick_from_room, #leave_room, #restart!, #send_to_room, #send_to_user, #set_presence, #set_topic, #start!

Class Method Details

.on_exception(&block) ⇒ Object



44
45
46
# File 'lib/hipbot/bot.rb', line 44

def on_exception &block
  instance.configuration.exception_handler = block
end

.on_preload(&block) ⇒ Object



40
41
42
# File 'lib/hipbot/bot.rb', line 40

def on_preload &block
  instance.configuration.preloader = block
end

.start!Object



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hipbot/bot.rb', line 48

def start!
  ::EM.error_handler(&instance.configuration.exception_handler)
  ::EM.run do
    instance.setup
    begin
      instance.start!
    rescue Exception => e
      instance_exec(e, &instance.configuration.exception_handler)
    end
  end
end

Instance Method Details

#setupObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/hipbot/bot.rb', line 28

def setup
  Hipbot.bot = self

  User.send(:include, storage)
  Room.send(:include, storage)
  Response.send(:include, helpers)

  helpers.module_exec(&preloader)
  plugins << self
end