@botuser = @registry.sub_registry('botuser')
end
- def get_data_hash(user)
+ def get_data_hash(user, opts={})
+ plain = opts[:plain]
iu = user.to_irc_user
bu = iu.botuser
else
bh = @botuser[bu.username] || {}
end
- return ih.merge! bh
+ ih.merge!(bh)
+
+ unless plain
+ class << ih
+ alias :single_retrieve :[]
+ alias :single_assign :[]=
+ include DottedIndex
+ end
+ end
+
+ return ih
end
def get_data(user, key=nil)
return h[key]
end
- def set_data_hash(user, h)
+ def set_data_hash(user, hh)
iu = user.to_irc_user
bu = iu.botuser
+ # we .dup the hash to remove singleton methods
+ # and make it dump-able
+ h = hh.dup
+
@ircuser[iu.nick] = h
return h if bu.default?
key = params[:key].intern
data = get_data(user, key)
if data
- m.reply (_("%{key} data for %{user}: %{data}") % {
+ m.reply(_("%{key} data for %{user}: %{data}") % {
:key => key,
:user => user.nick,
:data => data
})
else
- m.reply (_("sorry, no %{key} data for %{user}") % {
+ m.reply(_("sorry, no %{key} data for %{user}") % {
:key => key,
:user => user.nick,
})
# data = params[:data].to_s
# end
+ def event_botuser(action, opts={})
+ case action
+ when :copy, :rename
+ source = opts[:source]
+ return unless @botuser.key?(source)
+ dest = opts[:dest]
+ @botuser[dest] = @botuser[source].dup
+ @botuser.delete(source) if action == :rename
+ when :pre_perm
+ @permification ||= {}
+ k = [opts[:irc_user], opts[:bot_user]]
+ @permification[k] = get_data_hash(opts[:irc_user], :plain => true)
+ when :post_perm
+ @permification ||= {}
+ k = [opts[:irc_user], opts[:bot_user]]
+ if @permification.has_key?(k)
+ @botuser[opts[:bot_user]] = @permification[k]
+ @permification.delete(k)
+ end
+ end
+ end
+
end
plugin = UserDataModule.new