Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------------------------------
- -- COMMUNITY CONTRIBUTION FOR CIT2.NET
- -- PURPOSE: Feedback for the updates
- -- DEVELOPERS: Nikos , Zelda
- ------------------------------------------------------------------------------------
- local dbname =
- local host =
- local username =
- local password =
- local con = dbConnect("mysql", "dbname="..dbname..";host="..host.."", ""..username.."", ""..password.."")
- dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
- -- local con = dbConnect("sqlite", "//feedbacks.db")
- -- dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
- -- dbExec(con, "DELETE FROM feedbacks")
- local removeTable ={
- -- day
- "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
- -- days
- "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th",
- "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st",
- "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st",
- }
- local months = { -- fix age bug from string
- "January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December",
- }
- local antibug = {
- "a","b","c","d","e","f","g","h","i","j","k","l","m",
- "n","o","p","k","r","s","t","u","v","w","x","y","z",
- "1","2","3","4","5","6","7","8","9","10",
- }
- local startAge, endAge = 2018, 2070 -- age filtrer
- function onResourceStart()
- cache = {}
- fetchRemote("https://cit2.net/updates.txt", sendData, "", false)
- end
- addEventHandler("onResourceStart", resourceRoot, onResourceStart)
- function sendData(data, error)
- if (error == 0) then
- updates = ""..data..""
- for k = startAge, endAge do
- for index, v in ipairs(months) do
- updates = string.gsub(updates, ""..v.." "..k.."", "")
- end
- end
- for index, v in ipairs(removeTable) do
- updates = string.gsub(updates, ""..v.." ", "")
- end
- local updates = string.gsub(updates, "\n", "")
- local updates = string.gsub(updates, "\r", "")
- for i, v in ipairs(antibug) do -- fix bug ( - ).
- updates = string.gsub(updates, "-"..v.."", "~"..v.."")
- end
- local ent = split(updates, "-") or {}
- for i, v in ipairs(ent) do
- table.insert(cache, ""..i..". "..v)
- end
- end
- end
- function getUpdatesList()
- if (isGuestAccount(getPlayerAccount(client))) then
- return
- end
- if (#cache == 0) then
- outputChatBox("The feedback list is not loaded yet, retry later.", client, 255, 0, 0)
- else
- triggerClientEvent(client, "CITfeedback.sendFeedbackList", client, cache)
- end
- end
- addEvent("CITfeedback.getUpdatesList", true )
- addEventHandler("CITfeedback.getUpdatesList", root, getUpdatesList)
- function sendFeedback(message, update)
- if (isGuestAccount(getPlayerAccount(client))) then
- return
- end
- local name = getPlayerName(client)
- local accname = getAccountName(getPlayerAccount(client))
- local results = dbPoll(dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) ,-1)
- if (#results == 0) then
- local cc = "- "..name.." ("..accname..")\n"..message..""
- dbExec(con,"INSERT INTO feedbacks VALUES (?, ?)", update, cc, accname)
- exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
- else
- if (string.find(results[1]["message"], "("..accname..")")) then
- exports.CIThelp:dm("You have already made a comment to this update.", client, 255, 0, 0)
- return
- end
- local cc = ""..results[1]["message"].."\n- "..name.." ("..accname..")\n"..message..""
- dbExec(con, "UPDATE feedbacks SET message=? WHERE update_post=?", cc, update)
- exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
- end
- end
- addEvent("CITfeedback.sendFeedback", true )
- addEventHandler("CITfeedback.sendFeedback", root, sendFeedback)
- function getGridData(update)
- local result = dbPoll( dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) , -1)
- if (type(result) == "table" and #result ~= 0) then
- triggerClientEvent(client, "CITfeedback.sendGridData", client, result[1]["message"])
- else
- triggerClientEvent(client, "CITfeedback.sendGridData", client, "No comments yet.")
- end
- end
- addEvent("CITfeedback.getGridData", true )
- addEventHandler("CITfeedback.getGridData", root, getGridData)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement