]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Fix some bugs when setting permissions; introduce the new 'permissions view for ...
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 6 Aug 2006 17:40:21 +0000 (17:40 +0000)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Sun, 6 Aug 2006 17:40:21 +0000 (17:40 +0000)
lib/rbot/botuser.rb
lib/rbot/core/auth.rb

index 952776d818c8a80cf1bcb4fb3d1c89ecd53f9772..3363d5835f4dff3faf0fb122a2d265e0c812e104 100644 (file)
@@ -110,6 +110,7 @@ module Irc
     # This class describes a permission set\r
     class PermissionSet\r
 \r
+      attr_reader :perm\r
       # Create a new (empty) PermissionSet\r
       #\r
       def initialize\r
index 5662c119eb318af31a24ce0e7574f09b75619916..2d8b00d0fbc7728bc5aa56e5c876e8e06064abe7 100644 (file)
@@ -72,7 +72,7 @@ class AuthModule < CoreBotModule
           warns << ArgumentError("#{x} doesn't look like a channel name") unless @bot.server.supports[:chantypes].include?(x[0])\r
           locs << x\r
         end\r
-        unless wants_more\r
+        unless want_more\r
           last_idx = i\r
           break\r
         end\r
@@ -94,7 +94,7 @@ class AuthModule < CoreBotModule
     begin\r
       user = @bot.auth.get_botuser(splits[-1].sub(/^all$/,"everyone"))\r
     rescue\r
-      return m.reply("couldn't find botuser #{user}")\r
+      return m.reply("couldn't find botuser #{splits[-1]}")\r
     end\r
     return m.reply("you can't change permissions for #{user.username}") if user == @bot.auth.botowner\r
     splits.slice!(-2,2) if has_for\r
@@ -139,6 +139,35 @@ class AuthModule < CoreBotModule
   end\r
 \r
   def auth_view_perm(m, params)\r
+    begin\r
+      user = @bot.auth.get_botuser(params[:user].sub(/^all$/,"everyone"))\r
+    rescue\r
+      return m.reply("couldn't find botuser #{params[:user]}")\r
+    end\r
+    perm = user.perm\r
+    str = []\r
+    perm.each { |k, val|\r
+      next if val.perm.empty?\r
+      case k\r
+      when :*\r
+        str << "on any channel: "\r
+      when :"?"\r
+        str << "in private: "\r
+      else\r
+        str << "on #{k}: "\r
+      end\r
+      sub = []\r
+      val.perm.each { |cmd, bool|\r
+        sub << (bool ? "+" : "-")\r
+        sub.last << cmd.to_s\r
+      }\r
+      str.last << sub.join(', ')\r
+    }\r
+    if str.empty?\r
+      m.reply "no permissions set for #{user.username}"\r
+    else\r
+      m.reply "permissions for #{user.username}:: #{str.join('; ')}"\r
+    end\r
   end\r
 \r
   def get_botuser_for(user)\r
@@ -684,5 +713,9 @@ auth.map "permissions reset *args",
   :action => 'auth_edit_perm',\r
   :auth_path => ':edit::reset:'\r
 \r
+auth.map "permissions view for :user",\r
+  :action => 'auth_view_perm',\r
+  :auth_path => '::'\r
+\r
 auth.default_auth('*', false)\r
 \r