mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-19 06:46:03 +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
|
local FormattedToken = "Bot "..config.DiscordToken
|
||||||
|
|
||||||
function DiscordRequest(method, endpoint, jsondata)
|
function DiscordRequest(method, endpoint, jsondata)
|
||||||
@@ -14,42 +14,12 @@ function DiscordRequest(method, endpoint, jsondata)
|
|||||||
return data
|
return data
|
||||||
end
|
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)
|
function IsRolePresent(user, role)
|
||||||
local discordId = nil
|
local discordId = nil
|
||||||
for _, id in ipairs(GetPlayerIdentifiers(user)) do
|
for _, id in ipairs(GetPlayerIdentifiers(user)) do
|
||||||
if string.match(id, "discord:") then
|
if string.match(id, "discord:") then
|
||||||
discordId = string.gsub(id, "discord:", "")
|
discordId = string.gsub(id, "discord:", "")
|
||||||
print("Found discord id: "..discordId)
|
--print("Found discord id: "..discordId)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -62,7 +32,7 @@ function IsRolePresent(user, role)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if theRole == "0" then
|
if theRole == "0" then
|
||||||
print("Role Given (0 in config)")
|
--print("Role Given (0 in config)")
|
||||||
return true
|
return true
|
||||||
elseif discordId then
|
elseif discordId then
|
||||||
local endpoint = ("guilds/%s/members/%s"):format(config.GuildId, discordId)
|
local endpoint = ("guilds/%s/members/%s"):format(config.GuildId, discordId)
|
||||||
@@ -73,18 +43,18 @@ function IsRolePresent(user, role)
|
|||||||
local found = true
|
local found = true
|
||||||
for i=1, #roles do
|
for i=1, #roles do
|
||||||
if roles[i] == theRole then
|
if roles[i] == theRole then
|
||||||
print("Found role")
|
--print("Found role")
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
print("Not found!")
|
--print("Not found!")
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
print("Error occurred, maybe they are not in discord?")
|
--print("Error occurred, maybe they are not in discord?")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
print("missing identifier")
|
--print("missing identifier")
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user