Class: Campfire::Bot
- Inherits:
-
Object
- Object
- Campfire::Bot
- Defined in:
- lib/campfire_bot.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Method Summary collapse
Instance Method Summary collapse
- #evaluate(message) ⇒ Object
-
#initialize ⇒ Bot
constructor
A new instance of Bot.
- #login(&block) ⇒ Object
- #msg(text) ⇒ Object
- #on(regex, &block) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ Bot
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
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() if event = find_event() event.action.call end end |
#login(&block) ⇒ Object
20 21 22 23 24 |
# File 'lib/campfire_bot.rb', line 20 def login(&block) config = Config.new block.call(config) @campfire = Tinder::Campfire.new(config.subdomain, login_credentials(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 |
#start ⇒ Object
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 |