<commit_before>EPGP = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "AceDebug-2.0", "AceEvent-2.0", "AceModuleCore-2.0", "FuBarPlugin-2.0")
EPGP:SetModuleMixins("AceDebug-2.0")

-------------------------------------------------------------------------------
-- DB defaults
-------------------------------------------------------------------------------
EPGP:RegisterDB("EPGP_DB")
EPGP:RegisterDefaults("profile", {
  -- Undo queue
  rosters = nil,
  -- Default report channel
  report_channel = "GUILD",
  show_alts = false,
  raid_mode = true,
})

-------------------------------------------------------------------------------
-- Init code
-------------------------------------------------------------------------------
function EPGP:OnInitialize()
  self.DEFAULT_RAID_WINDOW = 10
  self.DEFAULT_MIN_RAIDS = 2
  self.DEFAULT_FLAT_CREDENTIALS = false
  self.OnMenuRequest = self:BuildOptions()
  self:RegisterChatCommand({ "/epgp" }, self.OnMenuRequest)
end

function EPGP:OnEnable()
  self:Print("EPGP addon is enabled")
  self:RegisterEvent("GUILD_ROSTER_UPDATE")
  self:RegisterEvent("PLAYER_GUILD_UPDATE")
  self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  self:RegisterEvent("EPGP_LOAD_ROSTER", 1)
  self:ZONE_CHANGED_NEW_AREA()
  self:PLAYER_GUILD_UPDATE()
end

function EPGP:IsFlatCredentials()
  return self.flat_credentials or self.DEFAULT_FLAT_CREDENTIALS
end

function EPGP:SetFlatCredentials(val)
  self.flat_credentials = val and true or false
  self:Print("Flat credentials " .. (self.flat_credentials and "on" or "off"))
end

function EPGP:GetRaidWindow()
  return self.raid_window or self.DEFAULT_RAID_WINDOW
end

function EPGP:SetRaidWindow(rw)
  assert(rw and tonumber(rw), "Attempt to set raid window to something that is not a number!")
  rw = tonumber(rw)
  if (self.raid_window ~= rw) then
    self.raid_window = rw
    self:Print("Raid Window set to " .. tostring(rw))
  end
end

function EPGP:GetMinRaids()
  return self.min_raids or self.DEFAULT_MIN_RAIDS
end

function EPGP:SetMinRaids(mr)
  assert(mr and tonumber(mr), "Attempt to set min raids to something that is not a number!")
  mr = tonumber(mr)
  if (self.min_raids ~= mr) then
    self.min_raids = mr
    self:Print("Min raids set to " .. tostring(mr))
  end
end

function EPGP:PLAYER_GUILD_UPDATE()
  -- Keep Guild Roster up to date by calling GuildRoster() every 15 secs
  if (IsInGuild()) then
    GuildRoster()
    self:ScheduleRepeatingEvent(GuildRoster, 15)
  else
    self:CancelAllScheduledEvents()
  end
end

function EPGP:GUILD_ROSTER_UPDATE()
  self:Debug("Processing GUILD_ROSTER_UPDATE")
  self:LoadConfig()
  self:ScheduleEvent("EPGP_LOAD_ROSTER", 1)
end

function EPGP:ZONE_CHANGED_NEW_AREA()
  self.current_zone = GetRealZoneText()
end

function EPGP:OnDisable()

end

function EPGP:CanLogRaids()
  return CanEditOfficerNote() and CanEditPublicNote()
end

function EPGP:CanChangeRules()
  return IsGuildLeader() or (self:CanLogRaids() and self:IsFlatCredentials())
end

