<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,42 +1,6 @@
 #!/usr/bin/env ruby
 require File.join(File.dirname(__FILE__), '..', 'lib', 'on_irc')
 
-# This implements an array that won't grow larger than a given length.
-# it drops items from the start when you append to it.
-class Backlog
-  attr_reader :length
-
-  def initialize(length)
-    @array = []
-    @length = length
-  end
-
-  def &lt;&lt;(msg)
-    @array.unshift msg
-    @array.pop if @array.length &gt; @length
-
-    self
-  end
-
-  def [](index)
-    raise 'index out of bounds' if index &gt;= @length
-    @array[index]
-  end
-
-  def []=(index, value)
-    raise 'index out of bounds' if index &gt;= @length
-    @array[index] = value
-  end
-
-  def newest
-    @array.first
-  end
-
-  def oldest
-    @array.last
-  end
-end
-
 MAX_BANGS = 3
 CH_USER_MEMORY = {}
 CHANNEL_MEMORY = {}
@@ -63,27 +27,36 @@ end
 IRC.on :privmsg do
   next unless params[0][0,1] == '#' # make sure regex replace only happens in channels
   channel = params[0]
-  user = prefix.split('!').first
+  nick = prefix.split('!').first
   message = params[1]
 
-  if params[1] =~ %r&quot;^(!{0,#{MAX_BANGS}})s/((?:[^\\/]|\\.)*)/((?:[^\\/]|\\.)*)/(?:(\w*))?&quot;
+  CHANNEL_MEMORY[channel] ||= []
+  CH_USER_MEMORY[channel] ||= {}
+  CH_USER_MEMORY[channel][nick] ||= []
+
+  if params[1] =~ %r&quot;^(!*)s/((?:[^\\/]|\\.)*)/((?:[^\\/]|\\.)*)/(?:(\w*))?&quot;
     bangs   = $1
     match   = $2
     replace = $3
     flags   = $4
 
+    if bangs.length &gt; MAX_BANGS
+      privmsg params[0], &quot;#{nick}: I only support up to #{MAX_BANGS} !'s.&quot;
+      privmsg params[0], 'in bed' if rand(1000) == 42
+      next
+    end
+
     begin
       match = Regexp.new match
     rescue RegexpError =&gt; err
-      privmsg(params[0], 'RegexpError: ' + err.message)
+      privmsg params[0], &quot;RegexpError: #{err.message}&quot;
       next
     end
 
-    target = case bangs.length
-    when 0
+    target = if bangs.length == 0
       CHANNEL_MEMORY[channel][1] || ''
-    when 1..MAX_BANGS
-      CH_USER_MEMORY[channel][user][bangs.length-1] || ''
+    else
+      CH_USER_MEMORY[channel][nick][-bangs.length] || ''
     end
 
     if flags.chars.include? 'g'
@@ -92,17 +65,23 @@ IRC.on :privmsg do
       answer = target.sub(match, replace)
     end
 
-    if bangs.length &gt; 0 || CHANNEL_MEMORY[channel][0] == prefix.split('!').first
-      privmsg(params[0], prefix.split('!').first + ' meant: ' + answer)
+    if bangs.length &gt; 0 || CHANNEL_MEMORY[channel][0] == nick
+      privmsg(params[0], nick + ' meant: ' + answer)
     else
-      privmsg(params[0], prefix.split('!').first + ' thinks ' + CHANNEL_MEMORY[channel][0] + ' meant: ' + answer)
+      privmsg(params[0], nick + ' thinks ' + CHANNEL_MEMORY[channel][0] + ' meant: ' + answer)
     end
 
   else
-    CH_USER_MEMORY[channel] ||= {}
-    CH_USER_MEMORY[channel][user] ||= Backlog.new(MAX_BANGS)
-    CH_USER_MEMORY[channel][user] &lt;&lt; message
-    CHANNEL_MEMORY[channel] = [user, message]
+    if message =~ /^\x01(\S+) (.*)\x01$/
+      next unless $1 == 'ACTION'
+
+      message = &quot;* #{nick} #{$2}&quot;
+    end
+
+    CH_USER_MEMORY[channel][nick] &lt;&lt; message
+    CH_USER_MEMORY[channel][nick].unshift if CH_USER_MEMORY[channel][nick].length &gt; MAX_BANGS
+
+    CHANNEL_MEMORY[channel] = [nick, message]
   end
 end
 </diff>
      <filename>examples/regex_bot.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>62fd0cfcfdb9b4718e0dc171fce10e9c6f5833cb</id>
    </parent>
  </parents>
  <author>
    <name>Scott Olson</name>
    <email>scott@scott-olson.org</email>
  </author>
  <url>http://github.com/tsion/on_irc/commit/59984faec7f0e6c42e109810402dde56d3695a77</url>
  <id>59984faec7f0e6c42e109810402dde56d3695a77</id>
  <committed-date>2009-09-25T17:06:54-07:00</committed-date>
  <authored-date>2009-09-25T17:06:54-07:00</authored-date>
  <message>the regex bot should now ignore CTCPs and handle ACTIONs properly</message>
  <tree>b6e6981f5690318594f2b342c84ff53f19cd2af6</tree>
  <committer>
    <name>Scott Olson</name>
    <email>scott@scott-olson.org</email>
  </committer>
</commit>
