X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frbot%2Fcore%2Fauth.rb;h=d54e8177495c962f6b4aa38185ee12395692ba88;hb=82ac675c1e0af29f276457dd7256ad0d800b9021;hp=1fec6e4b4530e0862ce476a472367fccb7efaf65;hpb=570d8535619cf3a9d20ca3d72e5176db2c4c8223;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git diff --git a/lib/rbot/core/auth.rb b/lib/rbot/core/auth.rb index 1fec6e4b..d54e8177 100644 --- a/lib/rbot/core/auth.rb +++ b/lib/rbot/core/auth.rb @@ -1,13 +1,27 @@ #-- vim:sw=2:et #++ - +# +# :title: rbot auth management from IRC +# +# Author:: Giuseppe "Oblomov" Bilotta +# Copyright:: (C) 2006,2007 Giuseppe Bilotta +# License:: GPL v2 class AuthModule < CoreBotModule def initialize super + + # The namespace migration causes each Irc::Auth::PermissionSet to be + # unrecoverable, and we have to rename their class name to + # Irc::Bot::Auth::PermissionSet + @registry.recovery = Proc.new { |val| + patched = val.sub("o:\035Irc::Auth::PermissionSet", "o:\042Irc::Bot::Auth::PermissionSet") + Marshal.restore(patched) + } + load_array(:default, true) - debug "initialized auth. Botusers: #{@bot.auth.save_array.inspect}" + debug "initialized auth. Botusers: #{@bot.auth.save_array.pretty_inspect}" end def save @@ -18,12 +32,12 @@ class AuthModule < CoreBotModule if @bot.auth.changed? @registry[key] = @bot.auth.save_array @bot.auth.reset_changed - debug "saved botusers (#{key}): #{@registry[key].inspect}" + debug "saved botusers (#{key}): #{@registry[key].pretty_inspect}" end end def load_array(key=:default, forced=false) - debug "loading botusers (#{key}): #{@registry[key].inspect}" + debug "loading botusers (#{key}): #{@registry[key].pretty_inspect}" @bot.auth.load_array(@registry[key], forced) if @registry.has_key?(key) end @@ -54,9 +68,9 @@ class AuthModule < CoreBotModule next end if "+-".include?(x[0]) - warns << ArgumentError.new("please do not use + or - in front of command #{x} when resetting") unless setting + warns << ArgumentError.new(_("please do not use + or - in front of command %{command} when resetting") % {:command => x}) unless setting else - warns << ArgumentError.new("+ or - expected in front of #{x}") if setting + warns << ArgumentError.new(_("+ or - expected in front of %{string}") % {:string => command}) if setting end cmds << x else # parse locations @@ -69,7 +83,7 @@ class AuthModule < CoreBotModule when false locs << x.gsub(/^here$/,'_').gsub(/^private$/,'?') else - warns << ArgumentError("#{x} doesn't look like a channel name") unless @bot.server.supports[:chantypes].include?(x[0]) + warns << ArgumentError.new(_("'%{string}' doesn't look like a channel name") % {:string => x}) unless @bot.server.supports[:chantypes].include?(x[0]) locs << x end unless want_more @@ -78,8 +92,8 @@ class AuthModule < CoreBotModule end end } - warns << "trailing comma" if want_more - warns << "you probably forgot a comma" unless last_idx == ar.length - 1 + warns << _("trailing comma") if want_more + warns << _("you probably forgot a comma") unless last_idx == ar.length - 1 return cmds, locs, warns end @@ -89,21 +103,21 @@ class AuthModule < CoreBotModule splits = params[:args] has_for = splits[-2] == "for" - return usage unless has_for + return usage(m) unless has_for begin user = @bot.auth.get_botuser(splits[-1].sub(/^all$/,"everyone")) rescue - return m.reply("couldn't find botuser #{splits[-1]}") + return m.reply(_("couldn't find botuser %{name}") % {:name => splits[-1]}) end - return m.reply("you can't change permissions for #{user.username}") if user == @bot.auth.botowner + return m.reply(_("you can't change permissions for %{username}") % {:username => user.username}) if user.owner? splits.slice!(-2,2) if has_for cmds, locs, warns = parse_args(splits, setting) errs = warns.select { |w| w.kind_of?(Exception) } unless errs.empty? - m.reply "couldn't satisfy your request: #{errs.join(',')}" + m.reply _("couldn't satisfy your request: %{errors}") % {:errors => errs.join(',')} return end @@ -140,9 +154,15 @@ class AuthModule < CoreBotModule def auth_view_perm(m, params) begin - user = @bot.auth.get_botuser(params[:user].sub(/^all$/,"everyone")) + if params[:user].nil? + user = get_botusername_for(m.source) + return m.reply(_("you are owner, you can do anything")) if user.owner? + else + user = @bot.auth.get_botuser(params[:user].sub(/^all$/,"everyone")) + return m.reply(_("owner can do anything")) if user.owner? + end rescue - return m.reply("couldn't find botuser #{params[:user]}") + return m.reply(_("couldn't find botuser %{name}") % {:name => params[:user]}) end perm = user.perm str = [] @@ -150,11 +170,11 @@ class AuthModule < CoreBotModule next if val.perm.empty? case k when :* - str << "on any channel: " + str << _("on any channel: ") when :"?" - str << "in private: " + str << _("in private: ") else - str << "on #{k}: " + str << _("on #{k}: ") end sub = [] val.perm.each { |cmd, bool| @@ -164,9 +184,10 @@ class AuthModule < CoreBotModule str.last << sub.join(', ') } if str.empty? - m.reply "no permissions set for #{user.username}" + m.reply _("no permissions set for %{user}") % {:user => user.username} else - m.reply "permissions for #{user.username}:: #{str.join('; ')}" + m.reply _("permissions for %{user}:: %{permissions}") % + { :user => user.username, :permissions => str.join('; ')} end end @@ -179,7 +200,12 @@ class AuthModule < CoreBotModule end def welcome(user) - "welcome, #{get_botusername_for(user)}" + _("welcome, %{user}") % {:user => get_botusername_for(user)} + end + + def auth_auth(m, params) + params[:botuser] = 'owner' + auth_login(m,params) end def auth_login(m, params) @@ -189,19 +215,18 @@ class AuthModule < CoreBotModule m.reply welcome(m.source) @bot.auth.set_changed else - m.reply "sorry, can't do" + m.reply _("sorry, can't do") end rescue => e - m.reply "couldn't login: #{e}" + m.reply _("couldn't login: %{exception}") % {:exception => e} raise end end def auth_autologin(m, params) u = do_autologin(m.source) - case u.username - when 'everyone' - m.reply "I couldn't find anything to let you login automatically" + if u.default? + m.reply _("I couldn't find anything to let you login automatically") else m.reply welcome(m.source) end @@ -212,67 +237,94 @@ class AuthModule < CoreBotModule end def auth_whoami(m, params) - rep = "" - # if m.public? - # rep << m.source.nick << ", " - # end - rep << "you are " - rep << get_botusername_for(m.source).gsub(/^everyone$/, "no one that I know").gsub(/^owner$/, "my boss") - m.reply rep + m.reply _("you are %{who}") % { + :who => get_botusername_for(m.source).gsub( + /^everyone$/, _("no one that I know")).gsub( + /^owner$/, _("my boss")) + } + end + + def auth_whois(m, params) + return auth_whoami(m, params) if !m.public? + u = m.channel.users[params[:user]] + + return m.reply("I don't see anyone named '#{params[:user]}' here") unless u + + m.reply _("#{params[:user]} is %{who}") % { + :who => get_botusername_for(u).gsub( + /^everyone$/, _("no one that I know")).gsub( + /^owner$/, _("my boss")) + } end def help(cmd, topic="") case cmd when "login" - return "login [] []: logs in to the bot as botuser with password . When using the full form, you must contact the bot in private. can be omitted if allows login-by-mask and your netmask is among the known ones. if is omitted too autologin will be attempted" + return _("login [] []: logs in to the bot as botuser with password . When using the full form, you must contact the bot in private. can be omitted if allows login-by-mask and your netmask is among the known ones. if is omitted too autologin will be attempted") when "whoami" - return "whoami: names the botuser you're linked to" + return _("whoami: names the botuser you're linked to") + when "who" + return _("who is : names the botuser is linked to") when /^permission/ case topic when "syntax" - return "a permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix" + return _("a permission is specified as module::path::to::cmd; when you want to enable it, prefix it with +; when you want to disable it, prefix it with -; when using the +reset+ command, do not use any prefix") + when "set", "reset", "[re]set", "(re)set" + return _("permissions [re]set [in ] for : sets or resets the permissions for botuser in channel (use ? to change the permissions for private addressing)") + when "view" + return _("permissions view [for ]: display the permissions for user ") else - return "permissions (re)set [in ] for : sets or resets the permissions for botuser in channel (use ? to change the permissions for private addressing)" + return _("permission topics: syntax, (re)set, view") end when "user" case topic when "show" - return "user show : shows info about the user; can be any of autologin, login-by-mask, netmasks" + return _("user show : shows info about the user; can be any of autologin, login-by-mask, netmasks") when /^(en|dis)able/ - return "user enable|disable : turns on or off (autologin, login-by-mask)" + return _("user enable|disable : turns on or off (autologin, login-by-mask)") when "set" - return "user set password : sets the user password to ; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long" + return _("user set password : sets the user password to ; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long") when "add", "rm" - return "user add|rm netmask : adds/removes netmask from the list of netmasks known to the botuser you're linked to" + return _("user add|rm netmask : adds/removes netmask from the list of netmasks known to the botuser you're linked to") when "reset" - return "user reset : resets to the default values. can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)" + return _("user reset : resets to the default values. can be +netmasks+ (the list will be emptied), +autologin+ or +login-by-mask+ (will be reset to the default value) or +password+ (a new one will be generated and you'll be told in private)") when "tell" - return "user tell the password for : contacts in private to tell him/her the password for " + return _("user tell the password for : contacts in private to tell him/her the password for ") when "create" - return "user create : create botuser named with password . The password can be omitted, in which case a random one will be generated. The should only contain alphanumeric characters and the underscore (_)" + return _("user create : create botuser named with password . The password can be omitted, in which case a random one will be generated. The should only contain alphanumeric characters and the underscore (_)") when "list" - return "user list : lists all the botusers" + return _("user list : lists all the botusers") when "destroy" - return "user destroy : destroys ; this function #{Bold}must#{Bold} be called in two steps. On the first call, no password must be specified: is then queued for destruction. On the second call, you must specify the correct password for , and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy +" + return _("user destroy : destroys ; this function %{highlight}must%{highlight} be called in two steps. On the first call, no password must be specified: is then queued for destruction. On the second call, you must specify the correct password for , and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy +") % {:highlight => Bold} else - return "user show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy" + return _("user topics: show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy") end + when "auth" + return _("auth : log in as the bot owner; other commands: login, whoami, permission syntax, permissions [re]set, permissions view, user, meet, hello") + when "meet" + return _("meet [as ]: creates a bot user for nick, calling it user (defaults to the nick itself)") + when "hello" + return _("hello: creates a bot user for the person issuing the command") else - return "#{name}: login, whoami, permission syntax, permissions, user" + return _("auth commands: auth, login, whoami, who, permission[s], user, meet, hello") end end def need_args(cmd) - "sorry, I need more arguments to #{cmd}" + _("sorry, I need more arguments to %{command}") % {:command => cmd} end def not_args(cmd, *stuff) - "I can only #{cmd} these: #{stuff.join(', ')}" + _("I can only %{command} these: %{arguments}") % + {:command => cmd, :arguments => stuff.join(', ')} end def set_prop(botuser, prop, val) k = prop.to_s.gsub("-","_") botuser.send( (k + "=").to_sym, val) + if prop == :password and botuser == @bot.auth.botowner + @bot.config.items[:'auth.password'].set_string(@bot.auth.botowner.password) + end end def reset_prop(botuser, prop) @@ -296,9 +348,12 @@ class AuthModule < CoreBotModule butarget = botuser has_for = splits[-2] == "for" - butarget = @bot.auth.get_botuser(splits[-1]) if has_for - return m.reply("you can't mess with #{butarget.username}") if butarget == @bot.auth.botowner && botuser != butarget - splits.slice!(-2,2) if has_for + if has_for + butarget = @bot.auth.get_botuser(splits[-1]) rescue nil + return m.reply(_("no such bot user %{user}") % {:user => splits[-1]}) unless butarget + splits.slice!(-2,2) + end + return m.reply(_("you can't mess with %{user}") % {:user => butarget.username}) if butarget.owner? && botuser != butarget bools = [:autologin, :"login-by-mask"] can_set = [:password] @@ -306,21 +361,25 @@ class AuthModule < CoreBotModule can_reset = bools + can_set + can_addrm can_show = can_reset + ["perms"] + begin case cmd.to_sym when :show - return "you can't see the properties of #{butarget.username}" if botuser != butarget and !botuser.permit?("auth::show::other") + return m.reply(_("you can't see the properties of %{user}") % + {:user => butarget.username}) if botuser != butarget && + !botuser.permit?("auth::show::other") case splits[1] when nil, "all" props = can_reset when "password" if botuser != butarget - return m.reply("no way I'm telling you the master password!") if butarget == @bot.auth.botowner - return m.reply("you can't ask for someone else's password") + return m.reply(_("no way I'm telling you the master password!")) if butarget == @bot.auth.botowner + return m.reply(_("you can't ask for someone else's password")) end - return m.reply("c'mon, you can't be asking me seriously to tell you the password in public!") if m.public? - return m.reply("the password for #{butarget.username} is #{butarget.password}") + return m.reply(_("c'mon, you can't be asking me seriously to tell you the password in public!")) if m.public? + return m.reply(_("the password for %{user} is %{password}") % + { :user => butarget.username, :password => butarget.password }) else props = splits[1..-1] end @@ -332,23 +391,24 @@ class AuthModule < CoreBotModule next if k == :password case k when *bools - str << "can" - str.last << "not" unless ask_bool_prop(butarget, k) - str.last << " #{k}" + if ask_bool_prop(butarget, k) + str << _("can %{action}") % {:action => k} + else + str << _("can not %{action}") % {:action => k} + end when :netmasks - str << "knows " if butarget.netmasks.empty? - str.last << "no netmasks" + str << _("knows no netmasks") else - str.last << butarget.netmasks.join(", ") + str << _("knows %{netmasks}") % {:netmasks => butarget.netmasks.join(", ")} end end } return m.reply("#{butarget.username} #{str.join('; ')}") when :enable, :disable - return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::other::default") - return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other") + return m.reply(_("you can't change the default user")) if butarget.default? && !botuser.permit?("auth::edit::other::default") + return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if butarget != botuser && !botuser.permit?("auth::edit::other") return m.reply(need_args(cmd)) unless splits[1] things = [] @@ -363,17 +423,21 @@ class AuthModule < CoreBotModule end } - m.reply "I ignored #{skipped.join(', ')} because " + not_args(cmd, *bools) unless skipped.empty? + m.reply(_("I ignored %{things} because %{reason}") % { + :things => skipped.join(', '), + :reason => not_args(cmd, *bools)}) unless skipped.empty? if things.empty? - m.reply "I haven't changed anything" + m.reply _("I haven't changed anything") else @bot.auth.set_changed return auth_manage_user(m, {:data => ["show"] + things + ["for", butarget.username] }) end when :set - return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default") - return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other") + return m.reply(_("you can't change the default user")) if + butarget.default? && !botuser.permit?("auth::edit::default") + return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if + butarget != botuser && !botuser.permit?("auth::edit::other") return m.reply(need_args(cmd)) unless splits[1] arg = splits[1].to_sym @@ -381,15 +445,17 @@ class AuthModule < CoreBotModule argarg = splits[2] return m.reply(need_args([cmd, splits[1]].join(" "))) unless argarg if arg == :password && m.public? - return m.reply("is that a joke? setting the password in public?") + return m.reply(_("is that a joke? setting the password in public?")) end set_prop(butarget, arg, argarg) @bot.auth.set_changed auth_manage_user(m, {:data => ["show", arg, "for", butarget.username] }) when :reset - return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default") - return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other") + return m.reply(_("you can't change the default user")) if + butarget.default? && !botuser.permit?("auth::edit::default") + return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if + butarget != botuser && !botuser.permit?("auth::edit::other") return m.reply(need_args(cmd)) unless splits[1] things = [] @@ -404,22 +470,28 @@ class AuthModule < CoreBotModule end } - m.reply "I ignored #{skipped.join(', ')} because " + not_args(cmd, *can_reset) unless skipped.empty? + m.reply(_("I ignored %{things} because %{reason}") % + { :things => skipped.join(', '), + :reason => not_args(cmd, *can_reset)}) unless skipped.empty? if things.empty? - m.reply "I haven't changed anything" + m.reply _("I haven't changed anything") else @bot.auth.set_changed - @bot.say m.source, "the password for #{butarget.username} is now #{butarget.password}" if things.include?("password") + @bot.say(m.source, _("the password for %{user} is now %{password}") % + {:user => butarget.username, :password => butarget.password}) if + things.include?("password") return auth_manage_user(m, {:data => (["show"] + things - ["password"]) + ["for", butarget.username]}) end when :add, :rm, :remove, :del, :delete - return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default") - return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other") + return m.reply(_("you can't change the default user")) if + butarget.default? && !botuser.permit?("auth::edit::default") + return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if + butarget != botuser && !botuser.permit?("auth::edit::other") arg = splits[1] if arg.nil? or arg !~ /netmasks?/ or splits[2].nil? - return m.reply("I can only add/remove netmasks. See +help user add+ for more instructions") + return m.reply(_("I can only add/remove netmasks. See +help user add+ for more instructions")) end method = cmd.to_sym == :add ? :add_netmask : :delete_netmask @@ -429,7 +501,9 @@ class AuthModule < CoreBotModule splits[2..-1].each { |mask| begin butarget.send(method, mask.to_irc_netmask(:server => @bot.server)) - rescue + rescue => e + debug "failed with #{e.message}" + debug e.backtrace.join("\n") failed << mask end } @@ -438,7 +512,48 @@ class AuthModule < CoreBotModule return auth_manage_user(m, {:data => ["show", "netmasks", "for", butarget.username] }) else - m.reply "sorry, I don't know how to #{m.message}" + m.reply _("sorry, I don't know how to %{request}") % {:request => m.message} + end + rescue => e + m.reply _("couldn't %{cmd}: %{exception}") % {:cmd => cmd, :exception => e} + end + end + + def auth_meet(m, params) + nick = params[:nick] + if !nick + # we are actually responding to a 'hello' command + unless m.botuser.transient? + m.reply @bot.lang.get('hello_X') % m.botuser + return + end + nick = m.sourcenick + irc_user = m.source + else + # m.channel is always an Irc::Channel because the command is either + # public-only 'meet' or private/public 'hello' which was handled by + # the !nick case, so this shouldn't fail + irc_user = m.channel.users[nick] + return m.reply("I don't see anyone named '#{nick}' here") unless irc_user + end + # BotUser name + buname = params[:user] || nick + begin + call_event(:botuser,:pre_perm, {:irc_user => irc_user, :bot_user => buname}) + met = @bot.auth.make_permanent(irc_user, buname) + @bot.auth.set_changed + call_event(:botuser,:post_perm, {:irc_user => irc_user, :bot_user => buname}) + m.reply @bot.lang.get('hello_X') % met + @bot.say nick, _("you are now registered as %{buname}. I created a random password for you : %{pass} and you can change it at any time by telling me 'user set password ' in private" % { + :buname => buname, + :pass => met.password + }) + rescue RuntimeError + # or can this happen for other cases too? + # TODO autologin if forced + m.reply _("but I already know %{buname}" % {:buname => buname}) + rescue => e + m.reply _("I had problems meeting %{nick}: %{e}" % { :nick => nick, :e => e }) end end @@ -447,45 +562,48 @@ class AuthModule < CoreBotModule begin botuser = @bot.auth.get_botuser(params[:botuser]) rescue - return m.reply("coudln't find botuser #{params[:botuser]})") + return m.reply(_("couldn't find botuser %{user}") % {:user => params[:botuser]}) end - m.reply "I'm not telling the master password to anyway, pal" if botuser == @bot.auth.botowner - msg = "the password for botuser #{botuser.username} is #{botuser.password}" + m.reply(_("I'm not telling the master password to anyway, pal")) if botuser == @bot.auth.botowner + msg = _("the password for botuser %{user} is %{password}") % + {:user => botuser.username, :password => botuser.password} @bot.say user, msg - @bot.say m.source, "I told #{user} that " + msg + @bot.say m.source, _("I told %{user} that %{message}") % {:user => user, :message => msg} end def auth_create_user(m, params) name = params[:name] password = params[:password] - return m.reply("are you nuts, creating a botuser with a publicly known password?") if m.public? and not password.nil? + return m.reply(_("are you nuts, creating a botuser with a publicly known password?")) if m.public? and not password.nil? begin bu = @bot.auth.create_botuser(name, password) @bot.auth.set_changed rescue => e - m.reply "failed to create #{name}: #{e}" + m.reply(_("failed to create %{user}: %{exception}") % {:user => name, :exception => e}) debug e.inspect + "\n" + e.backtrace.join("\n") return end - m.reply "created botuser #{bu.username}" + m.reply(_("created botuser %{user}") % {:user => bu.username}) end def auth_list_users(m, params) # TODO name regexp to filter results - list = @bot.auth.save_array.inject([]) { |list, x| list << x[:username] } - ['everyone', 'owner'] + list = @bot.auth.save_array.inject([]) { |list, x| ['everyone', 'owner'].include?(x[:username]) ? list : list << x[:username] } if defined?(@destroy_q) list.map! { |x| - @destroy_q.include?(x) ? x + " (queued for destruction)" : x + @destroy_q.include?(x) ? x + _(" (queued for destruction)") : x } end - return m.reply("I have no botusers other than the default ones") if list.empty? - return m.reply("botuser#{'s' if list.length > 1}: #{list.join(', ')}") + return m.reply(_("I have no botusers other than the default ones")) if list.empty? + return m.reply(n_("botuser: %{list}", "botusers: %{list}", list.length) % + {:list => list.join(', ')}) end def auth_destroy_user(m, params) @destroy_q = [] unless defined?(@destroy_q) buname = params[:name] - return m.reply("You can't destroy #{buname}") if ["everyone", "owner"].include?(buname) + return m.reply(_("You can't destroy %{user}") % {:user => buname}) if + ["everyone", "owner"].include?(buname) cancel = m.message.split[1] == 'cancel' password = params[:password] @@ -495,30 +613,32 @@ class AuthModule < CoreBotModule h } - return m.reply("no such botuser #{buname}") unless buser_hash.keys.include?(buname) + return m.reply(_("no such botuser %{user}") % {:user=>buname}) unless + buser_hash.keys.include?(buname) if cancel if @destroy_q.include?(buname) @destroy_q.delete(buname) - m.reply "#{buname} removed from the destruction queue" + m.reply(_("%{user} removed from the destruction queue") % {:user=>buname}) else - m.reply "#{buname} was not queued for destruction" + m.reply(_("%{user} was not queued for destruction") % {:user=>buname}) end return end if password.nil? if @destroy_q.include?(buname) - rep = "#{buname} already queued for destruction" + return m.reply(_("%{user} already queued for destruction, use %{highlight}user destroy %{user} %{highlight} to destroy it") % {:user=>buname, :highlight=>Bold}) else @destroy_q << buname - rep = "#{buname} queued for destruction" + return m.reply(_("%{user} queued for destruction, use %{highlight}user destroy %{user} %{highlight} to destroy it") % {:user=>buname, :highlight=>Bold}) end - return m.reply(rep + ", use #{Bold}user destroy #{buname} #{Bold} to destroy it") else begin - return m.reply("#{buname} is not queued for destruction yet") unless @destroy_q.include?(buname) - return m.reply("wrong password for #{buname}") unless buser_hash[buname][:password] == password + return m.reply(_("%{user} is not queued for destruction yet") % + {:user=>buname}) unless @destroy_q.include?(buname) + return m.reply(_("wrong password for %{user}") % + {:user=>buname}) unless buser_hash[buname][:password] == password buser_array.delete_if { |u| u[:username] == buname } @@ -526,9 +646,9 @@ class AuthModule < CoreBotModule @bot.auth.load_array(buser_array, true) @bot.auth.set_changed rescue => e - return m.reply("failed: #{e}") + return m.reply(_("failed: %{exception}") % {:exception => e}) end - return m.reply("botuser #{buname} destroyed") + return m.reply(_("botuser %{user} destroyed") % {:user => buname}) end end @@ -536,7 +656,8 @@ class AuthModule < CoreBotModule def auth_copy_ren_user(m, params) source = Auth::BotUser.sanitize_username(params[:source]) dest = Auth::BotUser.sanitize_username(params[:dest]) - return m.reply("please don't touch the default users") if (["everyone", "owner"] | [source, dest]).length < 4 + return m.reply(_("please don't touch the default users")) unless + (["everyone", "owner"] & [source, dest]).empty? buser_array = @bot.auth.save_array buser_hash = buser_array.inject({}) { |h, u| @@ -544,8 +665,10 @@ class AuthModule < CoreBotModule h } - return m.reply("no such botuser #{source}") unless buser_hash.keys.include?(source) - return m.reply("botuser #{dest} exists already") if buser_hash.keys.include?(dest) + return m.reply(_("no such botuser %{source}") % {:source=>source}) unless + buser_hash.keys.include?(source) + return m.reply(_("botuser %{dest} exists already") % {:dest=>dest}) if + buser_hash.keys.include?(dest) copying = m.message.split[1] == "copy" begin @@ -562,11 +685,17 @@ class AuthModule < CoreBotModule @bot.auth.load_array(buser_array, true) @bot.auth.set_changed + call_event(:botuser, copying ? :copy : :rename, :source => source, :dest => dest) rescue => e - return m.reply("failed: #{e}") + return m.reply(_("failed: %{exception}") % {:exception=>e}) + end + if copying + m.reply(_("botuser %{source} copied to %{dest}") % + {:source=>source, :dest=>dest}) + else + m.reply(_("botuser %{source} renamed to %{dest}") % + {:source=>source, :dest=>dest}) end - return m.reply("botuser #{source} copied to #{dest}") if copying - return m.reply("botuser #{source} renamed to #{dest}") end @@ -584,7 +713,7 @@ class AuthModule < CoreBotModule what.delete("all") - m.reply "selecting data to export ..." + m.reply _("selecting data to export ...") buser_array = @bot.auth.save_array buser_hash = buser_array.inject({}) { |h, u| @@ -600,7 +729,7 @@ class AuthModule < CoreBotModule } end - m.reply "preparing data for export ..." + m.reply _("preparing data for export ...") begin yaml_hash = {} we_want.each { |k, val| @@ -623,23 +752,23 @@ class AuthModule < CoreBotModule } } rescue => e - m.reply "failed to prepare data: #{e}" + m.reply _("failed to prepare data: %{exception}") % {:exception=>e} debug e.backtrace.dup.unshift(e.inspect).join("\n") return end - m.reply "exporting to #{exportfile} ..." + m.reply _("exporting to %{file} ...") % {:file=>exportfile} begin # m.reply yaml_hash.inspect File.open(exportfile, "w") do |file| file.puts YAML::dump(yaml_hash) end rescue => e - m.reply "failed to export users: #{e}" + m.reply _("failed to export users: %{exception}") % {:exception=>e} debug e.backtrace.dup.unshift(e.inspect).join("\n") return end - m.reply "done" + m.reply _("done") end def auth_import(m, params) @@ -656,18 +785,18 @@ class AuthModule < CoreBotModule what.delete("all") - m.reply "reading #{importfile} ..." + m.reply _("reading %{file} ...") % {:file=>importfile} begin yaml_hash = YAML::load_file(importfile) rescue => e - m.reply "failed to import from: #{e}" + m.reply _("failed to import from: %{exception}") % {:exception=>e} debug e.backtrace.dup.unshift(e.inspect).join("\n") return end # m.reply yaml_hash.inspect - m.reply "selecting data to import ..." + m.reply _("selecting data to import ...") if what.empty? we_want = yaml_hash @@ -677,7 +806,7 @@ class AuthModule < CoreBotModule } end - m.reply "parsing data from import ..." + m.reply _("parsing data from import ...") buser_hash = {} @@ -697,7 +826,7 @@ class AuthModule < CoreBotModule } } rescue => e - m.reply "failed to parse data: #{e}" + m.reply _("failed to parse data: %{exception}") % {:exception=>e} debug e.backtrace.dup.unshift(e.inspect).join("\n") return end @@ -717,7 +846,7 @@ class AuthModule < CoreBotModule @bot.auth.load_array(new_buser_array, true) @bot.auth.set_changed - m.reply "done" + m.reply _("done") end end @@ -738,25 +867,29 @@ auth.map "user create :name :password", :defaults => {:password => nil}, :auth_path => ':manage:' -auth.map "user cancel destroy :name :password", +auth.map "user [cancel] destroy :name :password", :action => 'auth_destroy_user', :defaults => { :password => nil }, :auth_path => ':manage::destroy:' -auth.map "user destroy :name :password", - :action => 'auth_destroy_user', - :defaults => { :password => nil }, - :auth_path => ':manage:' - -auth.map "user copy :source :dest", +auth.map "user copy :source [to] :dest", :action => 'auth_copy_ren_user', :auth_path => ':manage:' -auth.map "user rename :source :dest", +auth.map "user rename :source [to] :dest", :action => 'auth_copy_ren_user', :auth_path => ':manage:' +auth.map "meet :nick [as :user]", + :action => 'auth_meet', + :auth_path => 'user::manage', :private => false + +auth.map "hello", + :action => 'auth_meet', + :auth_path => 'user::manage::meet' + auth.default_auth("user::manage", false) +auth.default_auth("user::manage::meet::hello", true) auth.map "user tell :user the password for :botuser", :action => 'auth_tell_password', @@ -776,6 +909,15 @@ auth.map "whoami", :action => 'auth_whoami', :auth_path => '!*!' +auth.map "who is :user", + :action => 'auth_whois', + :auth_path => '!*!' + +auth.map "auth :password", + :action => 'auth_auth', + :public => false, + :auth_path => '!login!' + auth.map "login :botuser :password", :action => 'auth_login', :public => false, @@ -798,7 +940,7 @@ auth.map "permissions reset *args", :action => 'auth_edit_perm', :auth_path => ':edit::reset:' -auth.map "permissions view for :user", +auth.map "permissions view [for :user]", :action => 'auth_view_perm', :auth_path => '::'