From 4ec0ec10454d3fafb4086b666c8842d039051951 Mon Sep 17 00:00:00 2001 From: MrCrAGoNz <109719216+MrCrAGoNz@users.noreply.github.com> Date: Fri, 23 Aug 2024 00:51:32 +0530 Subject: [PATCH 1/2] fix: #61 --- client/reports.lua | 43 +++++++++++++++++-------------------------- locales/en.json | 10 +++++++--- server/main.lua | 39 +++++++++++++++++++++++---------------- 3 files changed, 47 insertions(+), 45 deletions(-) diff --git a/client/reports.lua b/client/reports.lua index 70a905d..5e54ccf 100644 --- a/client/reports.lua +++ b/client/reports.lua @@ -1,8 +1,8 @@ -local reportOptions = { - function(report) +local function reportAction(selected, report) + if selected == 1 then lib.alertDialog({ header = string.format('Report ID: %s | Sender: %s', report.id, report.senderName), - content = report.message, + content = string.format('message: %s', report.message), centered = true, cancel = false, size = 'lg', @@ -12,39 +12,38 @@ local reportOptions = { }) lib.showMenu(('qbx_adminmenu_reports_menu_%s'):format(report.id), MenuIndexes[('qbx_adminmenu_reports_menu_%s'):format(report.id)]) - end, - function(report) + elseif selected == 2 then local input = lib.inputDialog(string.format('Report ID: %s | Sender: %s', report.id, report.senderName), { {type = 'input', label = 'Reply'} }) - - if not input then + if input[1] == '' then exports.qbx_core:Notify(locale('error.no_report_reply'), 'error') else TriggerServerEvent('qbx_admin:server:sendReply', report, input[1]) end lib.showMenu(('qbx_adminmenu_reports_menu_%s'):format(report.id), MenuIndexes[('qbx_adminmenu_reports_menu_%s'):format(report.id)]) - end, - function(report) + elseif selected == 3 then TriggerServerEvent('qbx_admin:server:deleteReport', report) - GenerateReportMenu() + else + return lib.showMenu(('qbx_adminmenu_reports_menu_%s'):format(report.id), MenuIndexes[('qbx_adminmenu_reports_menu_%s'):format(report.id)]) end -} +end function GenerateReportMenu() local reports = lib.callback.await('qbx_admin:server:getReports', false) if not reports or #reports < 1 then - lib.showMenu('qbx_adminmenu_main_menu', MenuIndexes.qbx_adminmenu_main_menu) - return + exports.qbx_core:Notify(locale('error.no_reports'), 'error') + return lib.showMenu('qbx_adminmenu_main_menu', MenuIndexes.qbx_adminmenu_main_menu) + else + exports.qbx_core:Notify(string.format(locale('success.report_load'), #reports), 'success') end - local optionsList = {} - + local reportsList = {} for i = 1, #reports do - optionsList[#optionsList + 1] = {label = string.format('Report ID: %s | Sender: %s', reports[i].id, reports[i].senderName), description = locale('report_options.desc1'), args = {reports[i]}} + reportsList[i] = {label = string.format(locale('report_options.label1'), reports[i].id, reports[i].senderName), description = locale('report_options.desc1'), args = {reports[i]}} end lib.registerMenu({ @@ -57,7 +56,7 @@ function GenerateReportMenu() onSelected = function(selected) MenuIndexes.qbx_adminmenu_reports_menu = selected end, - options = optionsList + options = reportsList }, function(_, _, args) local report = args[1] @@ -81,16 +80,8 @@ function GenerateReportMenu() {label = string.format('Sender Name: %s', report.senderName)} } }, function(selected) - local reportOption = reportOptions[selected] - - if not reportOption then - lib.showMenu(('qbx_adminmenu_reports_menu_%s'):format(report.id), MenuIndexes[('qbx_adminmenu_reports_menu_%s'):format(report.id)]) - return - end - - reportOption(report) + reportAction(selected, report) end) - lib.showMenu(('qbx_adminmenu_reports_menu_%s'):format(report.id), MenuIndexes[('qbx_adminmenu_reports_menu_%s'):format(report.id)]) end) diff --git a/locales/en.json b/locales/en.json index 6be6b89..f907091 100644 --- a/locales/en.json +++ b/locales/en.json @@ -19,7 +19,7 @@ "label5": "Developer Options", "desc5": "Options that are handy for a developer", "label6": "Pending Reports", - "desc6": "Someone needs to do it :(" + "desc6": "Manage pending reports" }, "admin_options": { "label1": "Noclip", @@ -145,6 +145,7 @@ } }, "report_options": { + "label1": "Report ID: %s | Sender: %s", "desc1": "Click to view report options" }, "success": { @@ -154,12 +155,15 @@ "heading_copied": "Heading copied to clipboard", "report_sent": "Report has been sent", "new_report": "A new report has been received", - "sent_report_reply": "Your reply has been sent" + "sent_report_reply": "Your reply has been sent", + "report_load": "%s report(s) loaded", + "report_claimed_by": "Report #%s was claimed by %s" }, "error": { "no_perms": "You don't have permission to do this", "blips_deactivated": "Blips deactivated", "names_deactivated": "Names deactivated", - "no_report_reply": "Reply failed to send due to no message" + "no_report_reply": "Reply failed to send due to no message", + "no_reports": "no pending reports to load" } } diff --git a/server/main.lua b/server/main.lua index 349a82f..4171ea4 100644 --- a/server/main.lua +++ b/server/main.lua @@ -1,5 +1,6 @@ local config = require 'config.server' local isFrozen = {} +local reportsCount = 0 REPORTS = {} @@ -19,9 +20,10 @@ end --- @param message string - Message for the report function SendReport(source, message) local reportId = #REPORTS + 1 + reportsCount += 1 REPORTS[reportId] = { - id = reportId, + id = reportsCount, senderId = source, senderName = GetPlayerName(source), message = message, @@ -50,19 +52,20 @@ end RegisterNetEvent('qbx_admin:server:sendReply', function(report, message) if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end - if REPORTS[report.id] then - local name = GetPlayerName(source) - - TriggerClientEvent('chatMessage', report.senderId, "", {255, 0, 0}, string.format('[REPORT #%s] [%s] ^7%s', report.id, name, message)) - - exports.qbx_core:Notify(source, locale('success.sent_report_reply'), 'success') - - if REPORTS[report.id].claimed == 'Nobody' then - REPORTS[report.id].claimed = name - - OnAdmin(config.commandPerms.reportReply, function(target) - exports.qbx_core:Notify(target.PlayerData.source, string.format('Report #%s was claimed by %s', report.id, name), 'success') - end) + for k, v in pairs(REPORTS) do + if v.id == report.id then + local name = GetPlayerName(source) + + TriggerClientEvent('chatMessage', report.senderId, "", {255, 0, 0}, string.format('[REPORT #%s] [%s] ^7%s', report.id, name, message)) + + exports.qbx_core:Notify(source, locale('success.sent_report_reply'), 'success') + if REPORTS[k].claimed == 'Nobody' then + REPORTS[k].claimed = name + OnAdmin(config.commandPerms.reportReply, function(target) + exports.qbx_core:Notify(target.PlayerData.source, string.format(locale('success.report_claimed_by'), report.id, name), 'success') + end) + end + return end end end) @@ -70,7 +73,11 @@ end) RegisterNetEvent('qbx_admin:server:deleteReport', function(report) if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end - REPORTS[report.id] = nil + for k, v in pairs(REPORTS) do + if v.id == report.id then + return table.remove(REPORTS, k) + end + end end) local generalOptions = { @@ -296,6 +303,6 @@ end) lib.callback.register('qbx_admin:server:getReports', function(source) if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end - + return REPORTS end) \ No newline at end of file From 7b2519c45fd1e2bf9e305774e831f7a6dcef10b7 Mon Sep 17 00:00:00 2001 From: MrCrAGoNz <109719216+MrCrAGoNz@users.noreply.github.com> Date: Fri, 23 Aug 2024 01:51:25 +0530 Subject: [PATCH 2/2] changes --- client/reports.lua | 20 ++++++++++---------- server/main.lua | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/client/reports.lua b/client/reports.lua index 5e54ccf..ec645d1 100644 --- a/client/reports.lua +++ b/client/reports.lua @@ -1,8 +1,8 @@ local function reportAction(selected, report) if selected == 1 then lib.alertDialog({ - header = string.format('Report ID: %s | Sender: %s', report.id, report.senderName), - content = string.format('message: %s', report.message), + header = ('Report ID: %s | Sender: %s'):format(report.id, report.senderName), + content = ('message: %s'):format(report.message), centered = true, cancel = false, size = 'lg', @@ -13,7 +13,7 @@ local function reportAction(selected, report) lib.showMenu(('qbx_adminmenu_reports_menu_%s'):format(report.id), MenuIndexes[('qbx_adminmenu_reports_menu_%s'):format(report.id)]) elseif selected == 2 then - local input = lib.inputDialog(string.format('Report ID: %s | Sender: %s', report.id, report.senderName), { + local input = lib.inputDialog(('Report ID: %s | Sender: %s'):format(report.id, report.senderName), { {type = 'input', label = 'Reply'} }) if input[1] == '' then @@ -38,12 +38,12 @@ function GenerateReportMenu() exports.qbx_core:Notify(locale('error.no_reports'), 'error') return lib.showMenu('qbx_adminmenu_main_menu', MenuIndexes.qbx_adminmenu_main_menu) else - exports.qbx_core:Notify(string.format(locale('success.report_load'), #reports), 'success') + exports.qbx_core:Notify(locale('success.report_load'):format(#reports), 'success') end local reportsList = {} for i = 1, #reports do - reportsList[i] = {label = string.format(locale('report_options.label1'), reports[i].id, reports[i].senderName), description = locale('report_options.desc1'), args = {reports[i]}} + reportsList[i] = {label = locale('report_options.label1'):format(reports[i].id, reports[i].senderName), description = locale('report_options.desc1'), args = {reports[i]}} end lib.registerMenu({ @@ -62,7 +62,7 @@ function GenerateReportMenu() lib.registerMenu({ id = ('qbx_adminmenu_reports_menu_%s'):format(report.id), - title = string.format('Report ID: %s | Sender: %s', report.id, report.senderName), + title = ('Report ID: %s | Sender: %s'):format(report.id, report.senderName), position = 'top-right', onClose = function(keyPressed) CloseMenu(false, keyPressed, 'qbx_adminmenu_reports_menu') @@ -74,10 +74,10 @@ function GenerateReportMenu() {label = 'View Message', icon = 'fas fa-message'}, {label = 'Send Message', icon = 'fas fa-reply'}, {label = 'Close Report', icon = 'fas fa-trash'}, - {label = string.format('Claimed By: %s', report.claimed)}, - {label = string.format('Report ID: %s', report.id)}, - {label = string.format('Sender ID: %s', report.senderId)}, - {label = string.format('Sender Name: %s', report.senderName)} + {label = ('Claimed By: %s'):format(report.claimed)}, + {label = ('Report ID: %s'):format(report.id)}, + {label = ('Sender ID: %s'):format(report.senderId)}, + {label = ('Sender Name: %s'):format(report.senderName)} } }, function(selected) reportAction(selected, report) diff --git a/server/main.lua b/server/main.lua index 4171ea4..5f7311b 100644 --- a/server/main.lua +++ b/server/main.lua @@ -303,6 +303,6 @@ end) lib.callback.register('qbx_admin:server:getReports', function(source) if not IsPlayerAceAllowed(source, config.commandPerms.reportReply) then exports.qbx_core:Notify(source, locale('error.no_perms'), 'error') return end - + return REPORTS end) \ No newline at end of file