Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: report system bug fixed #65

Merged
merged 2 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 24 additions & 33 deletions client/reports.lua
Original file line number Diff line number Diff line change
@@ -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,
header = ('Report ID: %s | Sender: %s'):format(report.id, report.senderName),
content = ('message: %s'):format(report.message),
centered = true,
cancel = false,
size = 'lg',
Expand All @@ -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)
local input = lib.inputDialog(string.format('Report ID: %s | Sender: %s', report.id, report.senderName), {
elseif selected == 2 then
local input = lib.inputDialog(('Report ID: %s | Sender: %s'):format(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(locale('success.report_load'):format(#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 = locale('report_options.label1'):format(reports[i].id, reports[i].senderName), description = locale('report_options.desc1'), args = {reports[i]}}
end

lib.registerMenu({
Expand All @@ -57,13 +56,13 @@ function GenerateReportMenu()
onSelected = function(selected)
MenuIndexes.qbx_adminmenu_reports_menu = selected
end,
options = optionsList
options = reportsList
}, function(_, _, args)
local report = args[1]

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')
Expand All @@ -75,22 +74,14 @@ 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)
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)

Expand Down
10 changes: 7 additions & 3 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -145,6 +145,7 @@
}
},
"report_options": {
"label1": "Report ID: %s | Sender: %s",
"desc1": "Click to view report options"
},
"success": {
Expand All @@ -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"
}
}
37 changes: 22 additions & 15 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local config = require 'config.server'
local isFrozen = {}
local reportsCount = 0

REPORTS = {}

Expand All @@ -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,
Expand Down Expand Up @@ -50,27 +52,32 @@ 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)

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 = {
Expand Down