-
Notifications
You must be signed in to change notification settings - Fork 1
/
AdminModuleCommandHandler.lua
113 lines (96 loc) · 3.49 KB
/
AdminModuleCommandHandler.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
--[[
Written by Begi.
Listens for commands, checks permissions, and executes the appropriate functions from AdminModule.
--]]
local AdminModule = require(game:GetService("ReplicatedStorage"):WaitForChild("AdminModule"))
local Config = require(game:GetService("ReplicatedStorage"):WaitForChild("AdminModule"):WaitForChild("Config"))
-- Services
local Players = game:GetService("Players")
-- Function to check if a player is an admin
local function isAdmin(player)
return table.find(Config.AdminUserIds, player.UserId) ~= nil
end
-- Function to process commands
local function processCommand(player, message)
-- Split the message into command and arguments
local args = message:split(" ")
local command = table.remove(args, 1):lower()
if command == Config.CommandPrefix .. "ban" then
if isAdmin(player) then
local targetID = tonumber(args[1])
local duration = args[2]
local durationParsed = AdminModule.parseDuration(duration)
local reason
if durationParsed then
reason = table.concat(args, " ", 3)
else
duration = "-1"
reason = table.concat(args, " ", 2)
end
if targetID then
AdminModule.BanPlayer(targetID, duration, reason, player)
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "Player not found.")
end
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "You do not have permission to use this command.")
end
elseif command == Config.CommandPrefix .. "unban" then
if isAdmin(player) then
local targetID = tonumber(args[1])
if targetID then
AdminModule.UnbanPlayer(targetID, player)
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "Player not found.")
end
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "You do not have permission to use this command.")
end
elseif command == Config.CommandPrefix .. "checkhistory" then
if isAdmin(player) then
local targetID = tonumber(args[1])
if targetID then
AdminModule.CheckPlayerHistory(targetID, player)
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "Player not found.")
end
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "You do not have permission to use this command.")
end
elseif command == Config.CommandPrefix .. "getid" then
if isAdmin(player) then
local targetUsername = args[1]
AdminModule.GetPlayerID(targetUsername, player)
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "You do not have permission to use this command.")
end
else
Config.Remotes.CommandFeedbackEvent:FireClient(player, "Unknown command.")
end
end
-- Listen for player chats
Players.PlayerAdded:Connect(function(player)
if isAdmin(player) then
Config.Remotes.CommandFeedbackEvent:FireClient(player, "AdminModule is activated for you. Toggle menu: "..tostring(Config.ToggleKey))
end
player.Chatted:Connect(function(message)
if message:sub(1, #Config.CommandPrefix) == Config.CommandPrefix then
processCommand(player, message)
end
end)
end)
Config.Remotes.CommandsFromUI.OnServerEvent:Connect(function(player, command, parameter)
if command == "GetID" then
local username = parameter
AdminModule.GetPlayerID(username, player)
elseif command == "Unban" then
local id = parameter
AdminModule.UnbanPlayer(id, player)
elseif command == "CheckHistory" then
local id = parameter
AdminModule.CheckPlayerHistory(id, player)
end
end)
Config.Remotes.BanFromUI.OnServerEvent:Connect(function(player, id, duration, reason)
AdminModule.BanPlayer(id, duration, reason, player)
end)