Class: Isaac::Bot
- Inherits:
-
Object
- Object
- Isaac::Bot
- Defined in:
- lib/isaac/bot.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.
-
#host ⇒ Object
Returns the value of attribute host.
-
#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.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #action(recipient, text) ⇒ Object
- #configure(&b) ⇒ Object
- #dispatch(event, msg = nil) ⇒ Object
- #halt ⇒ Object
- #helpers(&b) ⇒ Object
-
#initialize(&b) ⇒ Bot
constructor
A new instance of Bot.
- #join(*channels) ⇒ Object
- #kick(channel, user, reason = nil) ⇒ Object
- #mode(channel, option) ⇒ 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
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def channel @channel end |
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def config @config end |
#error ⇒ Object
Returns the value of attribute error.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def error @error end |
#host ⇒ Object
Returns the value of attribute host.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def host @host end |
#irc ⇒ Object
Returns the value of attribute irc.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def irc @irc end |
#match ⇒ Object
Returns the value of attribute match.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def match @match end |
#message ⇒ Object
Returns the value of attribute message.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def @message end |
#nick ⇒ Object
Returns the value of attribute nick.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def nick @nick end |
#user ⇒ Object
Returns the value of attribute user.
9 10 11 |
# File 'lib/isaac/bot.rb', line 9 def user @user end |
Instance Method Details
#action(recipient, text) ⇒ Object
44 45 46 |
# File 'lib/isaac/bot.rb', line 44 def action(recipient, text) raw("PRIVMSG #{recipient} :\001ACTION #{text}\001") end |
#configure(&b) ⇒ Object
19 20 21 |
# File 'lib/isaac/bot.rb', line 19 def configure(&b) b.call(@config) end |
#dispatch(event, msg = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/isaac/bot.rb', line 83 def dispatch(event, msg=nil) if msg @nick, @user, @host, @channel, @error, @message = msg.nick, msg.user, msg.host, msg.channel, msg.error, msg. end if handler = find(event, ) regexp, block = *handler self.match = .match(regexp).captures invoke block end end |
#halt ⇒ Object
32 33 34 |
# File 'lib/isaac/bot.rb', line 32 def halt throw :halt end |
#helpers(&b) ⇒ Object
28 29 30 |
# File 'lib/isaac/bot.rb', line 28 def helpers(&b) instance_eval(&b) end |
#join(*channels) ⇒ Object
48 49 50 |
# File 'lib/isaac/bot.rb', line 48 def join(*channels) channels.each {|channel| raw("JOIN #{channel}")} end |
#kick(channel, user, reason = nil) ⇒ Object
64 65 66 |
# File 'lib/isaac/bot.rb', line 64 def kick(channel, user, reason=nil) raw("KICK #{channel} #{user} :#{reason}") end |
#mode(channel, option) ⇒ Object
60 61 62 |
# File 'lib/isaac/bot.rb', line 60 def mode(channel, option) raw("MODE #{channel} #{option}") end |
#msg(recipient, text) ⇒ Object
40 41 42 |
# File 'lib/isaac/bot.rb', line 40 def msg(recipient, text) raw("PRIVMSG #{recipient} :#{text}") end |
#on(event, match = //, &block) ⇒ Object
23 24 25 26 |
# File 'lib/isaac/bot.rb', line 23 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/bot.rb', line 52 def part(*channels) channels.each {|channel| raw("PART #{channel}")} end |
#quit(message = nil) ⇒ Object
68 69 70 71 |
# File 'lib/isaac/bot.rb', line 68 def quit(=nil) command = ? "QUIT :#{}" : "QUIT" raw command end |
#raw(command) ⇒ Object
36 37 38 |
# File 'lib/isaac/bot.rb', line 36 def raw(command) @irc.(command) end |
#start ⇒ Object
73 74 75 76 77 |
# File 'lib/isaac/bot.rb', line 73 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/bot.rb', line 56 def topic(channel, text) raw("TOPIC #{channel} :#{text}") end |