<commit_before>local mod = EPGP:NewModule("announce")

local Debug = LibStub("LibDebug-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale("EPGP")

function mod:AnnounceTo(medium, fmt, ...)
  if not medium then return end

  local channel = self.db.profile.channel or 0

  -- Override raid and party if we are not grouped
  if medium == "RAID" and not UnitInRaid("player") then
    medium = "GUILD"
  elseif medium == "PARTY" and not UnitInRaid("player") then
    medium = "GUILD"
  end

  local msg = string.format(fmt, ...)
  local str = "EPGP:"
  for _,s in pairs({strsplit(" ", msg)}) do
    if #str + #s >= 250 then
      if ChatThrottleLib then
        ChatThrottleLib:SendChatMessage(
          "NORMAL", "EPGP", str, medium, nil, GetChannelName(channel))
      else
        SendChatMessage(str, medium, nil, GetChannelName(channel))
      end
      str = "EPGP:"
    end
    str = str .. " " .. s
  end

  SendChatMessage(str, medium, nil, GetChannelName(channel))
end

function mod:Announce(fmt, ...)
  local medium = self.db.profile.medium

  return mod:AnnounceTo(medium, fmt, ...)
end

function mod:EPAward(event_name, name, reason, amount, mass)
  if mass then return end
  mod:Announce(L["%+d EP (%s) to %s"], amount, reason, name)
end

function mod:GPAward(event_name, name, reason, amount, mass)
  if mass then return end
  mod:Announce(L["%+d GP (%s) to %s"], amount, reason, name)
end

function mod:BankedItem(event_name, name, reason, amount, mass)
  mod:Announce(L["%s to %s"], reason, name)
end

local function MakeCommaSeparated(t)
  local first = true
  local awarded = ""

  for name in pairs(t) do
    if first then
      awarded = name
      first = false
    else
      awarded = awarded..", "..name
    end
  end

  return awarded
end

function mod:MassEPAward(event_name, names, reason, amount,
                         extras_names, extras_reason, extras_amount)
  local normal = MakeCommaSeparated(names)
  local extras = MakeCommaSeparated(extras_names)
  mod:Announce(L["%+d EP (%s) to %s"], amount, reason, normal)
  mod:Announce(L["%+d EP (%s) to %s"], extras_amount, extras_reason, extras)
end
<commit_msg>Check that we actually have a list of extras before we attempt to announce them. This fixes issue 462.<commit_after>local mod = EPGP:NewModule("announce")

local Debug = LibStub("LibDebug-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale("EPGP")

function mod:AnnounceTo(medium, fmt, ...)
  if not medium then return end

  local channel = self.db.profile.channel or 0

  -- Override raid and party if we are not grouped
  if medium == "RAID" and not UnitInRaid("player") then
    medium = "GUILD"
  elseif medium == "PARTY" and not UnitInRaid("player") then
    medium = "GUILD"
  end

  local msg = string.format(fmt, ...)
  local str = "EPGP:"
  for _,s in pairs({strsplit(" ", msg)}) do
    if #str + #s >= 250 then
      if ChatThrottleLib then
        ChatThrottleLib:SendChatMessage(
          "NORMAL", "EPGP", str, medium, nil, GetChannelName(channel))
      else
        SendChatMessage(str, medium, nil, GetChannelName(channel))
      end
      str = "EPGP:"
    end
    str = str .. " " .. s
  end

  SendChatMessage(str, medium, nil, GetChannelName(channel))
end

function mod:Announce(fmt, ...)
  local medium = self.db.profile.medium

  return mod:AnnounceTo(medium, fmt, ...)
end

function mod:EPAward(event_name, name, reason, amount, mass)
  if mass then return end
  mod:Announce(L["%+d EP (%s) to %s"], amount, reason, name)
end

function mod:GPAward(event_name, name, reason, amount, mass)
  if mass then return end
  mod:Announce(L["%+d GP (%s) to %s"], amount, reason, name)
end

function mod:BankedItem(event_name, name, reason, amount, mass)
  mod:Announce(L["%s to %s"], reason, name)
end

local function MakeCommaSeparated(t)
  local first = true
  local awarded = ""

  for name in pairs(t) do
    if first then
      awarded = name
      first = false
    else
      awarded = awarded..", "..name
    end
  end

  return awarded
end

function mod:MassEPAward(event_name, names, reason, amount,
                         extras_names, extras_reason, extras_amount)
  local normal = MakeCommaSeparated(names)
  mod:Announce(L["%+d EP (%s) to %s"], amount, reason, normal)

  if extras_names then
    local extras = MakeCommaSeparated(extras_names)
    mod:Announce(L["%+d EP (%s) to %s"], extras_amount, extras_reason, extras)
  end
end

{'fraction_non_alphanumeric': 0.12667423382519863, 'fraction_numerical': 0.004313280363223609, 'mean_word_length': 3.4595141700404857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '287387', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1477, 'n_words': 456}