]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/nickserv.rb
* (plugins/translator) fixed a diagnostic message
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / nickserv.rb
index 0e5f2e8a2bb9abc4f3ee19d83cd75860346c47d9..b89e61d96489dcccf23b3c433f4af01a2d13c890 100644 (file)
@@ -1,21 +1,49 @@
+#-- vim:sw=2:et
+#++
+#
+# :title: Nickserv management plugin for rbot
+#
+# Author:: Tom Gilbert (giblet) <tom@linuxbrit.co.uk>
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>
+#
+# Copyright:: (C) 2002-2005 Tom Gilbert
+# Copyright:: (C) 2006 Tom Gilbert, Giuseppe Bilotta
+# Copyright:: (C) 2006-2007 Giuseppe Bilotta
+#
 # Automatically lookup nicks in @registry and identify when asked
+#
 # Takes over proper nick if required and nick is registered
-# TODO allow custom IDENTIFY and GHOST names
-# TODO instead of nickserv.wait it would be ideal if we could just
-# set up "don't send further commands until you receive this particular message"
+
+# TODO:: allow custom IDENTIFY and GHOST names
+#
+# FIXME:: identified? status returns false after a rescan, even if the bot
+#         previously identified successfully
 
 class NickServPlugin < Plugin
   
   BotConfig.register BotConfigStringValue.new('nickserv.name',
     :default => "nickserv", :requires_restart => false,
     :desc => "Name of the nick server (all lowercase)")
+
   BotConfig.register BotConfigStringValue.new('nickserv.ident_request',
     :default => "IDENTIFY", :requires_restart => false,
     :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_ident_request", v },
     :desc => "String to look for to see if the nick server is asking us to identify")
+  BotConfig.register BotConfigStringValue.new('nickserv.nick_avail',
+    :default => "not (currently )?online|killed|recovered|disconnesso|libero",
+    :requires_restart => false,
+    :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_nick_avail", v },
+    :desc => "String to look for to see if the nick server is informing us that our nick is now available")
+  BotConfig.register BotConfigStringValue.new('nickserv.identified_string',
+    :default => "(Password|Contrase|Mot de passe).+(acce[pt]t|r[ie]cog?n).+(identif|r[ie]cog?n)",
+    :requires_restart => false,
+    :on_change => Proc.new { |bot, v| bot.plugins.delegate "set_identified_string", v },
+    :desc => "String to look for to see if the nick server is informing us that we have identified successfully")
+
   BotConfig.register BotConfigBooleanValue.new('nickserv.wants_nick',
     :default => false, :requires_restart => false,
     :desc => "Set to false if the nick server doesn't expect the nick as a parameter in the identify command")
+
   BotConfig.register BotConfigIntegerValue.new('nickserv.wait',
     :default => 30, :validate => Proc.new { |v| v > 0 }, :requires_restart => false,
     :desc => "Seconds to wait after sending a message to nickserv, e.g. after ghosting")
@@ -36,18 +64,21 @@ class NickServPlugin < Plugin
   end
   
   def genpasswd
-    # generate a random password
-    passwd = ""
-    8.times do
-      passwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr
-    end
-    return passwd
+    return Irc::Auth.random_password
   end
 
   def set_ident_request(val)
     @ident_request = Regexp.new(val)
   end
 
+  def set_nick_avail(val)
+    @nick_avail = Regexp.new(val)
+  end
+
+  def set_identified_string(val)
+    @identified_string = Regexp.new(val)
+  end
+
   def initialize
     super
     # this plugin only wants to store strings!
@@ -60,6 +91,9 @@ class NickServPlugin < Plugin
       end
     end
     set_ident_request(@bot.config['nickserv.ident_request'])
+    set_nick_avail(@bot.config['nickserv.nick_avail'])
+    set_identified_string(@bot.config['nickserv.identified_string'])
+    @identified = false
   end
 
   # Returns the nickserv name
@@ -135,34 +169,38 @@ class NickServPlugin < Plugin
   end
   
   def connect
+    @identified = false
     do_identify
   end
   
   def nicktaken(nick)
     if @registry.has_key?(nick)
       ns_say "GHOST #{nick} #{@registry[nick]}"
-      if do_identify nick
-        sleep @bot.config['nickserv.wait']
-        @bot.nickchg nick
-        # We need to wait after changing nick, otherwise the server
-        # might refuse to execute further commangs, e.g. subsequent JOIN
-        # commands until the nick has changed.
-        sleep @bot.config['nickserv.wait']
-      else
-        debug "Failed to identify for nick #{nick}, cannot take over"
-      end
     end
   end
 
   def listen(m)
     return unless(m.kind_of? NoticeMessage)
+    return unless m.source.downcase == ns_nick.downcase
 
-    if (m.sourcenick.downcase == ns_nick.downcase && m.message =~ @ident_request)
+    case m.message
+    when @ident_request
       debug "nickserv asked us to identify for nick #{@bot.nick}"
       do_identify
+    when @nick_avail
+      debug "our nick seems to be free now"
+      @bot.nickchg @bot.config['irc.nick']
+    when @identified_string
+      debug "we identified successfully to nickserv"
+      @identified = true
+      @bot.plugins.delegate('identified')
     end
   end
 
+  def identified?
+    return @identified
+  end
+
 end
 plugin = NickServPlugin.new
 plugin.map 'nickserv password [:nick] :passwd', :action => "password"