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

Remove audit logs #1698

Merged
merged 1 commit into from
Nov 11, 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
68 changes: 3 additions & 65 deletions MainModule/Server/Commands/HeadAdmins.luau
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
return function(Vargs, env)
local server = Vargs.Server;
local service = Vargs.Service;
local AuditLogsDataStore = service.DataStoreService:GetDataStore("AdonisAuditLogsDataStore")
local Settings = server.Settings
local Functions, Commands, Admin, Anti, Core, HTTP, Logs, Remote, Process, Variables, Deps =
server.Functions, server.Commands, server.Admin, server.Anti, server.Core, server.HTTP, server.Logs, server.Remote, server.Process, server.Variables, server.Deps
Expand Down Expand Up @@ -170,7 +169,7 @@ return function(Vargs, env)
Description = "Makes the target player(s) a temporary admin; does not save";
AdminLevel = "HeadAdmins";
Dangerous = true;
Function = function(plr: Player, args: {string}, data: {})
Function = function(plr: Player, args: {string}, data: any)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe convert to {any}

local senderLevel = data.PlayerData.Level

for _, v in service.GetPlayers(plr, assert(args[1], "Missing target player (argument #1)")) do
Expand All @@ -193,7 +192,7 @@ return function(Vargs, env)
Description = "Makes the target player(s) an admin; saves";
AdminLevel = "HeadAdmins";
Dangerous = true;
Function = function(plr: Player, args: {string}, data: {})
Function = function(plr: Player, args: {string}, data: any)
local senderLevel = data.PlayerData.Level

