#
# rbot user management
# Author:: Giuseppe Bilotta (giuseppe.bilotta@gmail.com)
-# Copyright:: Copyright (c) 2006 Giuseppe Bilotta
-# License:: GPLv2
require 'singleton'
require 'set'
# }
# }
# end
-#
+#
module Irc
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',
#
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
attr_reader :password
attr_reader :netmasks
attr_reader :perm
+ attr_reader :perm_temp
attr_writer :login_by_mask
attr_writer :transient
raise "must provide a usable mask for transient BotUser #{@username}" if @transient and @netmasks.empty?
@perm = {}
+ @perm_temp = {}
end
# Inspection
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 << ">"
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
#
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
if user.class <= BotUser
botuser = user
else
- botuser = irc_to_botuser(user)
+ botuser = user.botuser
end
cmd = cmdtxt.to_irc_auth_command