- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAdminModule.lua
More file actions
Latest commit
228 lines (191 loc) · 6.99 KB
/
Copy pathAdminModule.lua
File metadata and controls
228 lines (191 loc) · 6.99 KB
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
--[[
Written by Begi.
AdminModule: Roblox Admin Commands System Based On New BanAPI.
--]]
localAdminModule= {}
localConfig=require(script.Config)
-- Services
localplayers=game:GetService("Players")
localhttpService=game:GetService("HttpService")
-- Helper function to send a message to a Discord webhook
localfunctionsendDiscordMessage(embed)
localdata=httpService:JSONEncode({ embeds= { embed } })
localheaders= { ["Content-Type"] ="application/json" }
localsuccess, error=pcall(function()
localv1=httpService:PostAsync(Config.WebhookURL, data, Enum.HttpContentType.ApplicationJson)
end)
ifnotsuccessthen
warn("Failed to send message to Discord: " ..tostring(error))
end
end
-- Helper function to get a player's profile link
localfunctiongetProfileLink(id)
return"https://www.roblox.com/users/" ..tostring(id) .."/profile"
end
-- Helper function to parse duration strings
functionAdminModule.parseDuration(durationStr)
ifnotdurationStrthen
returnnil
end
localduration=tonumber(durationStr:match("(%d+)"))
localunit=durationStr:match("(%a+)")
ifnotdurationornotunitthen
returnnil
end
ifunit=="s" then
returnduration
elseifunit=="m" then
returnduration*60
elseifunit=="h" then
returnduration*60*60
elseifunit=="d" then
returnduration*60*60*24
else
returnnil
end
end
-- Function to ban a player
functionAdminModule.BanPlayer(id, durationStr, reason, adminPlayer)
localduration=AdminModule.parseDuration(durationStr)
localdisplayDuration="N/A"
ifnotdurationthen
duration=-1
displayDuration="Permanent"
else
displayDuration=durationStr
end
ifnotreasonorreason=="" then
reason=Config.ReasonPlaceholders.NoReason
end
localembed=Config.Embeds.Ban
embed.description="[Target's Roblox Profile]("..getProfileLink(id)..")"
embed.fields[1].value=tostring(id)
embed.fields[2].value=displayDuration
embed.fields[3].value=reason
embed.fields[4].value=adminPlayer.Name
embed.footer= { text=os.date("%X | %d.%m.%Y") }
localdisplayReason=reason..Config.ReasonPlaceholders.ReasonTemplate
localconfig= {
UserIds= { id },
Duration=duration,
DisplayReason="Reason: " ..displayReason,
PrivateReason=os.date("%X | %d.%m.%Y"),
ApplyToUniverse=Config.BanApplyToUniverse,
ExcludeAltAccounts=Config.BanExcludeAltAccounts
}
localsuccess, error=pcall(function()
players:BanAsync(config)
end)
ifsuccessthen
sendDiscordMessage(embed)
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.Ban.Success)
else
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.Ban.Failure:gsub("{Error}", tostring(error)))
end
end
-- Function to unban a player
functionAdminModule.UnbanPlayer(id: IntValue, adminPlayer: Player)
localsuccess, error=pcall(function()
localconfig= {
UserIds= { id },
ApplyToUniverse=Config.UnbanExcludeAltAccounts
}
players:UnbanAsync(config)
end)
ifsuccessthen
localembed=Config.Embeds.Unban
embed.description="[Target's Roblox Profile]("..getProfileLink(id)..")"
embed.fields[1].value=tostring(id)
embed.fields[2].value=adminPlayer.Name
embed.footer= { text=os.date("%X | %d.%m.%Y") }
sendDiscordMessage(embed)
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.Unban.Success)
else
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.Unban.Failure:gsub("{Error}", tostring(error)))
end
end
-- Function to check player history (does not work in the studio)
functionAdminModule.CheckPlayerHistory(id, adminPlayer)
localsuccess, banHistory=pcall(function()
returnplayers:GetBanHistoryAsync(id)
end)
ifsuccessthen
localresults= {}
localpage=banHistory:GetCurrentPage()
for_, tableEntryinipairs(page) do
iftableEntry.Banthen
localresult= {
DisplayReason=tableEntry.DisplayReason,
PrivateReason=tableEntry.PrivateReason,
Duration=tableEntry.Duration
}
table.insert(results, result)
end
end
ifConfig.SendTxtthen
locallogContent=""
forindex, resultinipairs(results) do
logContent=logContent.."##############################################\n"
logContent=logContent.."Ban Case " ..index.."\n"
logContent=logContent..result.DisplayReason.."\n"
logContent=logContent.."Date: " ..result.PrivateReason.."\n"
logContent=logContent.."Duration: " ..tostring(result.Duration) .." seconds\n\n"
logContent=logContent.."##############################################\n\n"
end
localboundary="------------------------" ..string.gsub(httpService:GenerateGUID(false), "-", "")
localbody=""
body=body.."--" ..boundary.."\r\n"
body=body..'Content-Disposition: form-data; name="file"; filename="logs.txt"\r\n'
body=body.."Content-Type: text/plain\r\n\r\n"
body=body..logContent.."\r\n"
body=body.."--" ..boundary.."--"
localheaders= {
["Content-Type"] ="multipart/form-data; boundary=" ..boundary
}
localrequest= {
Url=Config.WebhookURL,
Method="POST",
Headers=headers,
Body=body
}
localembed=Config.Embeds.CheckHistory
embed.description="[Target's Roblox Profile]("..getProfileLink(id)..")"
embed.fields[1].value=adminPlayer.Name
embed.footer= { text=os.date("%X | %d.%m.%Y") }
sendDiscordMessage(embed)
localresponse=httpService:RequestAsync(request)
ifresponse.Successthen
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.CheckHistory.Success)
else
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.CheckHistory.Failure:gsub("{Error}", tostring(response.StatusMessage)))
end
else
localembed=Config.Embeds.CheckHistory
embed.description="[Target's Roblox Profile]("..getProfileLink(id)..")"
embed.fields[1].value=adminPlayer.Name
embed.footer= { text=os.date("%X | %d.%m.%Y") }
sendDiscordMessage(embed)
end
else
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.CheckHistory.Failure:gsub("{Error}", tostring(banHistory)))
end
end
-- Function to get player ID from username
functionAdminModule.GetPlayerID(username, adminPlayer)
localsuccess, playerId=pcall(function()
returnplayers:GetUserIdFromNameAsync(username)
end)
ifsuccessthen
localembed=Config.Embeds.GetID
embed.description="[Target's Roblox Profile]("..getProfileLink(playerId)..")"
embed.fields[1].value=username
embed.fields[2].value=tostring(playerId)
embed.fields[3].value=adminPlayer.Name
embed.footer= { text=os.date("%X | %d.%m.%Y") }
sendDiscordMessage(embed)
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.GetID.Success:gsub("{UserID}", tostring(playerId)))
else
Config.Remotes.CommandFeedbackEvent:FireClient(adminPlayer, Config.Messages.GetID.Failure:gsub("{Error}", tostring(error)))
end
end
returnAdminModule