<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>Rakefile</filename>
    </added>
    <added>
      <filename>SHAFT</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,4 @@
 = Isaac - the smallish DSL for writing IRC bots
-You want to create an IRC bot quickly? Then Isaac is you. It will be. At some point, at least. But you shall be welcome to try it out and help me extend and beautify it. Be aware, the code is not stellar by any measure, most likely it is very crude and a large portion of the IRC standard has not been implemented, simply because I haven't needed it yet. Oh, and a lot of concepts were borrowed from Sinatra (http://sinatrarb.com). Thanks.
 
 == Features
 * Wraps parsing of incoming messages and raw IRC commands in simple constructs.
@@ -9,7 +8,7 @@ You want to create an IRC bot quickly? Then Isaac is you. It will be. At some po
 == Getting started
 An Isaac-bot needs a few basics:
   require 'isaac'
-  config do |c|
+  configure do |c|
     c.nick    = &quot;AwesomeBot&quot;
     c.server  = &quot;irc.freenode.net&quot;
     c.port    = 6667
@@ -25,21 +24,23 @@ After the bot has connected to the IRC server you might want to join some channe
 === Responding to messages
 Joining a channel and sitting idle is not much fun. Let's repeat everything being said in these channels:
 
-  on :channel, /.*/ do
+  on :channel, // do
     msg channel, message
   end
 
-Notice the +channel+ and +message+ variables. Additionally +nick+ and +match+ is available for channel-events. +nick+ being the sender of the message, +match+ being a MatchData object returned by the regular expression you specified:
+Notice the +channel+ and +message+ variables. Additionally +nick+ and +match+ is
+available for channel-events. +nick+ being the sender of the message, +match+
+being an array of captures from the regular expression:
 
   on :channel, /^quote this: (.*)/ do
-    msg channel, &quot;Quote: '#{match[1]}' by #{nick}&quot;
+    msg channel, &quot;Quote: '#{match[0]}' by #{nick}&quot;
   end
 
 If you want to match private messages use the +on :private+ event:
 
   on :private, /^login (\S+) (\S+)/ do
-    username = match[1]
-    password = match[2]
+    username = match[0]
+    password = match[0]
     # do something to authorize or whatevz.
     msg nick, &quot;Login successful!&quot;
   end
@@ -84,11 +85,4 @@ You might want to send messages, join channels etc. without it strictly being th
 The source is hosted at GitHub: http://github.com/ichverstehe/isaac
 
 == License
-  ------------------------------------------------------------------------------
-  &quot;THE BEER-WARE LICENSE&quot; (Revision 42):
-  &lt;ichverstehe@gmail.com&gt; wrote this file. As long as you retain this notice you
-  can do whatever you want with this stuff. If we meet some day, and you think
-  this stuff is worth it, you can buy me a beer in return.
-  ------------------------------------------------------------------------------
-
-
+The MIT. Google it.</diff>
      <filename>README.rdoc</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 require 'lib/isaac.rb'
 
-config do |c|
+configure do |c|
   c.nick    = &quot;The_Echo_Bot&quot;
   c.server  = &quot;irc.freenode.net&quot;
   c.port    = 6667</diff>
      <filename>examples/excess_flood.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,7 +4,6 @@ config do |c|
   c.nick    = &quot;SomeBot&quot;
   c.server  = &quot;irc.freenode.net&quot;
   c.port    = 6667
-  c.username = 'ihayes'
   c.realname = 'Isaac Hayes'
   c.verbose  = true
   c.version  = 'SchemaBot v0.1.2' </diff>
      <filename>examples/schema.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,6 +18,8 @@ module Isaac
       instance_eval(&amp;b) if block_given?
     end
 
+    def binding; binding; end
+
     def start
       @irc = IRC.new(self, @config)
       @irc.connect
@@ -41,15 +43,15 @@ module Isaac
         env[:nick], env[:userhost], env[:channel], env[:error]
       self.message = env[:message] || &quot;&quot;
 
-      regexp, block = @events[event] &amp;&amp; @events[event].detect do |regexp, block|
+      event = @events[event] &amp;&amp; @events[event].detect do |regexp,_|
         message.match(regexp)
       end
 
-      self.match = message.match(regexp)
-      match_arr = match.to_a
-      match_arr.shift
-
-      catch(:halt) { block.call(*match_arr) }
+      if event
+        regexp, block = *event
+        self.match = message.match(regexp).captures
+        catch(:halt) { instance_eval(&amp;block) }
+      end
     end
 
     def halt
@@ -73,6 +75,8 @@ module Isaac
     def initialize(bot, config)
       @bot, @config = bot, config
       @transfered = 0
+      @registration = []
+      @lock = false
       @queue = []
     end
 
@@ -81,6 +85,7 @@ module Isaac
       message &quot;PASSWORD #{@config.password}&quot; if @config.password
       message &quot;NICK #{@config.nick}&quot;
       message &quot;USER #{@config.nick} 0 * :#{@config.realname}&quot;
+      @lock = true
 
       # This should probably be somewhere else..
       if @config.environment == :test
@@ -99,8 +104,15 @@ module Isaac
     def parse(input)
       puts &quot;&lt;&lt; #{input}&quot; if @bot.config.verbose
       case input
+      when /^:\S+ 00([1-4])/
+        @registration &lt;&lt; $1.to_i
+        if registered?
+          @lock = false
+          @bot.dispatch(:connect)
+          continue_queue
+        end
       when /^PING (\S+)/
