Skip to content

Commit

Permalink
refactor: integrate pending report check into main function
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires committed Dec 11, 2024
1 parent 91daaef commit 6c5413f
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions data/scripts/eventcallbacks/player/on_report_rule_violation.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
local function hasPendingReport(name, targetName, reportType)
local filePath = string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType)
local file = io.open(filePath, "r")
if file then
io.close(file)
return true
end
return false
end

local callback = EventCallback("PlayerOnReportRuleViolation")

function callback.playerOnReportRuleViolation(player, targetName, reportType, reportReason, comment, translation)
local name = player:getName()

if hasPendingReport(name, targetName, reportType) then
local filePath = string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType)
local file = io.open(filePath, "r")
if file then
io.close(file)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your report is being processed.")
return
end

local filePath = string.format("%s/reports/players/%s-%s-%d.txt", CORE_DIRECTORY, name, targetName, reportType)
local file = io.open(filePath, "a")
file = io.open(filePath, "a")
if not file then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There was an error when processing your report, please contact a gamemaster.")
return
Expand Down

0 comments on commit 6c5413f

Please sign in to comment.