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.
-
#newnick ⇒ Object
Returns the value of attribute newnick.
-
#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, text) ⇒ Object
- #on(event, match = //, &block) ⇒ Object
- #part(*channels) ⇒ Object
- #quit(message = nil) ⇒ Object
- #raw(command) ⇒ Object
- #start ⇒ Object
- #topic(channel, text) ⇒ Object
Constructor Details
#initialize(&b) ⇒ Bot
Returns a new instance of Bot.
16 17 18 19 20 21 |
# File 'lib/isaac.rb', line 16 def initialize(&b) @events = {} @config = Config.new("localhost", 6667, false, nil, "isaac", "Isaac", 'isaac', :production, false) instance_eval(&b) if block_given? end |
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 end |
#newnick ⇒ Object
Returns the value of attribute newnick.
13 14 15 |
# File 'lib/isaac.rb', line 13 def newnick @newnick 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
23 24 25 |
# File 'lib/isaac.rb', line 23 def configure(&b) b.call(@config) end |
#dispatch(event, env = {}) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/isaac.rb', line 71 def dispatch(event, env={}) self.nick, self.userhost, self.channel, self.error = env[:nick], env[:userhost], env[:channel], env[:error] self. = env[:message] || "" self.newnick = env[:newnick] || "" if handler = find(event, ) regexp, block = *handler self.match = .match(regexp).captures invoke block end end |
#halt ⇒ Object
36 37 38 |
# File 'lib/isaac.rb', line 36 def halt throw :halt end |
#helpers(&b) ⇒ Object
32 33 34 |
# File 'lib/isaac.rb', line 32 def helpers(&b) instance_eval(&b) end |
#join(*channels) ⇒ Object
48 49 50 |
# File 'lib/isaac.rb', line 48 def join(*channels) channels.each {|channel| raw("JOIN #{channel}")} end |
#msg(recipient, text) ⇒ Object
44 45 46 |
# File 'lib/isaac.rb', line 44 def msg(recipient, text) raw("PRIVMSG #{recipient} :#{text}") end |
#on(event, match = //, &block) ⇒ Object
27 28 29 30 |
# File 'lib/isaac.rb', line 27 def on(event, match=//, &block) match = match.to_s if match.is_a? Integer (@events[event] ||= []) << [Regexp.new(match), block] end |
#part(*channels) ⇒ Object
52 53 54 |
# File 'lib/isaac.rb', line 52 def part(*channels) channels.each {|channel| raw("PART #{channel}")} end |
#quit(message = nil) ⇒ Object
60 61 62 63 |
# File 'lib/isaac.rb', line 60 def quit(=nil) command = ? "QUIT :#{message}" : "QUIT" raw command end |
#raw(command) ⇒ Object
40 41 42 |
# File 'lib/isaac.rb', line 40 def raw(command) @irc.(command) end |
#start ⇒ Object
65 66 67 68 69 |
# File 'lib/isaac.rb', line 65 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
56 57 58 |
# File 'lib/isaac.rb', line 56 def topic(channel, text) raw("TOPIC #{channel} :#{text}") end |