#-- vim:sw=2:et\r
#++\r
-\r
+#\r
+# :title: rbot auth management from IRC\r
+#\r
+# Author:: Giuseppe "Oblomov" Bilotta <giuseppe.bilotta@gmail.com>\r
+# Copyright:: (C) 2006,2007 Giuseppe Bilotta\r
+# License:: GPL v2\r
\r
class AuthModule < CoreBotModule\r
\r
def initialize\r
super\r
load_array(:default, true)\r
- debug "initialized auth. Botusers: #{@bot.auth.save_array.inspect}"\r
+ debug "initialized auth. Botusers: #{@bot.auth.save_array.pretty_inspect}"\r
end\r
\r
def save\r
if @bot.auth.changed?\r
@registry[key] = @bot.auth.save_array\r
@bot.auth.reset_changed\r
- debug "saved botusers (#{key}): #{@registry[key].inspect}"\r
+ debug "saved botusers (#{key}): #{@registry[key].pretty_inspect}"\r
end\r
end\r
\r
def load_array(key=:default, forced=false)\r
- debug "loading botusers (#{key}): #{@registry[key].inspect}"\r
+ debug "loading botusers (#{key}): #{@registry[key].pretty_inspect}"\r
@bot.auth.load_array(@registry[key], forced) if @registry.has_key?(key)\r
end\r
\r
next\r
end\r
if "+-".include?(x[0])\r
- warns << ArgumentError.new("please do not use + or - in front of command #{x} when resetting") unless setting\r
+ warns << ArgumentError.new(_("please do not use + or - in front of command %{command} when resetting") % {:command => x}) unless setting\r
else\r
- warns << ArgumentError.new("+ or - expected in front of #{x}") if setting\r
+ warns << ArgumentError.new(_("+ or - expected in front of %{string}") % {:string => command}) if setting\r
end\r
cmds << x\r
else # parse locations\r
when false\r
locs << x.gsub(/^here$/,'_').gsub(/^private$/,'?')\r
else\r
- warns << ArgumentError("#{x} doesn't look like a channel name") unless @bot.server.supports[:chantypes].include?(x[0])\r
+ warns << ArgumentError.new(_("'%{string}' doesn't look like a channel name") % {:string => x}) unless @bot.server.supports[:chantypes].include?(x[0])\r
locs << x\r
end\r
unless want_more\r
end\r
end\r
}\r
- warns << "trailing comma" if want_more\r
- warns << "you probably forgot a comma" unless last_idx == ar.length - 1\r
+ warns << _("trailing comma") if want_more\r
+ warns << _("you probably forgot a comma") unless last_idx == ar.length - 1\r
return cmds, locs, warns\r
end\r
\r
splits = params[:args]\r
\r
has_for = splits[-2] == "for"\r
- return usage unless has_for\r
+ return usage(m) unless has_for\r
\r
begin\r
user = @bot.auth.get_botuser(splits[-1].sub(/^all$/,"everyone"))\r
rescue\r
- return m.reply("couldn't find botuser #{splits[-1]}")\r
+ return m.reply(_("couldn't find botuser %{name}") % {:name => splits[-1]})\r
end\r
- return m.reply("you can't change permissions for #{user.username}") if user == @bot.auth.botowner\r
+ return m.reply(_("you can't change permissions for %{username}") % {:username => user.username}) if user == @bot.auth.botowner\r
splits.slice!(-2,2) if has_for\r
\r
cmds, locs, warns = parse_args(splits, setting)\r
errs = warns.select { |w| w.kind_of?(Exception) }\r
\r
unless errs.empty?\r
- m.reply "couldn't satisfy your request: #{errs.join(',')}"\r
+ m.reply _("couldn't satisfy your request: %{errors}") % {:errors => errs.join(',')}\r
return\r
end\r
\r
begin\r
if params[:user].nil?\r
user = get_botusername_for(m.source)\r
- return m.reply("you are owner, you can do anything") if user == @bot.auth.botwoner\r
+ return m.reply(_("you are owner, you can do anything")) if user == @bot.auth.botwoner\r
else\r
user = @bot.auth.get_botuser(params[:user].sub(/^all$/,"everyone"))\r
- return m.reply("owner can do anything") if user.username == "owner" \r
+ return m.reply(_("owner can do anything")) if user.username == "owner"\r
end\r
rescue\r
- return m.reply("couldn't find botuser #{params[:user]}")\r
+ return m.reply(_("couldn't find botuser %{name}") % {:name => params[:user]})\r
end\r
perm = user.perm\r
str = []\r
next if val.perm.empty?\r
case k\r
when :*\r
- str << "on any channel: "\r
+ str << _("on any channel: ")\r
when :"?"\r
- str << "in private: "\r
+ str << _("in private: ")\r
else\r
- str << "on #{k}: "\r
+ str << _("on #{k}: ")\r
end\r
sub = []\r
val.perm.each { |cmd, bool|\r
str.last << sub.join(', ')\r
}\r
if str.empty?\r
- m.reply "no permissions set for #{user.username}"\r
+ m.reply _("no permissions set for %{user}") % {:user => user.username}\r
else\r
- m.reply "permissions for #{user.username}:: #{str.join('; ')}"\r
+ m.reply _("permissions for %{user}:: %{permissions}") %\r
+ { :user => user.username, :permissions => str.join('; ')}\r
end\r
end\r
\r
end\r
\r
def welcome(user)\r
- "welcome, #{get_botusername_for(user)}"\r
+ _("welcome, %{user}") % {:user => get_botusername_for(user)}\r
end\r
\r
def auth_auth(m, params)\r
m.reply welcome(m.source)\r
@bot.auth.set_changed\r
else\r
- m.reply "sorry, can't do"\r
+ m.reply _("sorry, can't do")\r
end\r
rescue => e\r
- m.reply "couldn't login: #{e}"\r
+ m.reply _("couldn't login: %{exception}") % {:exception => e}\r
raise\r
end\r
end\r
u = do_autologin(m.source)\r
case u.username\r
when 'everyone'\r
- m.reply "I couldn't find anything to let you login automatically"\r
+ m.reply _("I couldn't find anything to let you login automatically")\r
else\r
m.reply welcome(m.source)\r
end\r
# if m.public?\r
# rep << m.source.nick << ", "\r
# end\r
- rep << "you are "\r
- rep << get_botusername_for(m.source).gsub(/^everyone$/, "no one that I know").gsub(/^owner$/, "my boss")\r
- m.reply rep\r
+ m.reply _("you are %{who}") % {\r
+ :who => get_botusername_for(m.source).gsub(\r
+ /^everyone$/, _("no one that I know")).gsub(\r
+ /^owner$/, _("my boss"))\r
+ }\r
end\r
\r
def help(cmd, topic="")\r
case cmd\r
when "login"\r
- return "login [<botuser>] [<pass>]: logs in to the bot as botuser <botuser> with password <pass>. When using the full form, you must contact the bot in private. <pass> can be omitted if <botuser> allows login-by-mask and your netmask is among the known ones. if <botuser> is omitted too autologin will be attempted"\r
+ return _("login [<botuser>] [<pass>]: logs in to the bot as botuser <botuser> with password <pass>. When using the full form, you must contact the bot in private. <pass> can be omitted if <botuser> allows login-by-mask and your netmask is among the known ones. if <botuser> is omitted too autologin will be attempted")\r
when "whoami"\r
- return "whoami: names the botuser you're linked to"\r
+ return _("whoami: names the botuser you're linked to")\r
when /^permission/\r
case topic\r
when "syntax"\r
- 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"\r
+ 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")\r
when "set", "reset", "[re]set", "(re)set"\r
- return "permissions [re]set <permission> [in <channel>] for <user>: sets or resets the permissions for botuser <user> in channel <channel> (use ? to change the permissions for private addressing)"\r
+ return _("permissions [re]set <permission> [in <channel>] for <user>: sets or resets the permissions for botuser <user> in channel <channel> (use ? to change the permissions for private addressing)")\r
when "view"\r
- return "permissions view [for <user>]: display the permissions for user <user>"\r
+ return _("permissions view [for <user>]: display the permissions for user <user>")\r
+ else\r
+ return _("permission topics: syntax, (re)set, view")\r
end\r
when "user"\r
case topic\r
when "show"\r
- return "user show <what> : shows info about the user; <what> can be any of autologin, login-by-mask, netmasks"\r
+ return _("user show <what> : shows info about the user; <what> can be any of autologin, login-by-mask, netmasks")\r
when /^(en|dis)able/\r
- return "user enable|disable <what> : turns on or off <what> (autologin, login-by-mask)"\r
+ return _("user enable|disable <what> : turns on or off <what> (autologin, login-by-mask)")\r
when "set"\r
- return "user set password <blah> : sets the user password to <blah>; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long"\r
+ return _("user set password <blah> : sets the user password to <blah>; passwords can only contain upper and lowercase letters and numbers, and must be at least 4 characters long")\r
when "add", "rm"\r
- return "user add|rm netmask <mask> : adds/removes netmask <mask> from the list of netmasks known to the botuser you're linked to"\r
+ return _("user add|rm netmask <mask> : adds/removes netmask <mask> from the list of netmasks known to the botuser you're linked to")\r
when "reset"\r
- return "user reset <what> : resets <what> to the default values. <what> 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)"\r
+ return _("user reset <what> : resets <what> to the default values. <what> 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)")\r
when "tell"\r
- return "user tell <who> the password for <botuser> : contacts <who> in private to tell him/her the password for <botuser>"\r
+ return _("user tell <who> the password for <botuser> : contacts <who> in private to tell him/her the password for <botuser>")\r
when "create"\r
- return "user create <name> <password> : create botuser named <name> with password <password>. The password can be omitted, in which case a random one will be generated. The <name> should only contain alphanumeric characters and the underscore (_)"\r
+ return _("user create <name> <password> : create botuser named <name> with password <password>. The password can be omitted, in which case a random one will be generated. The <name> should only contain alphanumeric characters and the underscore (_)")\r
when "list"\r
- return "user list : lists all the botusers"\r
+ return _("user list : lists all the botusers")\r
when "destroy"\r
- return "user destroy <botuser> <password> : destroys <botuser>; this function #{Bold}must#{Bold} be called in two steps. On the first call, no password must be specified: <botuser> is then queued for destruction. On the second call, you must specify the correct password for <botuser>, and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy <botuser>+"\r
+ return _("user destroy <botuser> <password> : destroys <botuser>; this function %{highlight}must%{highlight} be called in two steps. On the first call, no password must be specified: <botuser> is then queued for destruction. On the second call, you must specify the correct password for <botuser>, and it will be destroyed. If you want to cancel the destruction, issue the command +user cancel destroy <botuser>+") % {:highlight => Bold}\r
else\r
- return "user show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy"\r
+ return _("user topics: show, enable|disable, add|rm netmask, set, reset, tell, create, list, destroy")\r
end\r
+ when "auth"\r
+ return _("auth <masterpassword>: log in as the bot owner; other commands: login, whoami, permission syntax, permissions [re]set, permissions view, user")\r
else\r
- return "#{name}: login, whoami, permission syntax, permissions [re]set, permissions view, user"\r
+ return _("auth commands: auth, login, whoami, permission[s], user")\r
end\r
end\r
\r
def need_args(cmd)\r
- "sorry, I need more arguments to #{cmd}"\r
+ _("sorry, I need more arguments to %{command}") % {:command => cmd}\r
end\r
\r
def not_args(cmd, *stuff)\r
- "I can only #{cmd} these: #{stuff.join(', ')}"\r
+ _("I can only %{command} these: %{arguments}") %\r
+ {:command => cmd, :arguments => stuff.join(', ')}\r
end\r
\r
def set_prop(botuser, prop, val)\r
k = prop.to_s.gsub("-","_")\r
botuser.send( (k + "=").to_sym, val)\r
+ if prop == :password and botuser == @bot.auth.botowner\r
+ @bot.config.items[:'auth.password'].set_string(@bot.auth.botowner.password)\r
+ end\r
end\r
\r
def reset_prop(botuser, prop)\r
\r
has_for = splits[-2] == "for"\r
butarget = @bot.auth.get_botuser(splits[-1]) if has_for\r
- return m.reply("you can't mess with #{butarget.username}") if butarget == @bot.auth.botowner && botuser != butarget\r
+ return m.reply(_("you can't mess with %{user}") % {:user => butarget.username}) \\r
+ if butarget == @bot.auth.botowner && botuser != butarget\r
splits.slice!(-2,2) if has_for\r
\r
bools = [:autologin, :"login-by-mask"]\r
case cmd.to_sym\r
\r
when :show\r
- return "you can't see the properties of #{butarget.username}" if botuser != butarget and !botuser.permit?("auth::show::other")\r
+ return _("you can't see the properties of %{user}") %\r
+ {:user => butarget.username} if botuser != butarget &&\r
+ !botuser.permit?("auth::show::other")\r
\r
case splits[1]\r
when nil, "all"\r
props = can_reset\r
when "password"\r
if botuser != butarget\r
- return m.reply("no way I'm telling you the master password!") if butarget == @bot.auth.botowner\r
- return m.reply("you can't ask for someone else's password")\r
+ return m.reply(_("no way I'm telling you the master password!")) if butarget == @bot.auth.botowner\r
+ return m.reply(_("you can't ask for someone else's password"))\r
end\r
- return m.reply("c'mon, you can't be asking me seriously to tell you the password in public!") if m.public?\r
- return m.reply("the password for #{butarget.username} is #{butarget.password}")\r
+ return m.reply(_("c'mon, you can't be asking me seriously to tell you the password in public!")) if m.public?\r
+ return m.reply(_("the password for %{user} is %{password}") %\r
+ { :user => butarget.username, :password => butarget.password })\r
else\r
props = splits[1..-1]\r
end\r
next if k == :password\r
case k\r
when *bools\r
- str << "can"\r
- str.last << "not" unless ask_bool_prop(butarget, k)\r
- str.last << " #{k}"\r
+ if ask_bool_prop(butarget, k)\r
+ str << _("can %{action}") % {:action => k}\r
+ else\r
+ str << _("can not %{action}") % {:action => k}\r
+ end\r
when :netmasks\r
- str << "knows "\r
if butarget.netmasks.empty?\r
- str.last << "no netmasks"\r
+ str << _("knows no netmasks")\r
else\r
- str.last << butarget.netmasks.join(", ")\r
+ str << _("knows %{netmasks}") % {:netmasks => butarget.netmasks.join(", ")}\r
end\r
end\r
}\r
return m.reply("#{butarget.username} #{str.join('; ')}")\r
\r
when :enable, :disable\r
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::other::default")\r
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+ return m.reply(_("you can't change the default user")) if butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::other::default")\r
+ return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if butarget != botuser && !botuser.permit?("auth::edit::other")\r
\r
return m.reply(need_args(cmd)) unless splits[1]\r
things = []\r
end\r
}\r
\r
- m.reply "I ignored #{skipped.join(', ')} because " + not_args(cmd, *bools) unless skipped.empty?\r
+ m.reply(_("I ignored %{things} because %{reason}") % {\r
+ :things => skipped.join(', '),\r
+ :reason => not_args(cmd, *bools)}) unless skipped.empty?\r
if things.empty?\r
- m.reply "I haven't changed anything"\r
+ m.reply _("I haven't changed anything")\r
else\r
@bot.auth.set_changed\r
return auth_manage_user(m, {:data => ["show"] + things + ["for", butarget.username] })\r
end\r
\r
when :set\r
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")\r
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+ return m.reply(_("you can't change the default user")) if\r
+ butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::default")\r
+ return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if\r
+ butarget != botuser && !botuser.permit?("auth::edit::other")\r
\r
return m.reply(need_args(cmd)) unless splits[1]\r
arg = splits[1].to_sym\r
argarg = splits[2]\r
return m.reply(need_args([cmd, splits[1]].join(" "))) unless argarg\r
if arg == :password && m.public?\r
- return m.reply("is that a joke? setting the password in public?")\r
+ return m.reply(_("is that a joke? setting the password in public?"))\r
end\r
set_prop(butarget, arg, argarg)\r
@bot.auth.set_changed\r
auth_manage_user(m, {:data => ["show", arg, "for", butarget.username] })\r
\r
when :reset\r
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")\r
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+ return m.reply(_("you can't change the default user")) if\r
+ butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::default")\r
+ return m.reply(_("you can't edit %{user}") % {:user=>butarget.username}) if\r
+ butarget != botuser && !botuser.permit?("auth::edit::other")\r
\r
return m.reply(need_args(cmd)) unless splits[1]\r
things = []\r
end\r
}\r
\r
- m.reply "I ignored #{skipped.join(', ')} because " + not_args(cmd, *can_reset) unless skipped.empty?\r
+ m.reply(_("I ignored %{things} because %{reason}") %\r
+ { :things => skipped.join(', '),\r
+ :reason => not_args(cmd, *can_reset)}) unless skipped.empty?\r
if things.empty?\r
- m.reply "I haven't changed anything"\r
+ m.reply _("I haven't changed anything")\r
else\r
@bot.auth.set_changed\r
- @bot.say m.source, "the password for #{butarget.username} is now #{butarget.password}" if things.include?("password")\r
+ @bot.say(m.source, _("the password for %{user} is now %{password}") %\r
+ {:user => butarget.username, :password => butarget.password}) if\r
+ things.include?("password")\r
return auth_manage_user(m, {:data => (["show"] + things - ["password"]) + ["for", butarget.username]})\r
end\r
\r
when :add, :rm, :remove, :del, :delete\r
- return m.reply("you can't change the default user") if butarget == @bot.auth.everyone and !botuser.permit?("auth::edit::default")\r
- return m.reply("you can't edit #{butarget.username}") if butarget != botuser and !botuser.permit?("auth::edit::other")\r
+ return m.reply(_("you can't change the default user")) if\r
+ butarget == @bot.auth.everyone && !botuser.permit?("auth::edit::default")\r
+ return m.reply(_("you can't edit %{user}") % {:user => butarget.username}) if\r
+ butarget != botuser && !botuser.permit?("auth::edit::other")\r
\r
arg = splits[1]\r
if arg.nil? or arg !~ /netmasks?/ or splits[2].nil?\r
- return m.reply("I can only add/remove netmasks. See +help user add+ for more instructions")\r
+ return m.reply(_("I can only add/remove netmasks. See +help user add+ for more instructions"))\r
end\r
\r
method = cmd.to_sym == :add ? :add_netmask : :delete_netmask\r
return auth_manage_user(m, {:data => ["show", "netmasks", "for", butarget.username] })\r
\r
else\r
- m.reply "sorry, I don't know how to #{m.message}"\r
+ m.reply _("sorry, I don't know how to %{request}") % {:request => m.message}\r
end\r
end\r
\r
begin\r
botuser = @bot.auth.get_botuser(params[:botuser])\r
rescue\r
- return m.reply("coudln't find botuser #{params[:botuser]})")\r
+ return m.reply(_("couldn't find botuser %{user}") % {:user => params[:botuser]})\r
end\r
- m.reply "I'm not telling the master password to anyway, pal" if botuser == @bot.auth.botowner\r
- msg = "the password for botuser #{botuser.username} is #{botuser.password}"\r
+ m.reply(_("I'm not telling the master password to anyway, pal")) if botuser == @bot.auth.botowner\r
+ msg = _("the password for botuser %{user} is %{password}") %\r
+ {:user => botuser.username, :password => botuser.password}\r
@bot.say user, msg\r
- @bot.say m.source, "I told #{user} that " + msg\r
+ @bot.say m.source, _("I told %{user} that %{message}") % {:user => user, :message => msg}\r
end\r
\r
def auth_create_user(m, params)\r
name = params[:name]\r
password = params[:password]\r
- return m.reply("are you nuts, creating a botuser with a publicly known password?") if m.public? and not password.nil?\r
+ return m.reply(_("are you nuts, creating a botuser with a publicly known password?")) if m.public? and not password.nil?\r
begin\r
bu = @bot.auth.create_botuser(name, password)\r
@bot.auth.set_changed\r
rescue => e\r
- m.reply "failed to create #{name}: #{e}"\r
+ m.reply(_("failed to create %{user}: %{exception}") % {:user => name, :exception => e})\r
debug e.inspect + "\n" + e.backtrace.join("\n")\r
return\r
end\r
- m.reply "created botuser #{bu.username}"\r
+ m.reply(_("created botuser %{user}") % {:user => bu.username})\r
end\r
\r
def auth_list_users(m, params)\r
list = @bot.auth.save_array.inject([]) { |list, x| list << x[:username] } - ['everyone', 'owner']\r
if defined?(@destroy_q)\r
list.map! { |x|\r
- @destroy_q.include?(x) ? x + " (queued for destruction)" : x\r
+ @destroy_q.include?(x) ? x + _(" (queued for destruction)") : x\r
}\r
end\r
- return m.reply("I have no botusers other than the default ones") if list.empty?\r
- return m.reply("botuser#{'s' if list.length > 1}: #{list.join(', ')}")\r
+ return m.reply(_("I have no botusers other than the default ones")) if list.empty?\r
+ return m.reply(n_("botuser: %{list}", "botusers: %{list}", list.length) %\r
+ {:list => list.join(', ')})\r
end\r
\r
def auth_destroy_user(m, params)\r
@destroy_q = [] unless defined?(@destroy_q)\r
buname = params[:name]\r
- return m.reply("You can't destroy #{buname}") if ["everyone", "owner"].include?(buname)\r
+ return m.reply(_("You can't destroy %{user}") % {:user => buname}) if\r
+ ["everyone", "owner"].include?(buname)\r
cancel = m.message.split[1] == 'cancel'\r
password = params[:password]\r
\r
h\r
}\r
\r
- return m.reply("no such botuser #{buname}") unless buser_hash.keys.include?(buname)\r
+ return m.reply(_("no such botuser %{user}") % {:user=>buname}) unless\r
+ buser_hash.keys.include?(buname)\r
\r
if cancel\r
if @destroy_q.include?(buname)\r
@destroy_q.delete(buname)\r
- m.reply "#{buname} removed from the destruction queue"\r
+ m.reply(_("%{user} removed from the destruction queue") % {:user=>buname})\r
else\r
- m.reply "#{buname} was not queued for destruction"\r
+ m.reply(_("%{user} was not queued for destruction") % {:user=>buname})\r
end\r
return\r
end\r
\r
if password.nil?\r
if @destroy_q.include?(buname)\r
- rep = "#{buname} already queued for destruction"\r
+ return m.reply(_("%{user} already queued for destruction, use %{highlight}user destroy %{user} <password>%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})\r
else\r
@destroy_q << buname\r
- rep = "#{buname} queued for destruction"\r
+ return m.reply(_("%{user} queued for destruction, use %{highlight}user destroy %{user} <password>%{highlight} to destroy it") % {:user=>buname, :highlight=>Bold})\r
end\r
- return m.reply(rep + ", use #{Bold}user destroy #{buname} <password>#{Bold} to destroy it")\r
else\r
begin\r
- return m.reply("#{buname} is not queued for destruction yet") unless @destroy_q.include?(buname)\r
- return m.reply("wrong password for #{buname}") unless buser_hash[buname][:password] == password\r
+ return m.reply(_("%{user} is not queued for destruction yet") %\r
+ {:user=>buname}) unless @destroy_q.include?(buname)\r
+ return m.reply(_("wrong password for %{user}") %\r
+ {:user=>buname}) unless buser_hash[buname][:password] == password\r
buser_array.delete_if { |u|\r
u[:username] == buname\r
}\r
@bot.auth.load_array(buser_array, true)\r
@bot.auth.set_changed\r
rescue => e\r
- return m.reply("failed: #{e}")\r
+ return m.reply(_("failed: %{exception}") % {:exception => e})\r
end\r
- return m.reply("botuser #{buname} destroyed")\r
+ return m.reply(_("botuser %{user} destroyed") % {:user => buname})\r
end\r
\r
end\r
def auth_copy_ren_user(m, params)\r
source = Auth::BotUser.sanitize_username(params[:source])\r
dest = Auth::BotUser.sanitize_username(params[:dest])\r
- return m.reply("please don't touch the default users") if (["everyone", "owner"] | [source, dest]).length < 4\r
+ return m.reply(_("please don't touch the default users")) unless\r
+ (["everyone", "owner"] & [source, dest]).empty?\r
\r
buser_array = @bot.auth.save_array\r
buser_hash = buser_array.inject({}) { |h, u|\r
h\r
}\r
\r
- return m.reply("no such botuser #{source}") unless buser_hash.keys.include?(source)\r
- return m.reply("botuser #{dest} exists already") if buser_hash.keys.include?(dest)\r
+ return m.reply(_("no such botuser %{source}") % {:source=>source}) unless\r
+ buser_hash.keys.include?(source)\r
+ return m.reply(_("botuser %{dest} exists already") % {:dest=>dest}) if\r
+ buser_hash.keys.include?(dest)\r
\r
copying = m.message.split[1] == "copy"\r
begin\r
@bot.auth.load_array(buser_array, true)\r
@bot.auth.set_changed\r
rescue => e\r
- return m.reply("failed: #{e}")\r
+ return m.reply(_("failed: %{exception}") % {:exception=>e})\r
end\r
- return m.reply("botuser #{source} copied to #{dest}") if copying\r
- return m.reply("botuser #{source} renamed to #{dest}")\r
+ return m.reply(_("botuser %{source} copied to %{dest}") %\r
+ {:source=>source, :dest=>dest}) if copying\r
+ return m.reply(_("botuser %{source} renamed to %{dest}") %\r
+ {:source=>source, :dest=>dest})\r
\r
end\r
\r
\r
what.delete("all")\r
\r
- m.reply "selecting data to export ..."\r
+ m.reply _("selecting data to export ...")\r
\r
buser_array = @bot.auth.save_array\r
buser_hash = buser_array.inject({}) { |h, u|\r
}\r
end\r
\r
- m.reply "preparing data for export ..."\r
+ m.reply _("preparing data for export ...")\r
begin\r
yaml_hash = {}\r
we_want.each { |k, val|\r
}\r
}\r
rescue => e\r
- m.reply "failed to prepare data: #{e}"\r
+ m.reply _("failed to prepare data: %{exception}") % {:exception=>e}\r
debug e.backtrace.dup.unshift(e.inspect).join("\n")\r
return\r
end\r
\r
- m.reply "exporting to #{exportfile} ..."\r
+ m.reply _("exporting to %{file} ...") % {:file=>exportfile}\r
begin\r
# m.reply yaml_hash.inspect\r
File.open(exportfile, "w") do |file|\r
file.puts YAML::dump(yaml_hash)\r
end\r
rescue => e\r
- m.reply "failed to export users: #{e}"\r
+ m.reply _("failed to export users: %{exception}") % {:exception=>e}\r
debug e.backtrace.dup.unshift(e.inspect).join("\n")\r
return\r
end\r
- m.reply "done"\r
+ m.reply _("done")\r
end\r
\r
def auth_import(m, params)\r
\r
what.delete("all")\r
\r
- m.reply "reading #{importfile} ..."\r
+ m.reply _("reading %{file} ...") % {:file=>importfile}\r
begin\r
yaml_hash = YAML::load_file(importfile)\r
rescue => e\r
- m.reply "failed to import from: #{e}"\r
+ m.reply _("failed to import from: %{exception}") % {:exception=>e}\r
debug e.backtrace.dup.unshift(e.inspect).join("\n")\r
return\r
end\r
\r
# m.reply yaml_hash.inspect\r
\r
- m.reply "selecting data to import ..."\r
+ m.reply _("selecting data to import ...")\r
\r
if what.empty?\r
we_want = yaml_hash\r
}\r
end\r
\r
- m.reply "parsing data from import ..."\r
+ m.reply _("parsing data from import ...")\r
\r
buser_hash = {}\r
\r
}\r
}\r
rescue => e\r
- m.reply "failed to parse data: #{e}"\r
+ m.reply _("failed to parse data: %{exception}") % {:exception=>e}\r
debug e.backtrace.dup.unshift(e.inspect).join("\n")\r
return\r
end\r
@bot.auth.load_array(new_buser_array, true)\r
@bot.auth.set_changed\r
\r
- m.reply "done"\r
+ m.reply _("done")\r
end\r
\r
end\r