Advertisement
RyanUSNS

CITsupport - Server

May 24th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.31 KB | None | 0 0
  1. local SupportBOTName = "[CIT]Support BOT"
  2. local SupportBOT = {
  3.         ['ping'] = 'Pong',
  4.         ['i need help'] = 'Hey, please state your issue so I can assist you.',
  5.         ['help me'] = 'Hey, please state your issue so I can assist you.',
  6.         ['how to earn money?'] = 'Hey, please press F1 > press the "help" tab and search for "How to make Money".',
  7.         ['i need money'] = 'Hey, press F1 > press the "help" tab and search for "How to make Money".',
  8.         ['how to get my vehicle back?'] = 'Press F2 > select the vehicle and click "Recover".',
  9.         ['what is vip?'] = 'Press F1 > Click the "Help" tab and search for "what is VIP".',
  10. }
  11.  
  12. --Permission Stuff
  13. function OpenSupGUI(client, commandName)
  14.     if (isGuestAccount(getPlayerAccount(client))) then
  15.         return false
  16.     end
  17.     triggerClientEvent(client, "OnPlayerOpenGUI", client)
  18. end
  19. addCommandHandler("openticket", OpenSupGUI)
  20.  
  21. function OpenAIGUI(client, commandName)
  22.     if (isGuestAccount(getPlayerAccount(client)) or not hasObjectPermissionTo(client, "command.staff", false)) then
  23.         return false
  24.     end
  25.     triggerClientEvent(client, "OnPlayerOpenAIGUI", client)
  26. end
  27. addCommandHandler("aipanel", OpenAIGUI)
  28.  
  29. --Ticket Stuff
  30. local tickets = {}  --Server side storage
  31. local messages = {} --Server side storage
  32.  
  33. --Returns list of all tickets
  34. function GetTickets()
  35.     triggerClientEvent(client, "loadTickets", source, tickets)
  36. end
  37. addEvent("getTickets", true)
  38. addEventHandler("getTickets", resourceRoot, GetTickets)
  39.  
  40. --Returns messages of one ticket
  41. function GetTicket(ticketId)
  42.     if (not ticketId or not messages[ticketId]) then
  43.         return false
  44.     end
  45.     triggerClientEvent(client, "loadTicket", source, messages[ticketId])
  46. end
  47. addEvent("getTicket", true)
  48. addEventHandler("getTicket", resourceRoot, GetTicket)
  49.  
  50. --Creates a new ticket, stores it in tickets list and it's messages
  51. function AddTicket(ticket)
  52.     if (not ticket) then
  53.         return false
  54.     end
  55.     local ticketId = ticket[1]
  56.     local ticketinfo = {ticket[1], ticket[2], ticket[3], getTickCount(), 0}
  57.     tickets[ticketId] = ticketinfo
  58.     messages[ticketId] = ticket[4]
  59.     --Support BOT
  60.     CallSupportBot(ticketId, ticket[4][1][3])
  61.     GetTickets()
  62.     for i, player in ipairs(getElementsByType("player")) do
  63.         if (getTeamName(getPlayerTeam(player)) == "Staff") then
  64.             outputChatBox("#B266FF(Support) #FFFFFFA new help ticket is created. Press J to view the ticket.", player, 255, 255, 255, true)
  65.         end
  66.     end
  67. end
  68. addEvent("addTicket", true)
  69. addEventHandler("addTicket", resourceRoot, AddTicket)
  70.  
  71. --Delete player ticket
  72. function DelTicket(ticket)
  73.     if (not ticket or not tickets[ticket[1]] or not hasObjectPermissionTo(client, "command.staff", false)) then
  74.         return false
  75.     end
  76.     tickets[ticket[1]] = nil
  77.     messages[ticket[1]] = nil
  78.     GetTickets()
  79. end
  80. addEvent("delTicket", true)
  81. addEventHandler("delTicket", resourceRoot, DelTicket)
  82.  
  83. --Save a new message inside a ticket
  84. function SendMessage(message)
  85.     if (not message) then
  86.         return false
  87.     end
  88.     local plrName = getPlayerName(client)
  89.     local ticketId = message[1]
  90.     if (not tickets[ticketId] or not messages[ticketId] or not hasObjectPermissionTo(client, "command.staff", false) or plrName ~= tickets[ticketId][3]) then
  91.         return false
  92.     end
  93.     table.insert(messages[ticketId], message[2])
  94.     --Support BOT
  95.     CallSupportBot(ticketId, message[2][3])
  96.     GetTicket(ticketId)
  97. end
  98. addEvent("sendMessage", true)
  99. addEventHandler("sendMessage", resourceRoot, SendMessage)
  100.  
  101. --AI Function
  102. function CallSupportBot(ticketId, message)
  103.     if (not message or not tickets[ticketId] or not messages[ticketId]) then
  104.         return false
  105.     end
  106.     --Support BOT
  107.     local text = string.lower(message)
  108.     if (SupportBOT[text]) then
  109.         local aiMessage = {getTickCount(), SupportBOTName, SupportBOT[text]}
  110.         table.insert(messages[ticketId], aiMessage)
  111.         outputChatBox("#B266FF(Support) #FFFFFF"..SupportBOTName..": "..SupportBOT[text], client, 255, 255, 255, true)
  112.     end
  113. end
  114.  
  115. function SolveTicket(ticketId)
  116.     if (getElementType(client) ~= "player") then
  117.         return false
  118.     end
  119.     local plrName = getPlayerName(client)
  120.     if (not ticketId or not tickets[ticketId] or not hasObjectPermissionTo(client, "command.staff", false) or plrName ~= tickets[ticketId][3]) then
  121.         return false
  122.     end
  123.     tickets[ticketId][5] = 1 --1 means the ticket is solved, esle not solved.
  124.     GetTickets()
  125. end
  126. addEvent("solveTicket", true)
  127. addEventHandler("solveTicket", resourceRoot, SolveTicket)
  128.  
  129. --AI Database Input
  130. function AddSupQ(text, msg)
  131.     if (SupportBOT[text]) then
  132.         outputChatBox("#FF0000[CIT]Support: #FFFFFFI already have that in my database.", client, 255, 255, 255, true)
  133.         return false
  134.     end
  135.     SupportBOT[text] = msg
  136. end
  137. addEvent("AIconfig", true)
  138. addEventHandler("AIconfig", resourceRoot, AddSupQ)
  139.  
  140. --Database Table
  141. function SaveAIDatabase(thePlayer, commandName, backup)
  142.     if (not hasObjectPermissionTo(thePlayer, "command.staff", false)) then
  143.         return false
  144.     end
  145.     local createfile = fileCreate('backup.json')
  146.     if (not fileExists('backup.json')) then
  147.         return false
  148.     end
  149.     backup = fileOpen('backup.json')
  150.     fileWrite(backup, toJSON(SupportBOT))
  151.     fileClose(backup)
  152.     outputChatBox("AI Table Added To Database.", thePlayer, 50, 255, 50, true)
  153. end
  154. addCommandHandler("SaveDB", SaveAIDatabase)
  155.  
  156. function LoadAIDatabase(thePlayer, commandName, backup)
  157.     if (not hasObjectPermissionTo(thePlayer, "command.staff", false)) then
  158.         return false
  159.     end
  160.     if (not fileExists('backup.json')) then
  161.         outputChatBox("Database Does not exists.", thePlayer, 255, 50, 50, true)
  162.         return false
  163.     end
  164.     local file = fileOpen('backup.json')
  165.     local size = fileGetSize(file)
  166.     local buffer = fileRead(file, size)
  167.     SupportBOT = fromJSON(buffer)
  168.     fileClose(file)
  169.     outputChatBox("AI Database Successfully Loaded.", thePlayer, 50, 255, 50, true)
  170. end
  171. addCommandHandler("LoadDB", LoadAIDatabase)
  172.  
  173. function DeleteAIDatabase(thePlayer, commandName, backup)
  174.     if (not hasObjectPermissionTo(thePlayer, "command.staff", false)) then
  175.         return false
  176.     end
  177.     if (fileExists('backup.json')) then
  178.         backup = fileOpen('backup.json')
  179.         fileClose(backup)
  180.         fileDelete('backup.json')
  181.     end
  182.     if (not fileExists('backup.json')) then
  183.         outputChatBox("AI Database Successfully Deleted.", thePlayer, 50, 255, 50, true)
  184.     else
  185.         outputChatBox("Ops, something went wrong.. Please restart the resource then use this command again.", thePlayer, 255, 50, 50, true)
  186.     end
  187. end
  188. addCommandHandler("DeleteDB", DeleteAIDatabase)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement