· 7 years ago · Dec 08, 2018, 03:08 PM
1------------------------------------------------------------------------------------
2-- COMMUNITY CONTRIBUTION FOR CIT2.NET
3-- PURPOSE: Feedback for the updates
4-- DEVELOPERS: Nikos , Zelda
5------------------------------------------------------------------------------------
6
7local dbname =
8local host =
9local username =
10local password =
11local con = dbConnect("mysql", "dbname="..dbname..";host="..host.."", ""..username.."", ""..password.."")
12dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
13
14-- local con = dbConnect("sqlite", "//feedbacks.db")
15-- dbExec(con, "CREATE TABLE IF NOT EXISTS feedbacks (update_post TEXT, message TEXT)")
16-- dbExec(con, "DELETE FROM feedbacks")
17
18local removeTable ={
19 -- day
20 "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
21
22 -- days
23 "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th", "10th", "11th",
24 "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th", "21st",
25 "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th", "31st",
26}
27
28local months = { -- fix age bug from string
29 "January", "February", "March", "April", "May", "June", "July",
30 "August", "September", "October", "November", "December",
31}
32
33local antibug = {
34 "a","b","c","d","e","f","g","h","i","j","k","l","m",
35 "n","o","p","k","r","s","t","u","v","w","x","y","z",
36 "1","2","3","4","5","6","7","8","9","10",
37}
38
39local startAge, endAge = 2018, 2070 -- age filtrer
40
41function process_updates(data)
42 local cache = {}
43 local updates = ""..data..""
44 for k = startAge, endAge do
45 for index, v in ipairs(months) do
46 updates = string.gsub(updates, ""..v.." "..k.."", "")
47 end
48 end
49 for index, v in ipairs(removeTable) do
50 updates = string.gsub(updates, ""..v.." ", "")
51 end
52 local updates = string.gsub(updates, "\n", "")
53 local updates = string.gsub(updates, "\r", "")
54 for i, v in ipairs(antibug) do -- fix bug ( - ).
55 updates = string.gsub(updates, "-"..v.."", "~"..v.."")
56 end
57 local ent = split(updates, "-") or {}
58 for i, v in ipairs(ent) do
59 table.insert(cache, ""..i..". "..v)
60 end
61 return cache
62end
63
64function getUpdatesList()
65 if (isGuestAccount(getPlayerAccount(client))) then
66 return
67 end
68 local conversion = process_updates(exports.CITupdatesInfo:getUpdates()) or {}
69 if (#conversion == 0) then
70 outputChatBox("The feedback list is not loaded yet, retry later.", client, 255, 0, 0)
71 else
72 triggerClientEvent(client, "CITfeedback.sendFeedbackList", client, conversion)
73 end
74end
75addEvent("CITfeedback.getUpdatesList", true )
76addEventHandler("CITfeedback.getUpdatesList", root, getUpdatesList)
77
78function sendFeedback(message, update)
79 if (isGuestAccount(getPlayerAccount(client))) then
80 return
81 end
82 local name = getPlayerName(client)
83 local accname = getAccountName(getPlayerAccount(client))
84 local results = dbPoll(dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) ,-1)
85 if (#results == 0) then
86 local cc = "- "..name.." ("..accname..")\n"..message..""
87 dbExec(con,"INSERT INTO feedbacks VALUES (?, ?)", update, cc, accname)
88 exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
89 else
90 if (string.find(results[1]["message"], "("..accname..")")) then
91 exports.CIThelp:dm("You have already made a comment to this update.", client, 255, 0, 0)
92 return
93 end
94 local cc = ""..results[1]["message"].."\n- "..name.." ("..accname..")\n"..message..""
95 dbExec(con, "UPDATE feedbacks SET message=? WHERE update_post=?", cc, update)
96 exports.CIThelp:dm("Feedback sended", client, 0, 255, 0)
97 end
98end
99addEvent("CITfeedback.sendFeedback", true )
100addEventHandler("CITfeedback.sendFeedback", root, sendFeedback)
101
102function getGridData(update)
103 local result = dbPoll( dbQuery(con, "SELECT * FROM feedbacks WHERE update_post=?", update) , -1)
104 if (type(result) == "table" and #result ~= 0) then
105 triggerClientEvent(client, "CITfeedback.sendGridData", client, result[1]["message"])
106 else
107 triggerClientEvent(client, "CITfeedback.sendGridData", client, "No comments yet.")
108 end
109end
110addEvent("CITfeedback.getGridData", true )
111addEventHandler("CITfeedback.getGridData", root, getGridData)