daily pastebin goal
3%
SHARE
TWEET

feedback.slua

a guest Dec 13th, 2018 68 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.         comments[update] = cc
  57.         dbExec(con,"INSERT INTO feedbacks VALUES (?, ?)", update, cc, accname)
  58.         exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
  59.     else
  60.         if (string.find(results, "("..accname..")")) then
  61.             exports.CIThelp:dm("You have already made a comment to this update.", client, 255, 0, 0)
  62.             return false
  63.         end
  64.         local cc = ""..results.."\n- "..name.." ("..accname..")\n"..message..""
  65.         comments[update] = cc
  66.         dbExec(con, "UPDATE feedbacks SET message=? WHERE update_post=?", cc, update)
  67.         exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
  68.     end
  69. end
  70. addEvent("CITfeedback.sendFeedback", true )
  71. addEventHandler("CITfeedback.sendFeedback", root, sendFeedback)
  72.  
  73. function getGridData(update)
  74.     local result = dbPoll( dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) , -1)
  75.     if (type(result) == "table" and #result ~= 0) then
  76.         triggerClientEvent(client, "CITfeedback.sendGridData", client, result[1]["message"])
  77.     else
  78.         triggerClientEvent(client, "CITfeedback.sendGridData", client, "No comments yet.")
  79.     end
  80. end
  81. addEvent("CITfeedback.getGridData", true )
  82. addEventHandler("CITfeedback.getGridData", root, getGridData)
  83.  
  84. function cleanDB(player)
  85.     if (exports.CITadmin:getPlayerAdminLevel(player) == 5) then
  86.         dbExec(con, "DELETE FROM feedbacks")
  87.         comments = {}
  88.         exports.CIThelp:dm("Feedback cleaned", player, 255, 255, 0)
  89.     end
  90. end
  91. 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
 
Top