Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- script_name("autogrammar")
- script_author("Rockwell / Shady (Discord: shadyxo)")
- local vkeys = require "vkeys"
- local autoGrammarEnabled = false
- local configFolder = getWorkingDirectory() .. '\\config\\'
- local configFile = configFolder .. 'autogrammar.ini'
- function main()
- if not doesDirectoryExist(configFolder) then
- createDirectory(configFolder)
- end
- if doesFileExist(configFile) then
- loadGrammarState()
- else
- blankIni()
- end
- while not isSampAvailable() do wait(100) end
- sampRegisterChatCommand("autogrammar", toggleAutoGrammar)
- while true do
- wait(0)
- if autoGrammarEnabled and sampIsChatInputActive() then
- if wasKeyPressed(vkeys.VK_RETURN) then
- local chatInput = sampGetChatInputText()
- if chatInput ~= "" and chatInput:match("%S") then
- if not chatInput:match("^/") then
- local correctedMessage = autoCorrectSentence(chatInput)
- sampSetChatInputText(correctedMessage)
- end
- end
- end
- end
- end
- end
- function toggleAutoGrammar()
- if autoGrammarEnabled then
- autoGrammarEnabled = false
- sampAddChatMessage("{FFA500}Info: {FFFFFF}You have {FF0000}disabled{FFFFFF} Automatic Grammar-Checking. ", -1)
- else
- autoGrammarEnabled = true
- sampAddChatMessage("{FFA500}Info: {FFFFFF}You have {00FF00}enabled{FFFFFF} Automatic Grammar-Checking.", -1)
- end
- saveGrammarState()
- end
- function autoCorrectSentence(msg)
- msg = msg:match("^%s*(.-)%s*$")
- msg = msg:sub(1, 1):upper() .. msg:sub(2)
- if not msg:find("[%.!%?]$") then
- msg = msg .. "."
- end
- msg = msg:gsub("([%.!?]%s*)(%l)", function(punct, letter)
- return punct .. letter:upper()
- end)
- return msg
- end
- function saveGrammarState()
- local f = io.open(configFile, "w")
- if f then
- f:write("[Settings]\n")
- f:write("autoGrammarEnabled=" .. tostring(autoGrammarEnabled) .. "\n")
- f:close()
- end
- end
- function loadGrammarState()
- local f = io.open(configFile, "r")
- if f then
- local content = f:read("*all")
- f:close()
- local enabled = content:match("autoGrammarEnabled=(%w+)")
- if enabled == "false" then
- autoGrammarEnabled = false
- else
- autoGrammarEnabled = true
- end
- end
- end
- function doesDirectoryExist(path)
- local f = io.open(path, "r")
- if f then
- f:close()
- return true
- else
- return false
- end
- end
- function createDirectory(path)
- os.execute("mkdir " .. path)
- end
- function doesFileExist(path)
- local f = io.open(path, "r")
- return f ~= nil
- end
- function blankIni()
- autoGrammarEnabled = false
- saveGrammarState()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement