]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/botuser.rb
fix: restore logging of session start/end
[user/henk/code/ruby/rbot.git] / lib / rbot / botuser.rb
index c77db4a54817f61ac939e06fff0be9f61aeb787a..97bab93cc34545c3ed4c875209107eec3dd2624c 100644 (file)
@@ -4,8 +4,6 @@
 #
 # rbot user management
 # Author:: Giuseppe Bilotta (giuseppe.bilotta@gmail.com)
-# Copyright:: Copyright (c) 2006 Giuseppe Bilotta
-# License:: GPLv2
 
 require 'singleton'
 require 'set'
@@ -26,7 +24,7 @@ require 'rbot/maskdb'
 #     }
 #   }
 # end
-# 
+#
 
 module Irc
 class Bot
@@ -37,7 +35,8 @@ class Bot
   module Auth
 
     Config.register Config::StringValue.new( 'auth.password',
-      :default => 'rbotauth', :wizard => true,
+      :default => [*?a..?z,*?A..?Z,*?0..?9].sample(8).join, :store_default => true,
+      :wizard => true,
       :on_change => Proc.new {|bot, v| bot.auth.botowner.password = v},
       :desc => _('Password for the bot owner'))
     Config.register Config::BooleanValue.new( 'auth.login_by_mask',
@@ -92,8 +91,8 @@ class Bot
       #
       def initialize(cmd)
         cmdpath = sanitize_command_path(cmd).split('::')
-        seq = cmdpath.inject(["*"]) { |list, cmd|
-          list << (list.length > 1 ? list.last + "::" : "") + cmd
+        seq = cmdpath.inject(["*"]) { |list, cc|
+          list << (list.length > 1 ? list.last + "::" : "") + cc
         }
         @path = seq.map { |k|
           k.to_sym
@@ -240,6 +239,7 @@ class Bot
       attr_reader :password
       attr_reader :netmasks
       attr_reader :perm
+      attr_reader :perm_temp
       attr_writer :login_by_mask
       attr_writer :transient
 
@@ -317,6 +317,7 @@ class Bot
         raise "must provide a usable mask for transient BotUser #{@username}" if @transient and @netmasks.empty?
 
         @perm = {}
+        @perm_temp = {}
       end
 
       # Inspection
@@ -327,6 +328,7 @@ class Bot
         str << " @username=#{@username.inspect}"
         str << " @netmasks=#{@netmasks.inspect}"
         str << " @perm=#{@perm.inspect}"
+        str << " @perm_temp=#{@perm_temp.inspect}" unless @perm_temp.empty?
         str << " @login_by_mask=#{@login_by_mask}"
         str << " @autologin=#{@autologin}"
         str << ">"
@@ -426,6 +428,20 @@ class Bot
         set_permission(cmd, nil, chan)
       end
 
+      # Sets the temporary permission for command _cmd_ to _val_ on channel _chan_
+      #
+      def set_temp_permission(cmd, val, chan="*")
+        k = chan.to_s.to_sym
+        @perm_temp[k] = PermissionSet.new unless @perm_temp.has_key?(k)
+        @perm_temp[k].set_permission(cmd, val)
+      end
+
+      # Resets the temporary permission for command _cmd_ on channel _chan_
+      #
+      def reset_temp_permission(cmd, chan ="*")
+        set_temp_permission(cmd, nil, chan)
+      end
+
       # Checks if BotUser is allowed to do something on channel _chan_,
       # or on all channels if _chan_ is nil
       #
@@ -436,8 +452,9 @@ class Bot
           k = :*
         end
         allow = nil
-        if @perm.has_key?(k)
-          allow = @perm[k].permit?(cmd)
+        pt = @perm.merge @perm_temp
+        if pt.has_key?(k)
+          allow = pt[k].permit?(cmd)
         end
         return allow
       end
@@ -856,7 +873,7 @@ class Bot
         if user.class <= BotUser
           botuser = user
         else
-          botuser = irc_to_botuser(user)
+          botuser = user.botuser
         end
         cmd = cmdtxt.to_irc_auth_command