]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/iplookup.rb
quiz: stop quizzes and timers on cleanup
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / iplookup.rb
index 715595e25ee07686fac757281f69002967b4c197..65867a501db399d42550dafc7077319488f3f8b5 100644 (file)
@@ -116,12 +116,12 @@ module ArinWhois
     def get_parsed_data
       return unless chunks = parse_chunks
 
-      results = split_array_at(parse_chunks) {|chunk|chunk.customer?}
-      results.map do |chunks|
+      results = split_array_at(chunks) {|chunk|chunk.customer?}
+      results.map do |data|
         {
-          :customer => chunks.select{|x|x.customer?}[0],
-          :net      => chunks.select{|x|x.network?}[0],
-          :contacts => chunks.select{|x|x.contact?}
+          :customer => data.select{|x|x.customer?}[0],
+          :net      => data.select{|x|x.network?}[0],
+          :contacts => data.select{|x|x.contact?}
         }
       end
     end
@@ -189,23 +189,25 @@ class IPLookupPlugin < Plugin
 
   def iplookup(m, params)
     reply = ""
-    if params[:domain]
+    if params[:domain].match(/^#{Regexp::Irc::HOSTADDR}$/)
+      ip = params[:domain]
+    else
       begin
         ip = Resolv.getaddress(params[:domain])
-        reply += "#{params[:domain]} | "
+        reply << "#{params[:domain]} | "
       rescue => e
         m.reply "#{e.message}"
         return
       end
-    else
-      ip = params[:ip]
     end
 
-    reply += ArinWhois.lookup_info(ip)
+    reply << ArinWhois.lookup_info(ip)
+
     m.reply reply
   end
 
   def userip(m, params)
+    m.reply "not implemented yet"
     #users = @channels[m.channel].users
     #m.reply "users = #{users.inspect}"
     #m.reply @bot.sendq("WHO #{params[:user]}")
@@ -214,9 +216,8 @@ class IPLookupPlugin < Plugin
 end
 
 plugin = IPLookupPlugin.new
-plugin.map 'iplookup :ip', :action => 'iplookup', :requirements => {:ip => /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/}
-plugin.map 'iplookup :domain', :action => 'iplookup', :requirements => {:domain => /^[a-z0-9\.\-]{4,255}$/i}
-plugin.map 'userip :user', :action => 'userip', :requirements => {:user => /\w+/}
+plugin.map 'iplookup :domain', :action => 'iplookup', :thread => true
+plugin.map 'userip :user', :action => 'userip', :requirements => {:user => /\w+/}, :thread => true
 
 
 if __FILE__ == $0