Skip to content

Commit a5f512c

Browse files
authored
Merge pull request #4 from RickyBhatti/feat/discord-requirement
feat/discord-requirement
2 parents 5e9a5c4 + 754239a commit a5f512c

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

sv_config.lua

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ Config = {
22
DiscordToken = "", -- Bot token (The bot must be in your Discord server.)
33
GuildID = "", -- Server ID (The server that the roles are based off of.)
44

5+
DiscordRequired = false, -- If this is set to true, the resource will kick players who do not have a Discord identifier.
6+
GuildRequired = false, -- If this is set to true, the resource will kick players who are not in the Discord server. (Requires DiscordRequired to be true.)
7+
58
ChatRolesEnabled = true, -- If you'd like chat tags, staff chat, enabled or not.
69
RoleList = { -- Role ID of 0, will grant the role to everyone. (Ensure that you have a default role)
710
{0, "👦🏻 ^4Civilian | "}, -- All.

sv_deferrals.lua

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
if not Config.DiscordRequired then return end
2+
3+
local GuildRequired = Config.GuildRequired
4+
5+
AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
6+
local identifiers = GetIdentifiersTable(source)
7+
local discord = identifiers.discord
8+
9+
if not discord then
10+
deferrals.done("You must have Discord open to join this server.")
11+
return
12+
end
13+
14+
if GuildRequired and not isInGuild(source) then
15+
deferrals.done("You must be in the Discord server to join this server.")
16+
return
17+
end
18+
19+
deferrals.done()
20+
end)

sv_discord_api.lua

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ local function DiscordRequest(endpoint, method, jsondata)
3333
return data
3434
end
3535

36+
function isInGuild(user)
37+
local identifiers = GetIdentifiersTable(user)
38+
if not identifiers.discord then return false end
39+
40+
local endpoint = ("guilds/%s/members/%s"):format(GuildID, identifiers.discord)
41+
local result = DiscordRequest(endpoint, "GET", {})
42+
43+
return result.code == 200
44+
end
45+
3646
function getRoles(user)
3747
local identifiers = GetIdentifiersTable(user)
3848
if not identifiers.discord then return {} end

0 commit comments

Comments
 (0)