mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-17 05:56:01 +01:00
Update discord.lua
Removed parts that aren't used and commented out that print that fills the server console. (keeping them commented incase anyone needs to test something)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
-- original discord roles author: https://forum.cfx.re/t/discord-roles-for-permissions-im-creative-i-know/233805?u=andyyy7666
|
||||
-- This is a edited version of discord-roles, original discord-roles resource: https://forum.cfx.re/t/discord-roles-for-permissions-im-creative-i-know/233805?u=andyyy7666
|
||||
local FormattedToken = "Bot "..config.DiscordToken
|
||||
|
||||
function DiscordRequest(method, endpoint, jsondata)
|
||||
@@ -14,42 +14,12 @@ function DiscordRequest(method, endpoint, jsondata)
|
||||
return data
|
||||
end
|
||||
|
||||
--[[ we don't use this in this resource.
|
||||
function GetRoles(user)
|
||||
local discordId = nil
|
||||
for _, id in ipairs(GetPlayerIdentifiers(user)) do
|
||||
if string.match(id, "discord:") then
|
||||
discordId = string.gsub(id, "discord:", "")
|
||||
print("Found discord id: "..discordId)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if discordId then
|
||||
local endpoint = ("guilds/%s/members/%s"):format(config.GuildId, discordId)
|
||||
local member = DiscordRequest("GET", endpoint, {})
|
||||
if member.code == 200 then
|
||||
local data = json.decode(member.data)
|
||||
local roles = data.roles
|
||||
local found = true
|
||||
return roles
|
||||
else
|
||||
print("Error occurred, maybe they are not in discord?")
|
||||
return false
|
||||
end
|
||||
else
|
||||
print("missing identifier")
|
||||
return false
|
||||
end
|
||||
end
|
||||
]]
|
||||
|
||||
function IsRolePresent(user, role)
|
||||
local discordId = nil
|
||||
for _, id in ipairs(GetPlayerIdentifiers(user)) do
|
||||
if string.match(id, "discord:") then
|
||||
discordId = string.gsub(id, "discord:", "")
|
||||
print("Found discord id: "..discordId)
|
||||
--print("Found discord id: "..discordId)
|
||||
break
|
||||
end
|
||||
end
|
||||
@@ -62,7 +32,7 @@ function IsRolePresent(user, role)
|
||||
end
|
||||
|
||||
if theRole == "0" then
|
||||
print("Role Given (0 in config)")
|
||||
--print("Role Given (0 in config)")
|
||||
return true
|
||||
elseif discordId then
|
||||
local endpoint = ("guilds/%s/members/%s"):format(config.GuildId, discordId)
|
||||
@@ -73,18 +43,18 @@ function IsRolePresent(user, role)
|
||||
local found = true
|
||||
for i=1, #roles do
|
||||
if roles[i] == theRole then
|
||||
print("Found role")
|
||||
--print("Found role")
|
||||
return true
|
||||
end
|
||||
end
|
||||
print("Not found!")
|
||||
--print("Not found!")
|
||||
return false
|
||||
else
|
||||
print("Error occurred, maybe they are not in discord?")
|
||||
--print("Error occurred, maybe they are not in discord?")
|
||||
return false
|
||||
end
|
||||
else
|
||||
print("missing identifier")
|
||||
--print("missing identifier")
|
||||
return false
|
||||
end
|
||||
end
|
||||
@@ -97,4 +67,4 @@ Citizen.CreateThread(function()
|
||||
else
|
||||
print("An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code))
|
||||
end
|
||||
end)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user