-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
60 lines (48 loc) · 1.64 KB
/
Copy pathserver.lua
File metadata and controls
60 lines (48 loc) · 1.64 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
local discordServerId = "ID_SERVER"
local discordRoleId = "ID_ROLE"
local discordAppId = "BOT_TOKEN"
local kickMessage = "Vous n'avez pas le rôle Discord requis pour rejoindre ce serveur."
function CheckDiscordRole(source)
local discordId = nil
for _, v in ipairs(GetPlayerIdentifiers(source)) do
if string.sub(v, 1, string.len("discord:")) == "discord:" then
discordId = string.sub(v, 9)
break
end
end
if discordId == nil then
return false
end
local endpoint = ("https://discordapp.com/api/guilds/%s/members/%s"):format(discordServerId, discordId)
local headers = {
["Authorization"] = "Bot " .. discordAppId,
["Content-Type"] = "application/json"
}
local roleFound = false
PerformHttpRequest(endpoint, function(statusCode, responseText, headers)
if statusCode == 200 then
local response = json.decode(responseText)
for _, role in ipairs(response.roles) do
if role == discordRoleId then
roleFound = true
break
end
end
end
end, "GET", "", headers)
Citizen.Wait(1000)
return roleFound
end
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
local source = source
deferrals.defer()
deferrals.update("Vérification de votre rôle Discord...")
Citizen.CreateThread(function()
Citizen.Wait(500)
if CheckDiscordRole(source) then
deferrals.done()
else
deferrals.done(kickMessage)
end
end)
end)