Changeset 5604d4bfb78ff357997bcce0ee3fd010cf7d9c8d
- 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
| r9125a2e |
r5604d4b |
|
| 18 | 18 | } |
|---|
| 19 | 19 | |
|---|
| 20 | | |
|---|
| 21 | 20 | def self.resolve(hostname) |
|---|
| 22 | 21 | res = {} |
|---|
| … | … | |
| 30 | 29 | end |
|---|
| 31 | 30 | |
|---|
| | 31 | class 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 |
|---|
| | 48 | end |
|---|
| | 49 | |
|---|
| 32 | 50 | class GeoIpPlugin < Plugin |
|---|
| 33 | 51 | def help(plugin, topic="") |
|---|
| … | … | |
| 35 | 53 | end |
|---|
| 36 | 54 | |
|---|
| | 55 | def initialize |
|---|
| | 56 | super |
|---|
| | 57 | |
|---|
| | 58 | @stack = Stack.new |
|---|
| | 59 | end |
|---|
| | 60 | |
|---|
| 37 | 61 | def whois(m) |
|---|
| | 62 | nick = m.whois[:nick].downcase |
|---|
| | 63 | |
|---|
| 38 | 64 | # 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) |
|---|
| 40 | 66 | |
|---|
| 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 |
|---|
| 45 | 73 | end |
|---|
| 46 | 74 | |
|---|
| 47 | | @nick, @source = nil |
|---|
| | 75 | @stack.clear(m.whois[:nick]) |
|---|
| 48 | 76 | end |
|---|
| 49 | 77 | |
|---|
| … | … | |
| 64 | 92 | |
|---|
| 65 | 93 | # 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 || |
|---|
| 67 | 95 | params[:input] =~ Resolv::IPv4::Regex |
|---|
| 68 | 96 | m.reply host2output(params[:input]) |
|---|
| … | … | |
| 70 | 98 | # assume input is a nick |
|---|
| 71 | 99 | else |
|---|
| 72 | | @source = m.replyto |
|---|
| 73 | | @nick = params[:input] |
|---|
| | 100 | nick = params[:input].downcase |
|---|
| 74 | 101 | |
|---|
| 75 | | @bot.whois(@nick) |
|---|
| | 102 | @stack[nick] << m.replyto |
|---|
| | 103 | @bot.whois(nick) |
|---|
| 76 | 104 | end |
|---|
| 77 | 105 | end |
|---|