<commit_before>pfDatabase = {}

local loc = GetLocale()
local dbs = { "items", "quests", "objects", "units", "zones", "professions" }

-- detect localized databases
pfDatabase.dbstring = ""
for id, db in pairs(dbs) do
  -- assign existing locale
  pfDB[db]["loc"] = pfDB[db][loc] or pfDB[db]["enUS"]
  pfDatabase.dbstring = pfDatabase.dbstring .. " |cffcccccc[|cffffffff" .. db .. "|cffcccccc:|cff33ffcc" .. ( pfDB[db][loc] and loc or "enUS" ) .. "|cffcccccc]"
end

-- add database shortcuts
local items = pfDB["items"]["data"]
local units = pfDB["units"]["data"]
local objects = pfDB["objects"]["data"]
local quests = pfDB["quests"]["data"]
local refloot = pfDB["refloot"]["data"]
local zones = pfDB["zones"]["loc"]
local professions = pfDB["professions"]["loc"]

local bitraces = {
  [1] = "Human",
  [2] = "Orc",
  [4] = "Dwarf",
  [8] = "NightElf",
  [16] = "Scourge",
  [32] = "Tauren",
  [64] = "Gnome",
  [128] = "Troll"
}

local bitclasses = {
  [1] = "WARRIOR",
  [2] = "PALADIN",
  [4] = "HUNTER",
  [8] = "ROGUE",
  [16] = "PRIEST",
  [64] = "SHAMAN",
  [128] = "MAGE",
  [256] = "WARLOCK",
  [1024] = "DRUID"
}

-- Patch databases to further expansions
local function patchtable(base, diff)
  for k, v in pairs(diff) do
    if base[k] and type(v) == "table" then
      patchtable(base[k], v)
    elseif type(v) == "string" and v == "_" then
      base[k] = nil
    else
      base[k] = v
    end
  end
end

local time = GetTime()
DEFAULT_CHAT_FRAME:AddMessage("Live-Patching pfDB for your Expansion...")
for _, exp in pairs({ "-tbc", "-wotlk" }) do
  for _, db in pairs(dbs) do
    if pfDB[db]["data"..exp] then

      loc_core = pfDB[db][loc] or pfDB[db]["enUS"]
      loc_update = pfDB[db][loc..exp] or pfDB[db]["enUS"..exp]
      patchtable(pfDB[db]["data"], pfDB[db]["data"..exp])
      patchtable(loc_core, loc_update)
    end
  end
end
DEFAULT_CHAT_FRAME:AddMessage("Complete! Took " .. GetTime() - time .. " seconds.")

-- PlayerHasSkill
-- Returns false if the player has the required skill
function pfDatabase:PlayerHasSkill(skill)
  if not professions[skill] then return false end

  for i=0,GetNumSkillLines() do
    if GetSkillLineInfo(i) == professions[skill] then
      return true
    end
  end

  return false
end

-- GetBitByRace<commit_msg>database: add patch handler for zones and professions<commit_after>pfDatabase = {}

local loc = GetLocale()
local dbs = { "items", "quests", "objects", "units", "zones", "professions" }

-- detect localized databases
pfDatabase.dbstring = ""
for id, db in pairs(dbs) do
  -- assign existing locale
  pfDB[db]["loc"] = pfDB[db][loc] or pfDB[db]["enUS"]
  pfDatabase.dbstring = pfDatabase.dbstring .. " |cffcccccc[|cffffffff" .. db .. "|cffcccccc:|cff33ffcc" .. ( pfDB[db][loc] and loc or "enUS" ) .. "|cffcccccc]"
end

-- add database shortcuts
local items = pfDB["items"]["data"]
local units = pfDB["units"]["data"]
local objects = pfDB["objects"]["data"]
local quests = pfDB["quests"]["data"]
local refloot = pfDB["refloot"]["data"]
local zones = pfDB["zones"]["loc"]
local professions = pfDB["professions"]["loc"]

local bitraces = {
  [1] = "Human",
  [2] = "Orc",
  [4] = "Dwarf",
  [8] = "NightElf",
  [16] = "Scourge",
  [32] = "Tauren",
  [64] = "Gnome",
  [128] = "Troll"
}

local bitclasses = {
  [1] = "WARRIOR",
  [2] = "PALADIN",
  [4] = "HUNTER",
  [8] = "ROGUE",
  [16] = "PRIEST",
  [64] = "SHAMAN",
  [128] = "MAGE",
  [256] = "WARLOCK",
  [1024] = "DRUID"
}

-- Patch databases to further expansions
local function patchtable(base, diff)
  for k, v in pairs(diff) do
    if base[k] and type(v) == "table" then
      patchtable(base[k], v)
    elseif type(v) == "string" and v == "_" then
      base[k] = nil
    else
      base[k] = v
    end
  end
end

local time = GetTime()
local loc_core, loc_update
DEFAULT_CHAT_FRAME:AddMessage("Live-Patching pfDB for your Expansion...")
for _, exp in pairs({ "-tbc", "-wotlk" }) do
  for _, db in pairs(dbs) do
    if pfDB[db]["data"..exp] then
      loc_core = pfDB[db][loc] or pfDB[db]["enUS"]
      loc_update = pfDB[db][loc..exp] or pfDB[db]["enUS"..exp]
      patchtable(pfDB[db]["data"], pfDB[db]["data"..exp])
      patchtable(loc_core, loc_update)
    end
  end

  loc_core = pfDB["professions"][loc] or pfDB["professions"]["enUS"]
  loc_update = pfDB["professions"][loc..exp] or pfDB["professions"]["enUS"..exp]
  if loc_update then patchtable(loc_core, loc_update) end

  loc_core = pfDB["zones"][loc] or pfDB["zones"]["enUS"]
  loc_update = pfDB["zones"][loc..exp] or pfDB["zones"]["enUS"..exp]
  if loc_update then patchtable(loc_core, loc_update) end
end
DEFAULT_CHAT_FRAME:AddMessage("Complete! Took " .. GetTime() - time .. " seconds.")

-- PlayerHasSkill
-- Returns false if the player has the required skill
function pfDatabase:PlayerHasSkill(skill)
  if not professions[skill] then return false end

  for i=0,GetNumSkillLines() do
    if GetSkillLineInfo(i) == professions[skill] then
      return true
    end
  end

  return false
end

-- GetBitByRace
{'fraction_non_alphanumeric': 0.1824, 'fraction_numerical': 0.0136, 'mean_word_length': 3.8459302325581395, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '705549', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1997, 'n_words': 471}