]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/botuser.rb
Relocate help strings to proper locations, add help for 'mode' command
[user/henk/code/ruby/rbot.git] / lib / rbot / botuser.rb
index 7daaf66e9cf7d3baf3cb8d003618e67d71ccf6d1..bed2b627cb59e9a36ea3a0ca1757f6771ecf88e8 100644 (file)
@@ -34,8 +34,8 @@ module Irc
     #\r
     def Auth.random_password(l=8)\r
       pwd = ""\r
-      8.times do\r
-        pwd += (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr\r
+      l.times do\r
+        pwd << (rand(26) + (rand(2) == 0 ? 65 : 97) ).chr\r
       end\r
       return pwd\r
     end\r
@@ -101,6 +101,16 @@ class String
 end\r
 \r
 \r
+class Symbol\r
+\r
+  # Returns an Irc::Auth::Comand from the receiver\r
+  def to_irc_auth_command\r
+    Irc::Auth::Command.new(self)\r
+  end\r
+\r
+end\r
+\r
+\r
 module Irc\r
 \r
 \r
@@ -160,6 +170,12 @@ module Irc
     end\r
 \r
 \r
+    # This is the error that gets raised when an invalid password is met\r
+    #\r
+    class InvalidPassword < RuntimeError\r
+    end\r
+\r
+\r
     # This is the basic class for bot users: they have a username, a password,\r
     # a list of netmasks to match against, and a list of permissions.\r
     #\r
@@ -247,18 +263,19 @@ module Irc
       # This method sets the password if the proposed new password\r
       # is valid\r
       def password=(pwd=nil)\r
-        if pwd\r
+        pass = pwd.to_s\r
+        if pass.empty?\r
+          reset_password\r
+        else\r
           begin\r
-            raise InvalidPassword, "#{pwd} contains invalid characters" if pwd !~ /^[A-Za-z0-9]+$/\r
-            raise InvalidPassword, "#{pwd} too short" if pwd.length < 4\r
-            @password = pwd\r
+            raise InvalidPassword, "#{pass} contains invalid characters" if pass !~ /^[\x21-\x7e]+$/\r
+            raise InvalidPassword, "#{pass} too short" if pass.length < 4\r
+            @password = pass\r
           rescue InvalidPassword => e\r
             raise e\r
           rescue => e\r
-            raise InvalidPassword, "Exception #{e.inspect} while checking #{pwd}"\r
+            raise InvalidPassword, "Exception #{e.inspect} while checking #{pass.inspect} (#{pwd.inspect})"\r
           end\r
-        else\r
-          reset_password\r
         end\r
       end\r
 \r
@@ -589,7 +606,7 @@ module Irc
         k = n.to_sym\r
         raise "No such BotUser #{n}" unless include?(k)\r
         if @botusers.has_key?(ircuser)\r
-          return true if @botusers[ircuser].username = n\r
+          return true if @botusers[ircuser].username == n\r
           # TODO\r
           # @botusers[ircuser].logout(ircuser)\r
         end\r