addon/Addon/Code/SpeechDataApi.lua

34 lines
780 B
Lua
Raw Normal View History

local _, addon = ...
2025-03-10 13:32:44 +01:00
local function BuildIndex(text)
local numberMarks = text:gsub("%d+%.?%d*", "#?")
local normalized = numberMarks:gsub('"', "'")
return normalized
2025-03-10 13:32:44 +01:00
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)
2025-03-10 13:32:44 +01:00
local index = BuildIndex(message)
local speech = addon.data.speech[index];
local text = speech and speech.m or nil
2025-03-10 13:32:44 +01:00
if text then
return FillPlaceholders(
addon.API.FillNumbers(text, message)
)
2025-03-10 13:32:44 +01:00
else
return nil
end
end
addon.API.GetSpeech = GetSpeech