Class: BotMob::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/bot_mob/application.rb

Overview

## BotMob::Application

This is the base class for BotMob.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot_class) ⇒ Application

Returns a new instance of Application.



8
9
10
11
12
13
# File 'lib/bot_mob/application.rb', line 8

def initialize(bot_class)
  @bot_class = bot_class
  @bots = {}

  Install.all.each { |install| register(install) }
end

Instance Attribute Details

#bot_classObject (readonly)

Returns the value of attribute bot_class.



6
7
8
# File 'lib/bot_mob/application.rb', line 6

def bot_class
  @bot_class
end

#botsObject (readonly)

Returns the value of attribute bots.



6
7
8
# File 'lib/bot_mob/application.rb', line 6

def bots
  @bots
end

Instance Method Details

#add_bot(user_id) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/bot_mob/application.rb', line 21

def add_bot(user_id)
  BotMob.logger.info "Adding bot: #{user_id}"
  install = Install.find_by_user_id(user_id)
  if install.nil?
    BotMob.logger.info "Could not find bot: #{user_id}"
    return
  end

  register install
end

#register(install) ⇒ Object



32
33
34
35
36
# File 'lib/bot_mob/application.rb', line 32

def register(install)
  bot = bot_class.new(install.user_id, install.token)
  @bots[install.user_id] ||= bot
  @bots[install.user_id].refresh
end

#start!Object



15
16
17
18
19
# File 'lib/bot_mob/application.rb', line 15

def start!
  BotMob.logger.info("=> BotMob #{BotMob::VERSION} application starting")
  wire.connect(self)
  loop { sleep(10) }
end