Class: Campfire::Bot

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

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBot

Returns a new instance of Bot.



16
17
18
# File 'lib/campfire_bot.rb', line 16

def initialize
  @events = []
end

Class Method Details

.config {|@bot| ... } ⇒ Object

Yields:

  • (@bot)


9
10
11
12
13
# File 'lib/campfire_bot.rb', line 9

def config
  @bot = new
  yield(@bot)
  @bot
end

Instance Method Details

#evaluate(message) ⇒ Object



41
42
43
44
45
# File 'lib/campfire_bot.rb', line 41

def evaluate(message)
  if event = find_event(message)
    event.action.call
  end
end

#login(&block) ⇒ Object



20
21
22
23
24
# File 'lib/campfire_bot.rb', line 20

def (&block)
  config = Config.new
  block.call(config)
  @campfire = Tinder::Campfire.new(config.subdomain, (config)).find_room_by_name(config.room)
end

#msg(text) ⇒ Object



33
34
35
# File 'lib/campfire_bot.rb', line 33

def msg(text)
  @campfire.speak(text)
end

#on(regex, &block) ⇒ Object



37
38
39
# File 'lib/campfire_bot.rb', line 37

def on(regex, &block)
  @events << Event.new(regex, block)
end

#startObject



26
27
28
29
30
31
# File 'lib/campfire_bot.rb', line 26

def start
  raise "You need to configure me" unless @campfire
  @campfire.listen do |line|
    evaluate(line[:body]) if line[:body]
  end
end