-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpromoteHandler.lua
109 lines (92 loc) · 3.96 KB
/
promoteHandler.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
-- Dependencies
local messagemodule = require(game:GetService("ReplicatedStorage").MessageModule) -- The message module holds the SendMessage function, which is used to show notifications to the player, this takes in 3 arguments, the player, the message, and the type of message. you can replace this with your own or don't use it at all
local HttpService = game:GetService("HttpService")
local Players = game:GetService("Players")
-- Constants
local GroupId = 123456 -- Replace this with your group id
local CommandPrefix = "!promote" -- You can change this if you want
local ServerURL = "https://example.com/promote" -- Replace this with your server URL
local AuthorizationKey = script:GetAttribute("key") -- Make sure you have a key attribute in the script set to the api key
-- Utility Functions
local function canPromote(player)
return player:GetRankInGroup(GroupId) >= 160 -- Change this to the minimum rank required to promote
end
local function sendMessage(player, message, messageType)
messagemodule.SendMessage(player, message, messageType)
end
local function findTargetPlayer(name)
return Players:FindFirstChild(name)
end
local function sendPromotionRequest(requestData)
local success, response = pcall(function()
return HttpService:RequestAsync({
Url = ServerURL,
Method = "POST",
Headers = {
["Content-Type"] = "application/json",
["Authorization"] = AuthorizationKey
},
Body = HttpService:JSONEncode(requestData)
})
end)
return success, response
end
local function handlePromotionResponse(player, response)
if response.Success then
local successDecode, responseTable = pcall(function()
return HttpService:JSONDecode(response.Body)
end)
if successDecode then
sendMessage(player, responseTable.message, responseTable.success and "success" or "error")
else
sendMessage(player, "Failed to parse server response", "error")
print("Failed to parse server response:", response.Body)
end
else
local responseTable = HttpService:JSONDecode(response.Body)
sendMessage(player, responseTable.message, "error")
print("Request failed:", response.StatusCode, response.StatusMessage)
end
end
local function handleCommand(player, args)
if #args < 2 then
return sendMessage(player, "Specify the person to promote", "error")
end
if not canPromote(player) then
return sendMessage(player, "Only high ranks can use this", "error")
end
local targetPlayer = findTargetPlayer(args[2])
if not targetPlayer then
return sendMessage(player, "That person is not in the game", "error")
end
local targetRank = targetPlayer:GetRankInGroup(GroupId)
local runnerRank = player:GetRankInGroup(GroupId)
if targetRank == 0 then
return sendMessage(player, "User is not in the group", "error")
end
if targetRank >= runnerRank then
return sendMessage(player, "You cannot promote someone with an equal or higher rank than you", "error")
end
if targetRank >= 254 then -- Change this to the maximum rank that can be promoted (your bot accounts rank -1)
return sendMessage(player, "User's rank is too high", "error")
end
local requestData = {
username = args[2],
runner = player.Name,
}
local success, response = sendPromotionRequest(requestData)
if success then
handlePromotionResponse(player, response)
else
sendMessage(player, "Failed to send request, try again later", "error")
print("Failed to send request:", response)
end
end
-- Event Listeners
Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if string.sub(string.lower(message), 1, #CommandPrefix) == CommandPrefix then
handleCommand(player, string.split(string.sub(message, #CommandPrefix + 1), " "))
end
end)
end)