-        @transfered = 0
+        @transfered, @lock = 0, false
         message &quot;PONG #{$1}&quot;
         continue_queue
       when /^:(\S+)!(\S+) PRIVMSG (\S+) :?(.*)/
@@ -111,11 +123,15 @@ module Isaac
         env = {:error =&gt; $1.to_i, :message =&gt; $1, :nick =&gt; $2, :channel =&gt; $2}
         @bot.dispatch(:error, env)
       when /^:\S+ PONG/
-        @transfered = 0
+        @transfered, @lock = 0, false
         continue_queue
       end
     end
 
+    def registered?
+      ([1,2,3,4] - @registration).empty?
+    end
+
     def message(msg)
       @queue &lt;&lt; msg
       continue_queue
@@ -123,13 +139,14 @@ module Isaac
 
     def continue_queue
       # &lt;= 1472 allows for \n
-      while msg = @queue.shift
+      while !@lock &amp;&amp; msg = @queue.shift
         if (@transfered + msg.size) &lt; 1472
           @socket.puts msg
           puts &quot;&gt;&gt; #{msg}&quot; if @bot.config.verbose
           @transfered += msg.size + 1
         else
           @queue.unshift(msg)
+          @lock = true
           @socket.puts &quot;PING :#{@bot.config.server}&quot;
           break
         end</diff>
      <filename>lib/isaac.rb</filename>
    </modified>
    <modified>
      <diff>@@ -31,6 +31,7 @@ class Test::Unit::TestCase
   def bot_is_connected
     assert_equal &quot;NICK isaac\n&quot;, @server.gets
     assert_equal &quot;USER isaac 0 * :Isaac\n&quot;, @server.gets
+    1.upto(4) {|i| @server.puts &quot;:localhost 00#{i}&quot;}
   end
 
   def assert_empty_buffer(io)</diff>
      <filename>test/helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -38,28 +38,27 @@ class TestEvents &lt; Test::Unit::TestCase
     }
     bot_is_connected
 
-    bot.dispatch(:connect)
     assert_equal &quot;PRIVMSG foo :bar baz\n&quot;, @server.gets
   end
 
   test &quot;regular expression match is accessible&quot; do
     bot = mock_bot {
-      on(:channel, /foo (bar)/) {assert_equal &quot;bar&quot;, match[1]}
+      on(:channel, /foo (bar)/) {assert_equal &quot;bar&quot;, match[0]}
     }
     bot_is_connected
 
     bot.dispatch(:channel, :message =&gt; &quot;foo bar&quot;)
   end
 
-  test &quot;regular expression matches is handed to block arguments&quot; do
-    bot = mock_bot {
-      on :channel, /(foo) (bar)/ do |foo,bar|
-        assert_equal &quot;foo&quot;, foo
-        assert_equal &quot;bar&quot;, bar
-      end
-    }
-    bot_is_connected
+  #test &quot;regular expression matches is handed to block arguments&quot; do
+    #bot = mock_bot {
+      #on :channel, /(foo) (bar)/ do |foo,bar|
+        #assert_equal &quot;foo&quot;, foo
+        #assert_equal &quot;bar&quot;, bar
+      #end
+    #}
+    #bot_is_connected
 
-    bot.dispatch(:channel, :message =&gt; &quot;foo bar&quot;)
-  end
+    #bot.dispatch(:channel, :message =&gt; &quot;foo bar&quot;)
+  #end
 end</diff>
      <filename>test/test_events.rb</filename>
    </modified>
    <modified>
      <diff>@@ -13,4 +13,25 @@ class TestIrc &lt; Test::Unit::TestCase
     }
     assert_equal &quot;PASSWORD foo\n&quot;, @server.gets
   end
+
+  test &quot;no messages are sent when registration isn't complete&quot; do
+    bot = mock_bot {
+      on(:connect) {raw &quot;Connected!&quot;}
+    }
+    2.times { @server.gets } # NICK / USER
+    bot.dispatch :connect
+
+    assert_empty_buffer @server
+  end
+
+  test &quot;no messages are sent until registration is complete&quot; do
+    bot = mock_bot {
+      on(:connect) {raw &quot;Connected!&quot;}
+    }
+    2.times { @server.gets } # NICK / USER
+    bot.dispatch :connect
+
+    1.upto(4) {|i| @server.puts &quot;:localhost 00#{i}&quot;}
+    assert_equal &quot;Connected!\n&quot;, @server.gets
+  end
 end</diff>
      <filename>test/test_irc.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>examples/execute.rb</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>39c3201109e7961aacf32f0ea7617dc848858b5d</id>
    </parent>
  </parents>
  <author>
    <name>Harry Vangberg</name>
    <email>harry@vangberg.name</email>
  </author>
  <url>http://github.com/ichverstehe/isaac/commit/590082e0755f70f10fc30415d167cdd1d55d33b0</url>
  <id>590082e0755f70f10fc30415d167cdd1d55d33b0</id>
  <committed-date>2009-02-23T12:51:49-08:00</committed-date>
  <authored-date>2009-02-23T12:51:49-08:00</authored-date>
  <message>more stuff</message>
  <tree>8e3cfa2c2707fe0c0dafa833dea145b7d1fa0388</tree>
  <committer>
    <name>Harry Vangberg</name>
    <email>harry@vangberg.name</email>
  </committer>
</commit>
