Class: Isaac::Bot

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#channelObject

Returns the value of attribute channel.



13
14
15
# File 'lib/isaac.rb', line 13

def channel
  @channel
end

#configObject

Returns the value of attribute config.



13
14
15
# File 'lib/isaac.rb', line 13

def config
  @config
end

#errorObject

Returns the value of attribute error.



13
14
15
# File 'lib/isaac.rb', line 13

def error
  @error
end

#ircObject

Returns the value of attribute irc.



13
14
15
# File 'lib/isaac.rb', line 13

def irc
  @irc
end

#matchObject

Returns the value of attribute match.



13
14
15
# File 'lib/isaac.rb', line 13

def match
  @match
end

#messageObject

Returns the value of attribute message.



13
14
15
# File 'lib/isaac.rb', line 13

def message
  @message
end

#newnickObject

Returns the value of attribute newnick.



13
14
15
# File 'lib/isaac.rb', line 13

def newnick
  @newnick
end

#nickObject

Returns the value of attribute nick.



13
14
15
# File 'lib/isaac.rb', line 13

def nick
  @nick
end

#userhostObject

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.message = env[:message] || ""
  self.newnick = env[:newnick] || ""

  if handler = find(event, message)
    regexp, block = *handler
    self.match = message.match(regexp).captures
    invoke block
  end
end

#haltObject



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(message=nil)
  command = message ? "QUIT :#{message}" : "QUIT"
  raw command
end

#raw(command) ⇒ Object



40
41
42
# File 'lib/isaac.rb', line 40

def raw(command)
  @irc.message(command)
end

#startObject



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