addon/Addon/Code/SpeechDataApi.lua
Roman Jaroš a32b698ebf
All checks were successful
forgejo/Czech Quests/addon/pipeline/head This commit looks good
Refactor encounter handling and placeholder logic
2025-04-18 14:03:11 +02:00

34 lines
No EOL
780 B
Lua
Executable file

local _, addon = ...
local function BuildIndex(text)
local numberMarks = text:gsub("%d+%.?%d*", "#?")
local normalized = numberMarks:gsub('"', "'")
return normalized
end
local function FillPlaceholders(text)
if text == nil then
return text
end
local playerName = UnitName("player")
local formatted = text;
formatted = string.gsub(formatted, '<name>', playerName);
return formatted
end
local function GetSpeech(message)
local index = BuildIndex(message)
local speech = addon.data.speech[index];
local text = speech and speech.m or nil
if text then
return FillPlaceholders(
addon.API.FillNumbers(text, message)
)
else
return nil
end
end
addon.API.GetSpeech = GetSpeech