SHARE
TWEET

feedback.slua

a guest Dec 13th, 2018 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ------------------------------------------------------------------------------------
  2. --  COMMUNITY CONTRIBUTION FOR CIT2.NET
  3. --  PURPOSE: Feedback for the updates
  4. --  DEVELOPERS: Nikos, Zelda - ( Server side )
  5. ------------------------------------------------------------------------------------
  6.  
  7. local comments = {}
  8. -- local con = dbConnect("sqlite", "//feedbacks.db")
  9. local con = dbConnect("mysql", "dbname=;host=", "", "")
  10. dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
  11.  
  12. function onResourceStart()
  13.     local results = dbPoll(dbQuery(con, "SELECT * FROM feedbacks") ,-1)
  14.     for i, v in ipairs(results) do
  15.         comments[v["update_post"]] = v["message"]
  16.     end
  17. end
  18. addEventHandler("onResourceStart", resourceRoot, onResourceStart)
  19.  
  20. function processUpdates(updates)
  21.     local cache = {}
  22.     for i, v in ipairs(split(updates, "\n") or {}) do
  23.         if  (string.byte(v, 1) == 45) then
  24.             table.insert(cache, ""..v.."")
  25.         end
  26.     end
  27.     return cache
  28. end
  29.  
  30. function getUpdatesList(player)
  31.     if (isGuestAccount(getPlayerAccount(player))) then
  32.         return false
  33.     end
  34.     if (exports.CITchecking:getPlayerTimeSinceLastOccurence(player, "feedback") < 3000) then
  35.         return false
  36.     end
  37.     local conversion = processUpdates(exports.CITupdatesInfo:getUpdates()) or {}
  38.     exports.CITchecking:setPlayerOccurenceTime(player, "feedback")
  39.     if (#conversion == 0) then
  40.         outputChatBox("The feedback list is not loaded yet, retry later.", player, 255, 0, 0)
  41.     else
  42.         triggerClientEvent(player, "CITfeedback.sendFeedbackList", player, conversion)
  43.     end
  44. end
  45. addCommandHandler("feedback", getUpdatesList)
  46.  
  47. function sendFeedback(message, update)
  48.     if (isGuestAccount(getPlayerAccount(client))) then
  49.         return false
  50.     end
  51.     local name = getPlayerName(client)
  52.     local accname = getAccountName(getPlayerAccount(client))
  53.     local results =  comments[update]
  54.     if (not results) then
  55.         local cc = "- "..name.." ("..accname..")\n"..message..""
  56.         dbExec(con,"INSERT INTO feedbacks VALUES (?, ?)", update, cc, accname)
  57.         exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
  58.     else
  59.         if (string.find(results, "("..accname..")")) then
  60.             exports.CIThelp:dm("You have already made a comment to this update.", client, 255, 0, 0)
  61.             return false
  62.         end
  63.         local cc = ""..results.."\n- "..name.." ("..accname..")\n"..message..""
  64.         dbExec(con, "UPDATE feedbacks SET message=? WHERE update_post=?", cc, update)
  65.         exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
  66.     end
  67. end
  68. addEvent("CITfeedback.sendFeedback", true )
  69. addEventHandler("CITfeedback.sendFeedback", root, sendFeedback)
  70.  
  71. function getGridData(update)
  72.     local result = dbPoll( dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) , -1)
  73.     if (type(result) == "table" and #result ~= 0) then
  74.         triggerClientEvent(client, "CITfeedback.sendGridData", client, result[1]["message"])
  75.     else
  76.         triggerClientEvent(client, "CITfeedback.sendGridData", client, "No comments yet.")
  77.     end
  78. end
  79. addEvent("CITfeedback.getGridData", true )
  80. addEventHandler("CITfeedback.getGridData", root, getGridData)
  81.  
  82. function cleanDB(player)
  83.     if (exports.CITadmin:getPlayerAdminLevel(player) == 5) then
  84.         dbExec(con, "DELETE FROM feedbacks")
  85.         comments = {}
  86.         exports.CIThelp:dm("Feedback cleaned", player, 255, 255, 0)
  87.     end
  88. end
  89. addCommandHandler("cleancomments", cleanDB)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top