<commit_before>local L = EPGPGlobalStrings

local mod = EPGP:NewModule("EPGP_Cache", "AceEvent-2.0")

function mod:OnInitialize()
  self.guild_member_count = 0
end

function mod:OnEnable()
  self:RegisterEvent("GUILD_ROSTER_UPDATE")
  self:RegisterEvent("PLAYER_GUILD_UPDATE")
  self:RegisterEvent("CHAT_MSG_ADDON")
  self:GuildRosterNow()
end

function mod:LoadConfig()
  local lines = {string.split("\n", GetGuildInfoText() or "")}
  local in_block = false

  local outsiders = {}
  local dummies = {}

  for _,line in pairs(lines) do
    if line == "-EPGP-" then
      in_block = not in_block
    elseif in_block then
      -- Get options and alts
      -- Format is:
      --   @DECAY_P:<number>    // for decay percent (defaults to 10)
      --   @MIN_EP:<number>     // for min eps until member can need items (defaults to 1000)
      --   @FC                  // for flat credentials (true if specified, false otherwise)

      -- Decay percent
      local dp = line:match("@DECAY_P:(%d+)")
      if dp then
        dp = tonumber(dp)
        if dp and dp >= 0 and dp <= 100 then EPGP.db.profile.decay_percent = dp
        else EPGP:Print(L["Decay Percent should be a number between 0 and 100"]) end
      end

      -- Min EPs
      local mep = tonumber(line:match("@MIN_EP:(%d+)"))
      if mep then
        if mep and mep >= 0 then EPGP.db.profile.min_eps = mep
        else EPGP:Print(L["Min EPs should be a positive number"]) end
      end
      
      -- Base GP
      local bgp = tonumber(line:match("@BASE_GP:(%d+)"))
      if bgp then
        if bgp and bgp >= 0 then EPGP.db.profile.base_gp = bgp
        else EPGP:Print(L["Base GP should be a positive number"]) end
      end
      
      -- Flat Credentials
      local fc = line:match("@FC")
      if fc then EPGP.db.profile.flat_credentials = true end

      -- Read in Outsiders
      for outsider, dummy in line:gmatch("(%a+):(%a+)") do
        outsiders[outsider] = dummy
        dummies[dummy] = outsider
      end
    end
  end
  EPGP.db.profile.outsiders = outsiders
  EPGP.db.profile.dummies = dummies
end

local function GetMemberData(obj, name)
  if obj:IsOutsider(name) then
    return EPGP.db.profile.data[EPGP.db.profile.outsiders[name]]
  elseif obj:IsAlt(name) then
    return EPGP.db.profile.data[EPGP.db.profile.alts[name]]
  else
    return EPGP.db.profile.data[name]
  end
end

function mod:IsAlt(name)
  return not not EPGP.db.profile.alts[name]
end

function mod:IsOutsider(name)
  return not not EPGP.db.profile.outsiders[name]
end

function mod:IsDummy(name)
  return not not EPGP.db.profile.dummies[name]
end

function mod:GetMemberEPGP(name)
  local t = GetMemberData(self, name)
  if not t then
    return
  else
    return unpack(t)
  end
end

function mod:GetMemberInfo(name)
  local guild_name = name
  if self:IsOutsider(name) then
    guild_name = EPGP.db.profile.outsiders[name]
  end
  local t = EPGP.db.profile.info[guild_name]
  if t then return unpack(t) end
end

function mod:SetMemberEPGP(name, ep, gp)
  assert(type(ep) == "number" and ep >= 0 and ep <= 999999999999999)
  assert(type(gp) == "number" and gp >= 0 and gp <= 999999999999999)
  local t = GetMemberData(self, name)
  t[1] = ep
  t[2] = gp
end

local function ParseNote(note)
  if note == "" then return 0, EPGP.db.profile.base_gp end
  local ep, tep, gp, tgp = string.match(note, "^(%d+)|(%d+)|(%d+)|(%d+)$")
  tgp = tgp + EPGP.db.profile.base_gp
  if ep then
    return tonumber(ep) + tonumber(tep), tonumber(gp) + tonumber(tgp)
  end

  ep, gp = string.match(note, "^(%d+)|(%d+)$")
  return tonumber(ep), tonumber(gp) + EPGP.db.profile.base_gp
end

function mod:LoadRoster()
  local data = {}
  local info = {}
  local alts = {}<commit_msg>Fix error on empty/unparsable officer notes.<commit_after>local L = EPGPGlobalStrings

local mod = EPGP:NewModule("EPGP_Cache", "AceEvent-2.0")

function mod:OnInitialize()
  self.guild_member_count = 0
end

function mod:OnEnable()
  self:RegisterEvent("GUILD_ROSTER_UPDATE")
  self:RegisterEvent("PLAYER_GUILD_UPDATE")
  self:RegisterEvent("CHAT_MSG_ADDON")
  self:GuildRosterNow()
end

function mod:LoadConfig()
  local lines = {string.split("\n", GetGuildInfoText() or "")}
  local in_block = false

  local outsiders = {}
  local dummies = {}

  for _,line in pairs(lines) do
    if line == "-EPGP-" then
      in_block = not in_block
    elseif in_block then
      -- Get options and alts
      -- Format is:
      --   @DECAY_P:<number>    // for decay percent (defaults to 10)
      --   @MIN_EP:<number>     // for min eps until member can need items (defaults to 1000)
      --   @FC                  // for flat credentials (true if specified, false otherwise)

      -- Decay percent
      local dp = line:match("@DECAY_P:(%d+)")
      if dp then
        dp = tonumber(dp)
        if dp and dp >= 0 and dp <= 100 then EPGP.db.profile.decay_percent = dp
        else EPGP:Print(L["Decay Percent should be a number between 0 and 100"]) end
      end

      -- Min EPs
      local mep = tonumber(line:match("@MIN_EP:(%d+)"))
      if mep then
        if mep and mep >= 0 then EPGP.db.profile.min_eps = mep
        else EPGP:Print(L["Min EPs should be a positive number"]) end
      end
      
      -- Base GP
      local bgp = tonumber(line:match("@BASE_GP:(%d+)"))
      if bgp then
        if bgp and bgp >= 0 then EPGP.db.profile.base_gp = bgp
        else EPGP:Print(L["Base GP should be a positive number"]) end
      end
      
      -- Flat Credentials
      local fc = line:match("@FC")
      if fc then EPGP.db.profile.flat_credentials = true end

      -- Read in Outsiders
      for outsider, dummy in line:gmatch("(%a+):(%a+)") do
        outsiders[outsider] = dummy
        dummies[dummy] = outsider
      end
    end
  end
  EPGP.db.profile.outsiders = outsiders
  EPGP.db.profile.dummies = dummies
end

local function GetMemberData(obj, name)
  if obj:IsOutsider(name) then
    return EPGP.db.profile.data[EPGP.db.profile.outsiders[name]]
  elseif obj:IsAlt(name) then
    return EPGP.db.profile.data[EPGP.db.profile.alts[name]]
  else
    return EPGP.db.profile.data[name]
  end
end

function mod:IsAlt(name)
  return not not EPGP.db.profile.alts[name]
end

function mod:IsOutsider(name)
  return not not EPGP.db.profile.outsiders[name]
end

function mod:IsDummy(name)
  return not not EPGP.db.profile.dummies[name]
end

function mod:GetMemberEPGP(name)
  local t = GetMemberData(self, name)
  if not t then
    return
  else
    return unpack(t)
  end
end

function mod:GetMemberInfo(name)
  local guild_name = name
  if self:IsOutsider(name) then
    guild_name = EPGP.db.profile.outsiders[name]
  end
  local t = EPGP.db.profile.info[guild_name]
  if t then return unpack(t) end
end

function mod:SetMemberEPGP(name, ep, gp)
  assert(type(ep) == "number" and ep >= 0 and ep <= 999999999999999)
  assert(type(gp) == "number" and gp >= 0 and gp <= 999999999999999)
  local t = GetMemberData(self, name)
  t[1] = ep
  t[2] = gp
end

local function ParseNote(note)
  if note == "" then return 0, EPGP.db.profile.base_gp end
  local ep, tep, gp, tgp = string.match(note, "^(%d+)|(%d+)|(%d+)|(%d+)$")
  if ep then
    return tonumber(ep) + tonumber(tep), tonumber(gp) + tonumber(tgp) + EPGP.db.profile.base_gp
  end

  ep, gp = string.match(note, "^(%d+)|(%d+)$")
  return tonumber(ep), tonumber(gp) + EPGP.db.profile.base_gp
end

function mod:LoadRoster()
  local data = {}
  local info = {}
  local alts = {}
{'fraction_non_alphanumeric': 0.12531900604432505, 'fraction_numerical': 0.014506380120886501, 'mean_word_length': 3.0401519262072707, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1229931', 'n_tokens_mistral': 2807, 'n_tokens_neox': 2698, 'n_words': 707}