Class: Isaac::Bot
- Inherits:
-
Object
- Object
- Isaac::Bot
- Defined in:
- lib/isaac.rb
Instance Attribute Summary collapse
-
#channel ⇒ Object
Returns the value of attribute channel.
-
#config ⇒ Object
Returns the value of attribute config.
-
#error ⇒ Object
Returns the value of attribute error.
-
#irc ⇒ Object
Returns the value of attribute irc.
-
#match ⇒ Object
Returns the value of attribute match.
-
#message ⇒ Object
Returns the value of attribute message.
-
#nick ⇒ Object
Returns the value of attribute nick.
-
#userhost ⇒ Object
Returns the value of attribute userhost.
Instance Method Summary collapse
- #configure(&b) ⇒ Object
- #dispatch(event, env = {}) ⇒ Object
- #halt ⇒ Object
- #helpers(&b) ⇒ Object
-
#initialize(&b) ⇒ Bot
constructor
A new instance of Bot.
- #join(*channels) ⇒ Object
- #msg(recipient, m) ⇒ Object
- #on(event, match = //, &b) ⇒ Object
- #part(*channels) ⇒ Object
- #raw(m) ⇒ Object
- #start ⇒ Object
- #topic(channel, text) ⇒ Object
Constructor Details
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
13 14 15 |
# File 'lib/isaac.rb', line 13 def channel @channel end |
#config ⇒ Object
Returns the value of attribute config.
13 14 15 |
# File 'lib/isaac.rb', line 13 def config @config end |
#error ⇒ Object
Returns the value of attribute error.
13 14 15 |
# File 'lib/isaac.rb', line 13 def error @error end |
#irc ⇒ Object
Returns the value of attribute irc.
13 14 15 |
# File 'lib/isaac.rb', line 13 def irc @irc end |
#match ⇒ Object
Returns the value of attribute match.
13 14 15 |
# File 'lib/isaac.rb', line 13 def match @match end |
#message ⇒ Object
Returns the value of attribute message.
13 14 15 |
# File 'lib/isaac.rb', line 13 def @message end |
#nick ⇒ Object
Returns the value of attribute nick.
13 14 15 |
# File 'lib/isaac.rb', line 13 def nick @nick end |
#userhost ⇒ Object
Returns the value of attribute userhost.
13 14 15 |
# File 'lib/isaac.rb', line 13 def userhost @userhost end |
Instance Method Details
#configure(&b) ⇒ Object
38 39 40 |
# File 'lib/isaac.rb', line 38 def configure(&b) b.call(@config) end |
#dispatch(event, env = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/isaac.rb', line 42 def dispatch(event, env={}) self.nick, self.userhost, self.channel, self.error = env[:nick], env[:userhost], env[:channel], env[:error] self. = env[:message] || "" event = @events[event] && @events[event].detect do |regexp,_| .match(regexp) end if event regexp, block = *event self.match = .match(regexp).captures catch(:halt) { instance_eval(&block) } end end |
#halt ⇒ Object
58 59 60 |
# File 'lib/isaac.rb', line 58 def halt throw :halt end |
#helpers(&b) ⇒ Object
34 35 36 |
# File 'lib/isaac.rb', line 34 def helpers(&b) instance_eval &b end |
#join(*channels) ⇒ Object
70 71 72 |
# File 'lib/isaac.rb', line 70 def join(*channels) channels.each {|channel| raw("JOIN #{channel}")} end |
#msg(recipient, m) ⇒ Object
66 67 68 |
# File 'lib/isaac.rb', line 66 def msg(recipient, m) raw("PRIVMSG #{recipient} :#{m}") end |
#on(event, match = //, &b) ⇒ Object
29 30 31 32 |
# File 'lib/isaac.rb', line 29 def on(event, match=//, &b) match = match.to_s if match.is_a? Integer (@events[event] ||= []) << [Regexp.new(match), b] end |
#part(*channels) ⇒ Object
74 75 76 |
# File 'lib/isaac.rb', line 74 def part(*channels) channels.each {|channel| raw("PART #{channel}")} end |
#raw(m) ⇒ Object
62 63 64 |
# File 'lib/isaac.rb', line 62 def raw(m) @irc.(m) end |
#start ⇒ Object
23 24 25 26 27 |
# File 'lib/isaac.rb', line 23 def start puts "Connecting to #{@config.server}:#{@config.port}" unless @config.environment == :test @irc = IRC.new(self, @config) @irc.connect end |
#topic(channel, text) ⇒ Object
78 79 80 |
# File 'lib/isaac.rb', line 78 def topic(channel, text) raw("TOPIC #{channel} :#{text}") end |