X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=lib%2Frbot%2Fbotuser.rb;h=97bab93cc34545c3ed4c875209107eec3dd2624c;hb=40ba5f69f763c47a4cd50439cc8c9937aab80dc4;hp=c77db4a54817f61ac939e06fff0be9f61aeb787a;hpb=6f9bfa43ac907700fcba394e0f6b9d987b1192fb;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/botuser.rb b/lib/rbot/botuser.rb index c77db4a5..97bab93c 100644 --- a/lib/rbot/botuser.rb +++ b/lib/rbot/botuser.rb @@ -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