Changeset 5604d4bfb78ff357997bcce0ee3fd010cf7d9c8d

Show
Ignore:
Timestamp:
08/11/08 21:29:18 (3 months ago)
Author:
Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
git-committer:
Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1218475758 +0200
git-parent:

[9125a2e6d1ef8af8d380da3766c704f9028dec69]

git-author:
Raine Virta <rane@kapsi.fi> 1218475191 +0300
Message:

geoip plugin: now stacking whois requests to prevent overlaps

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • data/rbot/plugins/geoip.rb

    r9125a2e r5604d4b  
    1818  } 
    1919 
    20  
    2120  def self.resolve(hostname) 
    2221    res = {} 
     
    3029end 
    3130 
     31class Stack 
     32  def initialize 
     33    @hash = {} 
     34  end 
     35 
     36  def [](nick) 
     37    @hash[nick] = [] unless @hash[nick] 
     38    @hash[nick] 
     39  end 
     40 
     41  def has_nick?(nick) 
     42    @hash.has_key?(nick) 
     43  end 
     44 
     45  def clear(nick) 
     46    @hash.delete(nick) 
     47  end 
     48end 
     49 
    3250class GeoIpPlugin < Plugin 
    3351  def help(plugin, topic="") 
     
    3553  end 
    3654 
     55  def initialize 
     56    super 
     57 
     58    @stack = Stack.new 
     59  end 
     60 
    3761  def whois(m) 
     62    nick = m.whois[:nick].downcase 
     63 
    3864    # need to see if the whois reply was invoked by this plugin 
    39     return unless m.whois[:nick] == @nick 
     65    return unless @stack.has_nick?(nick) 
    4066 
    41     if m.target 
    42       @bot.say @source, host2output(m.target.host, m.target.nick) 
    43     else 
    44       @bot.say @source, "no such user on "+@bot.server.hostname.split(".")[-2] 
     67    @stack[nick].each do |source| 
     68      if m.target 
     69        @bot.say source, host2output(m.target.host, m.target.nick) 
     70      else 
     71        @bot.say source, "no such user on "+@bot.server.hostname.split(".")[-2] 
     72      end 
    4573    end 
    4674 
    47     @nick, @source = nil 
     75    @stack.clear(m.whois[:nick]) 
    4876  end 
    4977 
     
    6492 
    6593      # input is a host name or an IP 
    66       if params[:input] =~ /[a-z0-9\-]+(?:\.[a-z0-9\-]+)*\.[a-z]{2,3}/i || 
     94      if params[:input] =~ /[a-z0-9\-]+(?:\.[a-z0-9\-]+)*\.[a-z]{2,4}/i || 
    6795         params[:input] =~ Resolv::IPv4::Regex 
    6896        m.reply host2output(params[:input]) 
     
    7098      # assume input is a nick 
    7199      else 
    72         @source = m.replyto 
    73         @nick   = params[:input] 
     100        nick = params[:input].downcase 
    74101 
    75         @bot.whois(@nick) 
     102        @stack[nick] << m.replyto 
     103        @bot.whois(nick) 
    76104      end 
    77105    end