From fd158900253be71240ac4e8c1f8035b85a09040f Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Tue, 4 Dec 2007 11:34:15 +0000 Subject: New Auth Framework: migrate userdata on botuser copy/rename --- lib/rbot/core/auth.rb | 10 +++++++--- lib/rbot/core/userdata.rb | 9 +++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/rbot/core/auth.rb b/lib/rbot/core/auth.rb index 0d78bdfb..179044eb 100644 --- a/lib/rbot/core/auth.rb +++ b/lib/rbot/core/auth.rb @@ -683,13 +683,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: %{exception}") % {:exception=>e}) end - return m.reply(_("botuser %{source} copied to %{dest}") % - {:source=>source, :dest=>dest}) if copying - return m.reply(_("botuser %{source} renamed to %{dest}") % + 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 end diff --git a/lib/rbot/core/userdata.rb b/lib/rbot/core/userdata.rb index 96995724..bfe71dd7 100644 --- a/lib/rbot/core/userdata.rb +++ b/lib/rbot/core/userdata.rb @@ -152,6 +152,15 @@ class UserDataModule < CoreBotModule # data = params[:data].to_s # end + def event_botuser(action, opts={}) + return unless [:copy, :rename].include?(action) + source = opts[:source] + return unless @botuser.key?(source) + dest = opts[:dest] + @botuser[dest] = @botuser[source].dup + @botuser.delete(source) if action == :rename + end + end plugin = UserDataModule.new -- cgit v1.2.3