local folderPath = [[data/botReports/]]
local channelId = 11
local exhaust = 60 * 1000 -- 1 minute
local exhausts = {}
local folderExists = false
for file in io.popen('dir "data/" /b /ad'):lines() do
if file:match("botReports") then
folderExists = true
end
end
if not folderExists then
os.execute('mkdir "'.. folderPath ..'"')
end
local function writeLog(filePath, text)
local file = io.open(filePath, "a+")
file:write(text .. "\n")
file:close()
end
function onSay(player, words, param)
if (param == "") then
return player:sendTextMessage(MESSAGE_INFO_DESCR, "Param required.") and false
end
local target = Player(param)
if not target then
return player:sendTextMessage(MESSAGE_INFO_DESCR, "Player is not online or you input an invalid player name.") and false
end
local exhausted = (exhausts[player:getId()] or 0) > os.mtime()
if not exhausted then
local reporter = player:getName()
local reported = target:getName()
local date = os.date()
sendChannelMessage(channelId, TALKTYPE_CHANNEL_R1, ("%s reported %s at [%s]"):format(reporter, reported, date))
writeLog(folderPath .. reporter .. ".log", ("[%s]: Reported player: %s."):format(date, reported))
exhausts[player:getId()] = os.mtime() + exhaust
return player:sendTextMessage(MESSAGE_INFO_DESCR, "Thank you for your report.") and false
else
return player:sendTextMessage(MESSAGE_INFO_DESCR, "You cannot report this fast.") and false
end
end