auth_export (AuthModule)

    # File lib/rbot/core/auth.rb, line 802
      def auth_export(m, params)

        exportfile = "#{@bot.botclass}/new-auth.users"

        what = params[:things]

        has_to = what[-2] == "to"
        if has_to
          exportfile = "#{@bot.botclass}/#{what[-1]}"
          what.slice!(-2,2)
        end

        what.delete("all")

        m.reply _("selecting data to export ...")

        buser_array = @bot.auth.save_array
        buser_hash = buser_array.inject({}) { |h, u|
          h[u[:username]] = u
          h
        }

        if what.empty?
          we_want = buser_hash
        else
          we_want = buser_hash.delete_if { |key, val|
            not what.include?(key)
          }
        end

        m.reply _("preparing data for export ...")
        begin
          yaml_hash = {}
          we_want.each { |k, val|
            yaml_hash[k] = {}
            val.each { |kk, v|
              case kk
              when :username
                next
              when :netmasks
                yaml_hash[k][kk] = []
                v.each { |nm|
                  yaml_hash[k][kk] << {
                    :fullform => nm.fullform,
                    :casemap => nm.casemap.to_s
                  }
                }
              else
                yaml_hash[k][kk] = v
              end
            }
          }
        rescue => 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 %{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: %{exception}") % {:exception=>e}
          debug e.backtrace.dup.unshift(e.inspect).join("\n")
          return
        end
        m.reply _("done")
      end