--PLAYER_ENTERING_WORLD
function()
    local date = date()
    local year = date:match("%d%d%/%d%d/(%d%d)") + 2000 --01/07/(19) 14:36:42
    local month = date:match("(%d%d)") --(01)/07/19 14:36:42
    local day = date:match("%d%d%/(%d%d)") --01/(07)/19 14:36:42
    if day:find("0") == 1 then
        day = day:gsub("0", "")
    end
    if month:find("0") == 1 then
        month = month:gsub("0", "")
    end
    local class = UnitClass("player")
    local localdate = day .. "." .. month .. "." .. year
    WeakAurasSaved.globalCharacterRegistry[UnitName("player")] =
    {
        ["Key"] = "",
        ["Level"] = 0,
        ["Date"] = localdate,
        ["Class"] = class,
    }
    for i = 1, 4 do
        for j = 1, GetContainerNumSlots(i) do
            local name = GetContainerItemLink(i, j) or ""
            if name:match("key") then
                local parts = {strsplit(':', name)}
                local level = tonumber(parts[3]);
                local name = parts[7]:gsub("%]", "")
                name = name:sub(2)
                WeakAurasSaved.globalCharacterRegistry[UnitName("player")].Key = name
                WeakAurasSaved.globalCharacterRegistry[UnitName("player")].Level = level
            end
        end
    end
end

--CHAT_MSG_WHISPER
function(e, msg, sender)
    local sender = sender:match("%a+")
    msg = msg:lower()
    if msg == "dai key" and sender == UnitName("player") then
        local output = ""
        for k, v in pairs(WeakAurasSaved.globalCharacterRegistry) do
            local name = k
            output = output .. aura_env.classColor(v.Class) .. name .. "|r " .. v.Key .. " " .. v.Level .. " - " .. v.Date .. "\n"
        end
        aura_env.f1.text:SetText(output)
        aura_env.f1:Show()
    end
    if msg == "ok" and sender == UnitName("player") then
        aura_env.f1:Hide()
    end
end

--INIT
aura_env.classColor = function(class)
    if class == "Death Knight" then return "|cFFC41F3B" elseif
    class == "Demon Hunter" then return "|cFFA330C9" elseif
    class == "Druid" then return "|cFFFF7D0A" elseif
    class == "Hunter" then return "|cFFABD473" elseif
    class == "Mage" then return "|cFF40C7EB" elseif
    class == "Monk" then return "|cFF00FF96" elseif
    class == "Paladin" then return "|cFFF58CBA" elseif
    class == "Priest" then return "|cFFFFFFFF" elseif
    class == "Rogue" then return "|cFFFFF569" elseif
    class == "Shaman" then return "|cFF0070DE" elseif
    class == "Warlock" then return "|cFF8787ED" elseif
    class == "Warrior" then return "|cFFC79C6E" else
    return "|cFF000000" end
end
aura_env.f1 = CreateFrame("Frame", nil, UIParent)
aura_env.f1:SetWidth(100)
aura_env.f1:SetHeight(100)
aura_env.f1:SetPoint("CENTER", 0, 100)
aura_env.f1.text = aura_env.f1:CreateFontString(nil, "ARTWORK")
aura_env.f1.text:SetFont("Fonts\\ARIALN.ttf", 26, "OUTLINE")
aura_env.f1.text:SetPoint("CENTER", 0, 0)
aura_env.f1:Hide()
if not WeakAurasSaved.globalCharacterRegistry then WeakAurasSaved.globalCharacterRegistry = {} end