-- Builds an AceOptions table for the options
function EPGP:BuildOptions()
  -- Set up raid tracking options
  local options = {
    type = "group",
    desc = "EPGP Options",
    args = { }
  }
  -- EPs to raid
  options.args["ep_raid"] = {
    type = "text",
    name = "+EPs to Raid",
    desc = "Award EPs to raid members that are zoned.",
    get = false,
    set = function(v) self:AddEP2Raid(tonumber(v)) end,
    usage = "<EP>",
    disabled = function() return not self:CanLogRaids() end,
    validate = function(v)
      local n = tonumber(v)
      return n and n >= 0 and n < 4096
    end,
    order = 1
  }
  -- EP% to raid
  options.args["ep_bonus_raid"] = {
    type = "text",
    name = "+EP bonus % to Raid",
    desc = "Award EP % bonus to raid members that are zoned.",
    get = false,
    set = function(v) self:AddEPBonus2Raid(tonumber(v)/100) end,
    usage = "<EP>",
    disabled = function() return not self:CanLogRaids() end,
    validate = function(v)
      local n = tonumber(v)
      return n and n > 0 and n <= 100
    end,
    order = 2
  }
  -- EPs to member
  options.args["ep"] = {
    type = "group",
    name = "+EPs to Member",
    desc = "Award EPs to member.",
    disabled = function() return not self:CanChangeRules() end,
    args = { },
    order = 3,
  }
  for n, t in pairs(self:GetRoster()) do
    local member_name, class, _, _ = n, unpack(t)
    if (not options.args["ep"].args[class]) then
      options.args["ep"].args[class] = {
        type = "group",
        name = class,
        desc = class .. " members",
        disabled = function() return not self:CanChangeRules() end,
        args = { }
      }
    end
    options.args["ep"].args[class].args[member_name] = {
      type = "text",
      name = member_name,
      desc = "Award EPs to " .. member_name .. ".",
      usage = "<EP>",
      get = false,
      set = function(v) self:AddEP2Member(member_name, tonumber(v)) end,
      validate = function(v) return (type(v) == "number" or tonumber(v)) and tonumber(v) < 4096 end,
      order = 3
    }
  end
  -- GPs to member
  options.args["gp"] = {
    type = "group",
    name = "+GPs to Member",
    desc = "Account GPs for member.",
    disabled = function() return not self:CanLogRaids() end,
    args = { },
    order = 4
  }
  for n, t in pairs(self:GetRoster()) do
    local member_name, class, _, _ = n, unpack(t)
    if (not options.args["gp"].args[class]) then
      options.args["gp"].args[class] = {
        type = "group",
        name = class,
        desc = class .. " members",
        disabled = function() return not self:CanChangeRules() end,
        args = { }
      }
    end
    options.args["gp"].args[class].args[member_name] = {
      type = "text",
      name = member_name,
      desc = "Account GPs to " .. member_name .. ".",
      usage = "<GP>",
      get = false,
      set = function(v) self:AddGP2Member(member_name, tonumber(v)) end,
      validate = function(v) return (type(v) == "number" or tonumber(v)) and tonumber(v) < 4096 end
    }
  end

  -----------------------------------------------------------------------------
  -- Administrative options

  -- Start new raid
  options.args["newraid"] = {
    type = "execute",
    name = "Create New Raid",
    desc = "Create a new raid slot.",
    order = 1001,
    disabled = function() return not self:CanLogRaids() end,
    func =  function() self:NewRaid() end 
  }
  -- Reporting channel
  options.args["report_channel"] = {
    type = "text",<commit_msg>Fix Issue 28. Commanders can now assign GPs.<commit_after>EPGP = AceLibrary("AceAddon-2.0"):new("AceConsole-2.0", "AceDB-2.0", "AceDebug-2.0", "AceEvent-2.0", "AceModuleCore-2.0", "FuBarPlugin-2.0")
EPGP:SetModuleMixins("AceDebug-2.0")

-------------------------------------------------------------------------------
-- DB defaults
-------------------------------------------------------------------------------
EPGP:RegisterDB("EPGP_DB")
EPGP:RegisterDefaults("profile", {
  -- Undo queue
  rosters = nil,
  -- Default report channel
  report_channel = "GUILD",
  show_alts = false,
  raid_mode = true,
})

-------------------------------------------------------------------------------
-- Init code
-------------------------------------------------------------------------------
function EPGP:OnInitialize()
  self.DEFAULT_RAID_WINDOW = 10
  self.DEFAULT_MIN_RAIDS = 2
  self.DEFAULT_FLAT_CREDENTIALS = false
  self.OnMenuRequest = self:BuildOptions()
  self:RegisterChatCommand({ "/epgp" }, self.OnMenuRequest)
end

function EPGP:OnEnable()
  self:Print("EPGP addon is enabled")
  self:RegisterEvent("GUILD_ROSTER_UPDATE")
  self:RegisterEvent("PLAYER_GUILD_UPDATE")
  self:RegisterEvent("ZONE_CHANGED_NEW_AREA")
  self:RegisterEvent("EPGP_LOAD_ROSTER", 1)
  self:ZONE_CHANGED_NEW_AREA()
  self:PLAYER_GUILD_UPDATE()
end

function EPGP:IsFlatCredentials()
  return self.flat_credentials or self.DEFAULT_FLAT_CREDENTIALS
end

function EPGP:SetFlatCredentials(val)
  self.flat_credentials = val and true or false
  self:Print("Flat credentials " .. (self.flat_credentials and "on" or "off"))
end

function EPGP:GetRaidWindow()
  return self.raid_window or self.DEFAULT_RAID_WINDOW
end

function EPGP:SetRaidWindow(rw)
  assert(rw and tonumber(rw), "Attempt to set raid window to something that is not a number!")
  rw = tonumber(rw)
  if (self.raid_window ~= rw) then
    self.raid_window = rw
    self:Print("Raid Window set to " .. tostring(rw))
  end
end

function EPGP:GetMinRaids()
  return self.min_raids or self.DEFAULT_MIN_RAIDS
end

function EPGP:SetMinRaids(mr)
  assert(mr and tonumber(mr), "Attempt to set min raids to something that is not a number!")
  mr = tonumber(mr)
  if (self.min_raids ~= mr) then
    self.min_raids = mr
    self:Print("Min raids set to " .. tostring(mr))
  end
end

function EPGP:PLAYER_GUILD_UPDATE()
  -- Keep Guild Roster up to date by calling GuildRoster() every 15 secs
  if (IsInGuild()) then
    GuildRoster()
    self:ScheduleRepeatingEvent(GuildRoster, 15)
  else
    self:CancelAllScheduledEvents()
  end
end

function EPGP:GUILD_ROSTER_UPDATE()
  self:Debug("Processing GUILD_ROSTER_UPDATE")
  self:LoadConfig()
  self:ScheduleEvent("EPGP_LOAD_ROSTER", 1)
end

function EPGP:ZONE_CHANGED_NEW_AREA()
  self.current_zone = GetRealZoneText()
end

function EPGP:OnDisable()

end

function EPGP:CanLogRaids()
  return CanEditOfficerNote() and CanEditPublicNote()
end

function EPGP:CanChangeRules()
  return IsGuildLeader() or (self:CanLogRaids() and self:IsFlatCredentials())
end

-- Builds an AceOptions table for the options
function EPGP:BuildOptions()
  -- Set up raid tracking options
  local options = {
    type = "group",
    desc = "EPGP Options",
    args = { }
  }
  -- EPs to raid
  options.args["ep_raid"] = {
    type = "text",
    name = "+EPs to Raid",
    desc = "Award EPs to raid members that are zoned.",
    get = false,
    set = function(v) self:AddEP2Raid(tonumber(v)) end,
    usage = "<EP>",
    disabled = function() return not self:CanLogRaids() end,
    validate = function(v)
      local n = tonumber(v)
      return n and n >= 0 and n < 4096
    end,
    order = 1
  }
  -- EP% to raid
  options.args["ep_bonus_raid"] = {
    type = "text",
    name = "+EP bonus % to Raid",
    desc = "Award EP % bonus to raid members that are zoned.",
    get = false,
    set = function(v) self:AddEPBonus2Raid(tonumber(v)/100) end,
    usage = "<EP>",
    disabled = function() return not self:CanLogRaids() end,
    validate = function(v)
      local n = tonumber(v)
      return n and n > 0 and n <= 100
    end,
    order = 2
  }
  -- EPs to member
  options.args["ep"] = {
    type = "group",
    name = "+EPs to Member",
    desc = "Award EPs to member.",
    disabled = function() return not self:CanChangeRules() end,
    args = { },
    order = 3,
  }
  for n, t in pairs(self:GetRoster()) do
    local member_name, class, _, _ = n, unpack(t)
    if (not options.args["ep"].args[class]) then
      options.args["ep"].args[class] = {
        type = "group",
        name = class,
        desc = class .. " members",
        disabled = function() return not self:CanChangeRules() end,
        args = { }
      }
    end
    options.args["ep"].args[class].args[member_name] = {
      type = "text",
      name = member_name,
      desc = "Award EPs to " .. member_name .. ".",
      usage = "<EP>",
      get = false,
      set = function(v) self:AddEP2Member(member_name, tonumber(v)) end,
      validate = function(v) return (type(v) == "number" or tonumber(v)) and tonumber(v) < 4096 end,
      order = 3
    }
  end
  -- GPs to member
  options.args["gp"] = {
    type = "group",
    name = "+GPs to Member",
    desc = "Account GPs for member.",
    disabled = function() return not self:CanLogRaids() end,
    args = { },
    order = 4
  }
  for n, t in pairs(self:GetRoster()) do
    local member_name, class, _, _ = n, unpack(t)
    if (not options.args["gp"].args[class]) then
      options.args["gp"].args[class] = {
        type = "group",
        name = class,
        desc = class .. " members",
        disabled = function() return not self:CanLogRaids() end,
        args = { }
      }
    end
    options.args["gp"].args[class].args[member_name] = {
      type = "text",
      name = member_name,
      desc = "Account GPs to " .. member_name .. ".",
      usage = "<GP>",
      get = false,
      set = function(v) self:AddGP2Member(member_name, tonumber(v)) end,
      validate = function(v) return (type(v) == "number" or tonumber(v)) and tonumber(v) < 4096 end
    }
  end

  -----------------------------------------------------------------------------
  -- Administrative options

  -- Start new raid
  options.args["newraid"] = {
    type = "execute",
    name = "Create New Raid",
    desc = "Create a new raid slot.",
    order = 1001,
    disabled = function() return not self:CanLogRaids() end,
    func =  function() self:NewRaid() end 
  }
  -- Reporting channel
  options.args["report_channel"] = {
    type = "text",
{'fraction_non_alphanumeric': 0.18557810578105782, 'fraction_numerical': 0.009071340713407134, 'mean_word_length': 2.5350543478260867, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '7066924', 'n_tokens_mistral': 4393, 'n_tokens_neox': 4302, 'n_words': 1092}