]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - data/rbot/plugins/nickserv.rb
new weather plugin that uses weatherunderground.com mobile interface. can be called...
[user/henk/code/ruby/rbot.git] / data / rbot / plugins / nickserv.rb
index 9ff79f084d8215f9bd1d2ccc50475cdbdc17c87a..720f3b3a9f15eb5a56680c5d54091b1a0f55cfd0 100644 (file)
@@ -7,8 +7,8 @@
 class NickServPlugin < Plugin
   
   BotConfig.register BotConfigStringValue.new('nickserv.name',
-    :default => "NickServ", :requires_restart => false,
-    :desc => "Name of the nick server")
+    :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 },
@@ -25,7 +25,7 @@ class NickServPlugin < Plugin
     when ""
       return "nickserv plugin: handles nickserv protected IRC nicks. topics password, register, identify, listnicks"
     when "password"
-      return "nickserv password <nick> <passwd>: remember the password for nick <nick> and use it to identify in future"
+      return "nickserv password [<nick>] <passwd>: remember the password for nick <nick> and use it to identify in future"
     when "register"
       return "nickserv register [<password> [<email>]]: register the current nick, choosing a random password unless <password> is supplied - current nick must not already be registered for this to work. Also specify email if required by your services"
     when "identify"
@@ -62,8 +62,25 @@ class NickServPlugin < Plugin
     set_ident_request(@bot.config['nickserv.ident_request'])
   end
 
+  # Returns the nickserv name
+  def ns_nick
+    @bot.config['nickserv.name']
+  end
+
+  # say something to nickserv
+  def ns_say(msg)
+    @bot.say ns_nick, msg
+  end
+
   def password(m, params)
-    @registry[params[:nick]] = params[:passwd]
+    nick = params[:nick] || @bot.nick
+    passwd = params[:passwd]
+    if nick == @bot.nick
+      ns_say "SET PASSWORD #{passwd}"
+    else
+      m.reply "I'm only changing this in my database, I won't inform #{ns_nick} of the change"
+    end
+    @registry[nick] = passwd
     m.okay
   end
 
@@ -71,7 +88,7 @@ class NickServPlugin < Plugin
     passwd = params[:passwd] ? params[:passwd] : genpasswd
     message = "REGISTER #{passwd}"
     message += " #{params[:email]}" if params[:email]
-    @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], message
+    ns_say message
     @registry[@bot.nick] = passwd
     m.okay
   end
@@ -89,10 +106,10 @@ class NickServPlugin < Plugin
   def do_identify(nick=@bot.nick)
     if @registry.has_key?(nick)
       if @bot.config['nickserv.wants_nick']
-        @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], "IDENTIFY #{nick} #{@registry[nick]}"
+        ns_say "IDENTIFY #{nick} #{@registry[nick]}"
       else
         if nick == @bot.nick
-          @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], "IDENTIFY #{@registry[nick]}"
+          ns_say "IDENTIFY #{@registry[nick]}"
         else
           # We cannot identify for different nicks if we can't use the nickname ...
           return false
@@ -100,14 +117,20 @@ class NickServPlugin < Plugin
       end
       return true
     end
-    return false
+    return nil
   end
 
   def identify(m, params)
-    if do_identify
+    ided = do_identify
+    case ided
+    when true
       m.okay
-    else
+    when false
+      m.reply "I cannot identify for a this nick"
+    when nil
       m.reply "I dunno the nickserv password for the nickname #{@bot.nick} :("
+    else
+      m.reply "uh ... something went wrong ..."
     end
   end
   
@@ -117,7 +140,7 @@ class NickServPlugin < Plugin
   
   def nicktaken(nick)
     if @registry.has_key?(nick)
-      @bot.sendmsg "PRIVMSG", @bot.config['nickserv.name'], "GHOST #{nick} #{@registry[nick]}"
+      ns_say "GHOST #{nick} #{@registry[nick]}"
       if do_identify nick
         sleep @bot.config['nickserv.wait']
         @bot.nickchg nick
@@ -134,7 +157,7 @@ class NickServPlugin < Plugin
   def listen(m)
     return unless(m.kind_of? NoticeMessage)
 
-    if (m.sourcenick == @bot.config['nickserv.name'] && m.message =~ @ident_request)
+    if (m.sourcenick == ns_nick && m.message =~ @ident_request)
       debug "nickserv asked us to identify for nick #{@bot.nick}"
       do_identify
     end
@@ -142,8 +165,11 @@ class NickServPlugin < Plugin
 
 end
 plugin = NickServPlugin.new
-plugin.map 'nickserv password :nick :passwd', :action => "password"
+plugin.map 'nickserv password [:nick] :passwd', :action => "password"
 plugin.map 'nickserv register :passwd :email', :action => 'nick_register',
            :defaults => {:passwd => false, :email => false}
 plugin.map 'nickserv listnicks', :action => "listnicks"
 plugin.map 'nickserv identify', :action => "identify"
+
+plugin.default_auth('*', false)
+