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 - ( Server side )
- ------------------------------------------------------------------------------------
- local con = dbConnect("mysql", "dbname=;host=", "", "")
- -- local con = dbConnect("sqlite", "//feedbacks.db")
- dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
- local antibug1 = { -- with this we filter and remove the months with the year. example August 2018. If we do not do this the gridlist will show the dates.
- "January", "February", "March", "April", "May", "June", "July",
- "August", "September", "October", "November", "December",
- }
- local antibug2 = { -- with this we can fix the error caused by detecting something like this inside the string (-30 decreased).
- "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 -- Years filter
- function processUpdates(data)
- local cache = {}
- local updates = ""..data..""
- for k = startAge, endAge do
- for index, v in ipairs(antibug1) do
- updates = string.gsub(updates, ""..v.." "..k.."", "")
- end
- end
- local updates = string.gsub(updates, "\n", "")
- local updates = string.gsub(updates, "\r", "")
- for i, v in ipairs(antibug2) do
- 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
- return cache
- end
- function getUpdatesList(player)
- if (isGuestAccount(getPlayerAccount(player))) then
- return false
- end
- if (exports.CITchecking:getPlayerTimeSinceLastOccurence(player, "feedback") < 3000) then
- return false
- end
- local conversion = processUpdates(exports.CITupdatesInfo:getUpdates()) or {}
- exports.CITchecking:setPlayerOccurenceTime(player, "feedback")
- if (#conversion == 0) then
- outputChatBox("The feedback list is not loaded yet, retry later.", player, 255, 0, 0)
- else
- triggerClientEvent(player, "CITfeedback.sendFeedbackList", player, conversion)
- end
- end
- addCommandHandler("feedback", getUpdatesList)
- function sendFeedback(message, update)
- if (isGuestAccount(getPlayerAccount(client))) then
- return false
- 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 false
- 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)
- function cleanDB(player)
- if exports.CITadmin:getPlayerAdminLevel(player) == 5 then
- dbExec(con, "DELETE FROM feedbacks")
- exports.CIThelp:dm("Feedback cleaned", player, 255, 255, 0)
- end
- end
- addCommandHandler("cleancomments", cleanDB)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement