Class: Raibo::Bot
- Inherits:
-
Object
- Object
- Raibo::Bot
- Defined in:
- lib/raibo/bot.rb
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(*args) ⇒ Bot
constructor
A new instance of Bot.
- #match(regexp, &block) ⇒ Object
- #run(async = false) ⇒ Object
- #stop ⇒ Object
- #use(handler = nil, &block) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Bot
Returns a new instance of Bot.
3 4 5 6 7 8 9 10 11 |
# File 'lib/raibo/bot.rb', line 3 def initialize(*args) @handlers = [] if args.first.is_a?(Raibo::Connection) @connection = args.shift else @connection = Raibo::Connection.new(*args) end end |
Instance Method Details
#alive? ⇒ Boolean
39 40 41 |
# File 'lib/raibo/bot.rb', line 39 def alive? @thread.alive? if @thread end |
#match(regexp, &block) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/raibo/bot.rb', line 17 def match(regexp, &block) use do |msg| if msg.body =~ regexp exec_with_var_arity($~, msg, &block) end end end |
#run(async = false) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/raibo/bot.rb', line 25 def run(async=false) if async @thread = Thread.new { run_sync } @thread.abort_on_exception = true else run_sync end end |
#stop ⇒ Object
34 35 36 37 |
# File 'lib/raibo/bot.rb', line 34 def stop @thread.kill if @thread @connection.close end |
#use(handler = nil, &block) ⇒ Object
13 14 15 |
# File 'lib/raibo/bot.rb', line 13 def use(handler=nil, &block) @handlers.push(handler || block) end |