Fix messages not broadcasting outside of owner

Signed-off-by: Ayane Satomi <ayane@vignetteapp.org>
This commit is contained in:
Ayane Satomi 2022-11-18 17:14:47 +08:00
parent ee8b448e93
commit 70a1653abe
No known key found for this signature in database
GPG key ID: 431E3C36BEBE204B

View file

@ -19,13 +19,18 @@ if SERVER then
-- hide tts chat messages -- hide tts chat messages
hook.add("PlayerSay", "hide_tts_chat", function(ply, text) hook.add("PlayerSay", "hide_tts_chat", function(ply, text)
-- network the original message
net.start("tts_message")
net.writeString(text)
net.send(ply)
if ply == owner() and string.sub(text, 1, 1) == ";" or string.sub(text, 1, 1) == ":" then if ply == owner() and string.sub(text, 1, 1) == ";" then
-- then finally return nothing net.start("tts_message")
net.writeString(string.sub(text, 2))
net.send()
return ""
end
if ply == owner() and string.sub(text, 1, 1) == ":" then
net.start("tts_language_switch")
net.writeString(string.sub(text, 2))
net.send()
return "" return ""
end end
end) end)
@ -36,7 +41,6 @@ if CLIENT then
if not hasPermission("bass.loadURL", "https://translate.google.com/translate_tts") then return end if not hasPermission("bass.loadURL", "https://translate.google.com/translate_tts") then return end
local function getRemoteLanguageIndex() local function getRemoteLanguageIndex()
if not owner() then return end
if not hasPermission("http.get", remoteLanguageIndex) then return end if not hasPermission("http.get", remoteLanguageIndex) then return end
print("Building language index. Please be patient...") print("Building language index. Please be patient...")
@ -60,15 +64,15 @@ if CLIENT then
end) end)
end end
local function RequestTTS(txt, l, callback) local function RequestTTS(txt, lng, callback)
bass.loadURL("https://translate.google.com/translate_tts?ie=UTF-8&q=" .. txt .. "&tl=" .. l .. "&client=tw-ob", "3d", callback) bass.loadURL("https://translate.google.com/translate_tts?ie=UTF-8&q=" .. txt .. "&tl=" .. lng .. "&client=tw-ob", "3d", callback)
end end
local function DoTTS(sound) local function DoTTS(sound)
-- check for validity -- check for validity
if not sound then if not sound then
error("Sound is invalid or niL!") error("Sound is invalid or nil!")
end end
-- we dispose the current reference, then we create a new one -- we dispose the current reference, then we create a new one
@ -102,32 +106,26 @@ if CLIENT then
getRemoteLanguageIndex() getRemoteLanguageIndex()
net.receive("tts_message", function() net.receive("tts_message", function()
local msg = net.readString() local text = net.readString()
if string.sub(msg, 1, 1) == ";" then RequestTTS(urlencode(text), currentLang, function(s, e)
local txt = string.sub(msg, 2)
local l = currentLang
RequestTTS(urlencode(txt), l, function(s, e, n)
if s then if s then
DoTTS(s) DoTTS(s)
else else
error(errorLookup[e] or "Unknown error") error("Error: " .. errorLookup[e])
end end
end) end)
elseif string.sub(msg, 1, 1) == ":" then end)
local lang = string.sub(msg, 2)
if hasval(languageIndex, string.lower(lang)) then net.receive("tts_language_switch", function()
local lang = net.readString()
if hasval(languageIndex, lang) then
currentLang = lang currentLang = lang
print("Language set to " .. lang) print("Switched to language " .. lang)
else else
if e == 2 then
currentLang = DEFAULT_LANGUAGE currentLang = DEFAULT_LANGUAGE
else print("That language isn't valid!")
error("error: " .. tostring(errorLookup[e]))
end
end
end end
end) end)
end end