local SampEvents = require("samp.events")
local inicfg = require("inicfg")
local directIni = "autogender.ini"
local ini = inicfg.load({
main = {
isMale = true
},
}, directIni)
inicfg.save(ini, directIni)
---@type [string, string][] {male, female}
local dict = {
{"отсосал", "отсосала"}
}
local function Message(...)
sampAddChatMessage("AutoGender // " .. table.concat({...}, " "), -1)
end
local function toLowerCase(str) -- https://www.blast.hk/threads/13380/page-37#post-1359480
local result = str:gsub("([A-ZА-ЯЁ])", function(c)
return string.char(string.byte(c) + (c == "ё" and 16 or 32))
end)
return result
end
local function applyGenderChanges(text)
local result = text:gsub("[%wА-Яа-яЁё]+", function(word)
for _, types in ipairs(dict) do
local male, female = types[1], types[2]
if (toLowerCase(word) == (ini.main.isMale and female or male)) then
return ini.main.isMale and male or female
end
end
end)
return result
end
function main()
while not isSampAvailable() do wait(0) end
sampRegisterChatCommand("autogender", function(testString)
if (#testString == 0) then
ini.main.isMale = not ini.main.isMale
inicfg.save(ini, directIni)
Message("Gender changed to", ini.main.isMale and "male" or "female")
return
end
Message("Current gender:", ini.main.isMale and "male" or "female", ". Gender replace results:");
Message("Original:", testString)
Message("Result:", applyGenderChanges(testString))
end)
wait(-1)
end
function SampEvents.onSendChat(test)
return {applyGenderChanges(test)}
end