for _, v in service.GetPlayers(plr, assert(args[1], "Missing target user (argument #1)"), {
Expand Down Expand Up @@ -423,7 +422,7 @@ return function(Vargs, env)
hide_character=hideCharacter
}
if hideCharacter then
v.CharacterAdded:Connect(function(character: Model)
v.CharacterAdded:Connect(function(character: Model)
for _, otherPlr: Player in service.Players:GetPlayers(v, if hidefromEveryone then "others" else "nonadmins") do
if otherPlr == v then continue end
Remote.LoadCode(otherPlr, [[
Expand Down Expand Up @@ -530,66 +529,5 @@ return function(Vargs, env)
end
};

AuditLogs = {
Prefix = Settings.Prefix;
Commands = {"auditlogs", "moderationlogs", "modlogs"};
Args = {"player"};
Description = "Fetches the recent moderation activity logs of the specified moderator or admin.";
AdminLevel = "HeadAdmins";
Function = function(plr: Player, args: {string})
local targetPlayers = service.GetPlayers(plr, args[1], {NoFakePlayer = true})

if #targetPlayers == 0 then
Functions.Hint("No player found with the specified name.", {plr})
return
end

for _, targetPlayer in ipairs(targetPlayers) do
local userId = targetPlayer.UserId
local key = "AuditLogs_" .. tostring(userId)

local success, auditLogs = pcall(function()
return AuditLogsDataStore:GetAsync(key) or {}
end)

if not success then
warn("Failed to retrieve audit logs for UserId " .. tostring(userId) .. ": " .. auditLogs)
Functions.Hint("Error retrieving logs.", {plr})
return
end

local filteredLogs = {}
print("Checking audit logs for:", targetPlayer.Name, "with UserId:", userId)
print(auditLogs)

for _, log in ipairs(auditLogs) do
local moderatorName = Functions.GetNameFromUserIdAsync(log.ModeratorId) or "Unknown"
local targetUserName = log.TargetPlayer

if type(targetUserName) == "table" then
targetUserName = targetUserName.Name or "Unknown"
elseif targetUserName == nil then
targetUserName = "Unknown"
end

local timestamp = os.date("%Y-%m-%d %H:%M:%S", log.Time)

local logText = string.format("%s | %s | %s", moderatorName, log.Action, timestamp)
local logEntry = { Text = logText .. " | " .. targetUserName, Desc = log.Details }
table.insert(filteredLogs, logEntry)
end

if #filteredLogs == 0 then
Functions.Hint(`No audit logs found for {targetPlayer.Name}`, {plr})
else
Remote.MakeGui(plr, "List", {
Title = `Audit Logs for {targetPlayer.Name}`,
Table = filteredLogs,
Update = "filteredLogs"
})
end
end
end
};
}
end
8 changes: 4 additions & 4 deletions MainModule/Server/Commands/Players.luau
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ return function(Vargs, env)
Args = {"num m", "num n"};
Description = "Generates a number using Lua's math.random";
AdminLevel = "Players";
Function = function(plr: Player, args: {string})
Function = function(plr: Player, args: {any})
assert((not args[1]) or tonumber(args[1]), "Argument(s) provided must be numbers")
assert((not args[2]) or tonumber(args[2]), "Arguments provided must be numbers")

Expand Down Expand Up @@ -260,7 +260,7 @@ return function(Vargs, env)
"Rock", "Glacier", "Snow", "Sandstone", "Mud", "Basalt", "Ground", "CrackedLava", "Asphalt", "LeafyGrass", "Salt", "Limestone", "Pavement"
}
for i, mat in mats do
mats[i] = {Text = mat; Desc = `Enum value: {Enum.Material[mat].Value}`}
mats[i] = {Text = mat; Desc = `Enum value: {(Enum.Material[mat]::Enum.Material).Value}`}
end
Remote.MakeGui(plr, "List", {Title = "Materials"; Tab = mats; TextSelectable = true;})
end
Expand Down Expand Up @@ -455,12 +455,12 @@ return function(Vargs, env)
local UserId = Functions.GetUserIdFromNameAsync(args[1])
if UserId then
local success, samePlace, errorMessage, placeId, jobId = pcall(service.TeleportService.GetPlayerPlaceInstanceAsync, service.TeleportService, UserId)

if success then
if samePlace then
error("You're already in this server!")
end

if placeId and jobId then
service.TeleportService:TeleportAsync(placeId, {plr}, service.New("TeleportOptions", {
ServerInstanceId = jobId
Expand Down
42 changes: 7 additions & 35 deletions MainModule/Server/Core/Functions.luau
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ return function(Vargs, GetEnv)
local service = Vargs.Service

local logError
local AuditLogsDataStore; pcall(function()
AuditLogsDataStore = service.DataStoreService:GetDataStore("AdonisAuditLogsDataStore")
end)
local Functions, Admin, Anti, Core, HTTP, Logs, Remote, Process, Variables, Settings
local function Init()
Functions = server.Functions;
Expand Down Expand Up @@ -1048,30 +1045,7 @@ return function(Vargs, GetEnv)
end;

LogAdminAction = function(plr, action, targetPlayerName, additionalDetails)
local logEntry = {
Timestamp = os.time(),
ModeratorId = plr.UserId,
ModeratorName = plr.Name,
Action = action,
TargetPlayer = targetPlayerName,
AdditionalDetails = additionalDetails or "N/A",
}

-- Attempt to log the action under the moderator's UserId
local key = "AuditLogs_" .. tostring(plr.UserId)

local success, errMessage = pcall(function()
-- Get existing logs
local existingLogs = AuditLogsDataStore:GetAsync(key) or {}
table.insert(existingLogs, logEntry)
AuditLogsDataStore:SetAsync(key, existingLogs)
end)

if not success then
warn("Failed to log audit entry for UserId " .. tostring(plr.UserId) .. ": " .. errMessage)
else
print("Audit log entry saved for:", plr.Name)
end
-- kept function here for potential future reimplementation
end;

NewParticle = function(target, particleType, props)
Expand Down Expand Up @@ -1585,7 +1559,7 @@ return function(Vargs, GetEnv)
local Humanoid: Humanoid = plr.Character and plr.Character:FindFirstChildOfClass("Humanoid")

local HumanoidDescription = Humanoid:GetAppliedDescription() or service.Players:GetHumanoidDescriptionFromUserId(plr.UserId)
local newCharacterModel: Model = service.Players:CreateHumanoidModelFromDescription(HumanoidDescription, rigType, Enum.AssetTypeVerification.Always)
local newCharacterModel: any = service.Players:CreateHumanoidModelFromDescription(HumanoidDescription, rigType, Enum.AssetTypeVerification.Always)
local Animate: BaseScript = newCharacterModel.Animate

newCharacterModel.Humanoid.DisplayName = Humanoid.DisplayName
Expand Down Expand Up @@ -1632,7 +1606,7 @@ return function(Vargs, GetEnv)
})
end;

ParseColor3 = function(str: string?)
ParseColor3 = function(str: string)
if not str then return nil end
if str:lower() == "random" then
return Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))
Expand All @@ -1644,17 +1618,15 @@ return function(Vargs, GetEnv)
end

if #color == 3 then
color = Color3.fromRGB(color[1], color[2], color[3])
return Color3.fromRGB(color[1], color[2], color[3])
else
local brickColor = BrickColor.new(str)
local brickColor = BrickColor.new(str::any);
if str == tostring(brickColor) then
color = brickColor.Color
return brickColor.Color
else
return
end
end

return color
end;

ParseBrickColor = function(str: string, allowNil: boolean?)
Expand All @@ -1665,7 +1637,7 @@ return function(Vargs, GetEnv)
return BrickColor.random()
end

local brickColor = BrickColor.new(str)
local brickColor = BrickColor.new(str::any)
if str == tostring(brickColor) then
return brickColor
else
Expand Down
1 change: 0 additions & 1 deletion MainModule/Server/Core/Logs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ return function(Vargs, GetEnv)

GetAuditLogs = function(playerId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you forgot to remove this.

local auditLogs = {}
local logs = Logs.AuditLogs:GetAsTable() or {}
for _, log in pairs(Logs.AuditLogs:GetAsTable()) do
if log.ModeratorId == playerId then
table.insert(auditLogs, log)
Expand Down
Loading