├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── client.lua ├── config.lua ├── example.lua ├── fxmanifest.lua ├── server.lua ├── version.txt └── versionChecker.lua /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: JaredScar 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Jared Scarito 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Badger_Discord_API 2 | 3 | ## Visitor Count 4 | 5 | 6 | ## Documentation 7 | [Installation Guide](https://docs.badger.store/fivem-discord-scripts/badger_discord_api/installation-script) 8 | 9 | [API Development/ Implementation Docs](https://docs.badger.store/fivem-discord-scripts/badger_discord_api) 10 | 11 | ## Jared's Developer Community [Discord] 12 | [![Developer Discord](https://discordapp.com/api/guilds/597445834153525298/widget.png?style=banner4)](https://discord.com/invite/WjB5VFz) 13 | 14 | ## Sponsors 15 | ### Want your message here? 16 | | Sponsor | Sponsor Message | 17 | | --- | --- | 18 | | | Sponsored by North American Roleplaying Community - NARC

Visit us @ https://discord.gg/NARC

| 19 | | |

Enemy of the State Roleplay

20 | 21 | ## Notes 22 | Some methods of the API not may fully work or be broken. I was able to test most and 75% of it works. If something does not work, please just submit an issue or pull request for it on the GitHub page. I will be making a more reinforced documentation for this whole API sometime in the future, but for now please just make use of the example.lua file for understanding it all. Thanks! 23 | 24 | ## What is it? 25 | This is essentially a Discord API for FiveM. It utilizes the REST API of Discord for all your essential needs :) Things that are heavy in Discord rate limiting (such as retreiving all server roles and player avatars) will be automatically stored to a cache for developers automatically. I will be moving all my scripts over to use this API for better ease of use. Some features include not having to gather role IDs at all, since the script gets the server's roles automatically, so you can just specify the role's name instead of role IDs at all (however, be aware that this will break then if someone changes the roles' names on Discord)... I hope you can all find some use for this, I know I will :P 26 | 27 | ## Scripts that utilize the API 28 | https://forum.cfx.re/t/release-badgertools-major-revamp/665756/ 29 | https://forum.cfx.re/t/discordaceperms-release/573044 30 | https://forum.cfx.re/t/release-bad-discordqueue-a-discord-role-based-queue-system-by-badger/1394685 31 | https://forum.cfx.re/t/discordtagids-i-know-i-know-i-only-make-discord-based-scripts/582513 32 | https://forum.cfx.re/t/discordchatroles-release/566338 33 | 34 | ## Example Usage: 35 | 36 | ``` 37 | -- IMPORTANT: 38 | -- For use in other resources, you will need to use: 39 | -- exports.Badger_Discord_API: 40 | -- 41 | -- For example: 42 | -- exports.Badger_Discord_API:GetRoleIdFromRoleName("roleName") 43 | 44 | RegisterCommand('testResource', function(source, args, rawCommand) 45 | local user = source; -- The user 46 | 47 | 48 | 49 | -- function GetRoleIdFromRoleName(name) 50 | -- Returns nil if not found 51 | -- Returns Discord Role ID if found 52 | -- Usage: 53 | local roleName = "Founder"; -- Change this to an existing role name on your Discord server 54 | 55 | local roleID = GetRoleIdFromRoleName(roleName); 56 | print("[Badger_Perms Example] The roleID for (" .. roleName .. ") is: " .. tostring(roleID)); 57 | 58 | -- function IsDiscordEmailVerified(user) 59 | -- Returns false if not found 60 | -- Returns true if verified 61 | -- Usage: 62 | local isVerified = IsDiscordEmailVerified(user); 63 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord email verified?: " .. tostring(isVerified)); 64 | 65 | -- function GetDiscordEmail(user) 66 | -- Returns nil if not found 67 | -- Returns Email if found 68 | -- Usage: 69 | local emailAddr = GetDiscordEmail(user); 70 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord email address: " .. tostring(emailAddr)); 71 | 72 | -- function GetDiscordName(user) 73 | -- Returns nil if not found 74 | -- Returns Discord name if found 75 | -- Usage: 76 | local name = GetDiscordName(user); 77 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord name: " .. tostring(name)); 78 | 79 | -- function GetGuildIcon() 80 | -- Returns nil if not found 81 | -- Returns URL if found 82 | -- Usage: 83 | local icon_URL = GetGuildIcon(); 84 | print("[Badger_Perms Example] Guild icon URL is: " .. tostring(icon_URL)); 85 | 86 | -- function GetGuildSplash() 87 | -- Returns nil if not found 88 | -- Returns URL if found 89 | -- Usage: 90 | local splash_URL = GetGuildSplash(); 91 | print("[Badger_Perms Example] Guild splash URL is: " .. tostring(splash_URL)); 92 | 93 | -- function GetGuildName() 94 | -- Returns nil if not found 95 | -- Returns name if found 96 | -- Usage: 97 | local guildName = GetGuildName(); 98 | print("[Badger_Perms Example] Guild name is: " .. tostring(guildName)); 99 | 100 | -- function GetGuildDescription() 101 | -- Returns nil if not found 102 | -- Returns description if found 103 | -- Usage: 104 | local guildDesc = GetGuildDescription(); 105 | print("[Badger_Perms Example] Guild description is: " .. tostring(guildDesc)); 106 | 107 | -- function GetGuildMemberCount() 108 | -- Returns nil if not found 109 | -- Returns member count if found 110 | -- Usage: 111 | local guildMemCount = GetGuildMemberCount(); 112 | print("[Badger_Perms Example] Guild member count is: " .. tostring(guildMemCount)); 113 | 114 | -- function GetGuildOnlineMemberCount() 115 | -- Returns nil if not found 116 | -- Returns description if found 117 | -- Usage: 118 | local onlineMemCount = GetGuildOnlineMemberCount(); 119 | print("[Badger_Perms Example] Guild online member count is: " .. tostring(onlineMemCount)); 120 | 121 | -- function GetDiscordAvatar(user) 122 | -- Returns nil if not found 123 | -- Returns URL if found 124 | -- Usage: 125 | local avatar = GetDiscordAvatar(user); 126 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord avatar: " .. tostring(avatar)); 127 | 128 | -- function GetDiscordNickname(user) 129 | -- Returns nil if not found 130 | -- Returns nickname if found 131 | -- Usage: 132 | local nickname = GetDiscordNickname(user); 133 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord nickname: " .. tostring(nickname)); 134 | 135 | -- function GetGuildRoleList() 136 | -- Returns nil if not found 137 | -- Returns associative array if found 138 | -- Usage: 139 | local roles = GetGuildRoleList(); 140 | for roleName, roleID in pairs(roles) do 141 | print(roleName .. " === " .. roleID); 142 | end 143 | 144 | -- function GetDiscordRoles(user) 145 | -- Returns nil if not found 146 | -- Returns array if found 147 | -- Usage: 148 | local roles = GetDiscordRoles(user) 149 | for i = 1, #roles do 150 | print(roles[i]); 151 | end 152 | 153 | -- function CheckEqual(role1, role2) 154 | -- Returns false if not equal 155 | -- Returns true if equal 156 | -- Usage: 157 | local isRolesEqual = CheckEqual("Founder", 597446100206616596); 158 | local isRolesEqual2 = CheckEqual("FounderRef", "Founder"); -- Refer to config.lua file, this is basically checking if FounderRef in the config is 159 | -- equal to the Founder role's ID 160 | 161 | -- function SetNickname(user, nickname) 162 | -- Returns error code 403 if the user is higher than the bot 163 | -- Usage: 164 | SetNickname(user, "🦡Badger", "Set nickname") 165 | SetNickname(user, "", "Reset nickname") 166 | 167 | -- function AddRole(user, roleId, reason) 168 | -- Returns error code 403 if the user is higher than the bot 169 | -- Usage: 170 | AddRole(user, "1038448129709723670", "Add role") 171 | 172 | -- function SetRoles(user, roleList, reason) 173 | -- Returns error code 403 if the user is higher than the bot 174 | -- Usage: 175 | SetRoles(user, { "1038448129709723670" }, "Set roles") 176 | 177 | -- function RemoveRole(user, roleId, reason) 178 | -- Returns error code 403 if the user is higher than the bot 179 | -- Usage: 180 | RemoveRole(user, "1038448129709723670", "Remove role") 181 | 182 | -- function ChangeDiscordVoice(user, voiceID) 183 | -- Returns error code 400 if voice channel ID is incorrect 184 | -- Usage: 185 | ChangeDiscordVoice(user, 123456789123456789) 186 | ChangeDiscordVoice(user, 123456789123456789, "Moved "..GetPlayerName(user).." to the admin channel") 187 | end) 188 | ``` 189 | 190 | ## Download 191 | 192 | https://github.com/JaredScar/Badger_Discord_API 193 | -------------------------------------------------------------------------------- /client.lua: -------------------------------------------------------------------------------- 1 | triggered = false; 2 | AddEventHandler("playerSpawned", function() 3 | if not triggered then 4 | triggered = true; 5 | Citizen.Wait((1000 * 20)); -- Wait 20 seconds 6 | TriggerServerEvent('Badger_Discord_API:PlayerLoaded'); 7 | end 8 | end) -------------------------------------------------------------------------------- /config.lua: -------------------------------------------------------------------------------- 1 | Config = { 2 | Guild_ID = '', -- Set to the ID of your guild (or your Primary guild if using Multiguild) 3 | Multiguild = false, -- Set to true if you want to use multiple guilds 4 | Guilds = { 5 | ["name"] = "guild_id", -- Replace this with a name, like "main" 6 | }, 7 | Bot_Token = '', 8 | RoleList = {}, 9 | DebugScript = false, 10 | CacheDiscordRoles = true, -- true to cache player roles, false to make a new Discord Request every time 11 | CacheDiscordRolesTime = 60, -- if CacheDiscordRoles is true, how long to cache roles before clearing (in seconds) 12 | } 13 | 14 | Config.Splash = { 15 | Header_IMG = 'https://forum.cfx.re/uploads/default/original/3X/a/6/a6ad03c9fb60fa7888424e7c9389402846107c7e.png', 16 | Enabled = true, 17 | Wait = 10, -- How many seconds should splash page be shown for? (Max is 12) 18 | Heading1 = "Welcome to [ServerName]", 19 | Heading2 = "Make sure to join our Discord and check out our website!", 20 | Discord_Link = 'https://discord.gg', 21 | Website_Link = 'https://badger.store', 22 | } -------------------------------------------------------------------------------- /example.lua: -------------------------------------------------------------------------------- 1 | -- IMPORTANT: 2 | -- For use in other resources, you will need to use: 3 | -- exports.Badger_Discord_API: 4 | -- 5 | -- For example: 6 | -- exports.Badger_Discord_API:GetRoleIdFromRoleName("roleName") 7 | 8 | RegisterCommand('testResource', function(source, args, rawCommand) 9 | local user = source; -- The user 10 | 11 | 12 | 13 | -- function GetRoleIdFromRoleName(name) 14 | -- Returns nil if not found 15 | -- Returns Discord Role ID if found 16 | -- Usage: 17 | local roleName = "Founder"; -- Change this to an existing role name on your Discord server 18 | 19 | local roleID = GetRoleIdFromRoleName(roleName); 20 | print("[Badger_Perms Example] The roleID for (" .. roleName .. ") is: " .. tostring(roleID)); 21 | 22 | -- function IsDiscordEmailVerified(user) 23 | -- Returns false if not found 24 | -- Returns true if verified 25 | -- Usage: 26 | local isVerified = IsDiscordEmailVerified(user); 27 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord email verified?: " .. tostring(isVerified)); 28 | 29 | -- function GetDiscordEmail(user) 30 | -- Returns nil if not found 31 | -- Returns Email if found 32 | -- Usage: 33 | local emailAddr = GetDiscordEmail(user); 34 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord email address: " .. tostring(emailAddr)); 35 | 36 | -- function GetDiscordName(user) 37 | -- Returns nil if not found 38 | -- Returns Discord name if found 39 | -- Usage: 40 | local name = GetDiscordName(user); 41 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord name: " .. tostring(name)); 42 | 43 | -- function GetGuildIcon() 44 | -- Returns nil if not found 45 | -- Returns URL if found 46 | -- Usage: 47 | local icon_URL = GetGuildIcon(); 48 | print("[Badger_Perms Example] Guild icon URL is: " .. tostring(icon_URL)); 49 | 50 | -- function GetGuildSplash() 51 | -- Returns nil if not found 52 | -- Returns URL if found 53 | -- Usage: 54 | local splash_URL = GetGuildSplash(); 55 | print("[Badger_Perms Example] Guild splash URL is: " .. tostring(splash_URL)); 56 | 57 | -- function GetGuildName() 58 | -- Returns nil if not found 59 | -- Returns name if found 60 | -- Usage: 61 | local guildName = GetGuildName(); 62 | print("[Badger_Perms Example] Guild name is: " .. tostring(guildName)); 63 | 64 | -- function GetGuildDescription() 65 | -- Returns nil if not found 66 | -- Returns description if found 67 | -- Usage: 68 | local guildDesc = GetGuildDescription(); 69 | print("[Badger_Perms Example] Guild description is: " .. tostring(guildDesc)); 70 | 71 | -- function GetGuildMemberCount() 72 | -- Returns nil if not found 73 | -- Returns member count if found 74 | -- Usage: 75 | local guildMemCount = GetGuildMemberCount(); 76 | print("[Badger_Perms Example] Guild member count is: " .. tostring(guildMemCount)); 77 | 78 | -- function GetGuildOnlineMemberCount() 79 | -- Returns nil if not found 80 | -- Returns description if found 81 | -- Usage: 82 | local onlineMemCount = GetGuildOnlineMemberCount(); 83 | print("[Badger_Perms Example] Guild online member count is: " .. tostring(onlineMemCount)); 84 | 85 | -- function GetDiscordAvatar(user) 86 | -- Returns nil if not found 87 | -- Returns URL if found 88 | -- Usage: 89 | local avatar = GetDiscordAvatar(user); 90 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord avatar: " .. tostring(avatar)); 91 | 92 | -- function GetDiscordNickname(user) 93 | -- Returns nil if not found 94 | -- Returns nickname if found 95 | -- Usage: 96 | local nickname = GetDiscordNickname(user); 97 | print("[Badger_Perms Example] Player " .. GetPlayerName(user) .. " has Discord nickname: " .. tostring(nickname)); 98 | 99 | -- function GetGuildRoleList() 100 | -- Returns nil if not found 101 | -- Returns associative array if found 102 | -- Usage: 103 | local roles = GetGuildRoleList(); 104 | for roleName, roleID in pairs(roles) do 105 | print(roleName .. " === " .. roleID); 106 | end 107 | 108 | -- function GetDiscordRoles(user) 109 | -- Returns nil if not found 110 | -- Returns array if found 111 | -- Usage: 112 | local roles = GetDiscordRoles(user) 113 | for i = 1, #roles do 114 | print(roles[i]); 115 | end 116 | 117 | -- function CheckEqual(role1, role2) 118 | -- Returns false if not equal 119 | -- Returns true if equal 120 | -- Usage: 121 | local isRolesEqual = CheckEqual("Founder", 597446100206616596); 122 | local isRolesEqual2 = CheckEqual("FounderRef", "Founder"); -- Refer to config.lua file, this is basically checking if FounderRef in the config is 123 | -- equal to the Founder role's ID 124 | 125 | -- function SetNickname(user, nickname) 126 | -- Returns error code 403 if the user is higher than the bot 127 | -- Usage: 128 | SetNickname(user, "🦡Badger", "Set nickname") 129 | SetNickname(user, "", "Reset nickname") 130 | 131 | -- function AddRole(user, roleId, reason) 132 | -- Returns error code 403 if the user is higher than the bot 133 | -- Usage: 134 | AddRole(user, "1038448129709723670", "Add role") 135 | 136 | -- function SetRoles(user, roleList, reason) 137 | -- Returns error code 403 if the user is higher than the bot 138 | -- Usage: 139 | SetRoles(user, { "1038448129709723670" }, "Set roles") 140 | 141 | -- function RemoveRole(user, roleId, reason) 142 | -- Returns error code 403 if the user is higher than the bot 143 | -- Usage: 144 | RemoveRole(user, "1038448129709723670", "Remove role") 145 | 146 | -- function ChangeDiscordVoice(user, voiceID) 147 | -- Returns error code 400 if voice channel ID is incorrect 148 | -- Usage: 149 | ChangeDiscordVoice(user, 123456789123456789) 150 | ChangeDiscordVoice(user, 123456789123456789, "Moved "..GetPlayerName(user).." to the admin channel") 151 | end) 152 | -------------------------------------------------------------------------------- /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'cerulean' 2 | game 'gta5' 3 | 4 | author 'JaredScar' 5 | description 'Badger\'s Discord API' 6 | version '1.6' 7 | url 'https://github.com/JaredScar/Badger_Discord_API' 8 | 9 | client_scripts { 10 | 'client.lua', 11 | } 12 | 13 | server_scripts { 14 | "versionChecker.lua", 15 | 'config.lua', 16 | "server.lua", -- Uncomment this line 17 | --"example.lua" -- Remove this when you actually start using the script!!! 18 | } 19 | 20 | server_exports { 21 | "GetDiscordRoles", 22 | "GetRoleIdFromRoleName", 23 | "GetDiscordAvatar", 24 | "GetDiscordName", 25 | "GetDiscordEmail", 26 | "IsDiscordEmailVerified", 27 | "GetDiscordNickname", 28 | "GetGuildIcon", 29 | "GetGuildSplash", 30 | "GetGuildName", 31 | "GetGuildDescription", 32 | "GetGuildMemberCount", 33 | "GetGuildOnlineMemberCount", 34 | "GetGuildRoleList", 35 | "ResetCaches", 36 | "CheckEqual", 37 | "SetNickname", 38 | "SetRoles", 39 | "AddRole", 40 | "RemoveRole", 41 | "ChangeDiscordVoice", 42 | "ClearCache", 43 | "FetchRoleID" 44 | } 45 | -------------------------------------------------------------------------------- /server.lua: -------------------------------------------------------------------------------- 1 | local FormattedToken = "Bot " .. Config.Bot_Token 2 | 3 | local error_codes_defined = { 4 | [200] = 'OK - The request was completed successfully..!', 5 | [204] = 'OK - No Content', 6 | [400] = "Error - The request was improperly formatted, or the server couldn't understand it..!", 7 | [401] = 'Error - The Authorization header was missing or invalid..! Your Discord Token is probably wrong or does not have correct permissions attributed to it.', 8 | [403] = 'Error - The Authorization token you passed did not have permission to the resource..! Your Discord Token is probably wrong or does not have correct permissions attributed to it.', 9 | [404] = "Error - The resource at the location specified doesn't exist.", 10 | [429] = 'Error - Too many requests, you hit the Discord rate limit. https://discord.com/developers/docs/topics/rate-limits', 11 | [502] = 'Error - Discord API may be down?...' 12 | }; 13 | 14 | Citizen.CreateThread(function() 15 | if (GetCurrentResourceName() ~= "Badger_Discord_API") then 16 | --StopResource(GetCurrentResourceName()); 17 | print("[" .. GetCurrentResourceName() .. "] " .. "IMPORTANT: This resource must be named Badger_Discord_API for it to work properly with other scripts..."); 18 | end 19 | print("[Badger_Discord_API] For support, make sure to join Badger's official Discord server: discord.gg/WjB5VFz"); 20 | print('^7[^2Zap-Hosting^7] ^3Use code ^5TheWolfBadger-4765 ^3at checkout for ^220% ^3off of selected services. Visit ^5https://zap-hosting.com/badger ^3to get started!'); 21 | end) 22 | 23 | function sendDebugMessage(msg) 24 | print("^1[^5Badger_Discord_API^1] ^3" .. msg); 25 | end 26 | 27 | tracked = {} 28 | 29 | RegisterNetEvent('Badger_Discord_API:PlayerLoaded') 30 | AddEventHandler('Badger_Discord_API:PlayerLoaded', function() 31 | if (GetCurrentResourceName() ~= "Badger_Discord_API") then 32 | TriggerClientEvent('chatMessage', -1, '^1[^5SCRIPT ERROR^1] ^3The script ^1' .. GetCurrentResourceName() .. ' ^3will not work properly... You must ' 33 | .. 'rename the resource to ^1Badger_Discord_API'); 34 | end 35 | local license = GetIdentifier(source, 'license'); 36 | if (tracked[license] == nil) then 37 | tracked[license] = true; 38 | TriggerClientEvent('chatMessage', source, 39 | '^1[^5Badger_Discord_API^1] ^3The Discord API script was created by Badger. You may join his Discord at: ^6discord.gg/WjB5VFz') 40 | end 41 | TriggerClientEvent('chatMessage', source, 42 | '^7[^2Zap-Hosting^7] ^3Use code ^5TheWolfBadger-4765 ^3at checkout for ^220% ^3off of selected services. Visit ^5https://zap-hosting.com/badger ^3to get started!'); 43 | end) 44 | 45 | card = '{"type":"AdaptiveCard","$schema":"http://adaptivecards.io/schemas/adaptive-card.json","version":"1.4","body":[{"type":"Image","url":"' .. Config.Splash.Header_IMG .. '","horizontalAlignment":"Center"},{"type":"Container","items":[{"type":"TextBlock","text":"Badger_Discord_API","wrap":true,"fontType":"Default","size":"ExtraLarge","weight":"Bolder","color":"Light","horizontalAlignment":"Center"},{"type":"TextBlock","text":"' .. Config.Splash.Heading1 .. '","wrap":true,"size":"Large","weight":"Bolder","color":"Light","horizontalAlignment":"Center"},{"type":"TextBlock","text":"' .. Config.Splash.Heading2 .. '","wrap":true,"color":"Light","size":"Medium","horizontalAlignment":"Center"},{"type":"ColumnSet","height":"stretch","minHeight":"100px","bleed":true,"horizontalAlignment":"Center","columns":[{"type":"Column","width":"stretch","items":[{"type":"ActionSet","actions":[{"type":"Action.OpenUrl","title":"Discord","url":"' .. Config.Splash.Discord_Link .. '","style":"positive"}],"horizontalAlignment":"Right"}],"height":"stretch"},{"type":"Column","width":"stretch","items":[{"type":"ActionSet","actions":[{"type":"Action.OpenUrl","title":"Website","style":"positive","url":"' .. Config.Splash.Website_Link .. '"}],"horizontalAlignment":"Left"}]}]},{"type":"ActionSet","actions":[{"type":"Action.OpenUrl","title":"Click to join Badger\'s Discord","style":"destructive","iconUrl":"https://i.gyazo.com/0904b936e8e30d0104dec44924bd2294.gif","url":"https://discord.com/invite/WjB5VFz"}],"horizontalAlignment":"Center"}],"style":"default","bleed":true,"height":"stretch"},{"type":"Image","url":"https://i.gyazo.com/7e896862b14be754ae8bad90b664a350.png","selectAction":{"type":"Action.OpenUrl","url":"https://zap-hosting.com/badger"},"horizontalAlignment":"Center"}]}' 46 | if Config.Splash.Enabled then 47 | AddEventHandler('playerConnecting', function(name, setKickReason, deferrals) 48 | -- Player is connecting 49 | deferrals.defer(); 50 | local src = source; 51 | local toEnd = false; 52 | local count = 0; 53 | while not toEnd do 54 | deferrals.presentCard(card, 55 | function(data, rawData) 56 | end) 57 | Wait((1000)) 58 | count = count + 1; 59 | if count == Config.Splash.Wait then 60 | toEnd = true; 61 | end 62 | end 63 | deferrals.done(); 64 | end) 65 | end 66 | 67 | function GetIdentifier(source, id_type) 68 | if type(id_type) ~= "string" then return; end 69 | for _, identifier in pairs(GetPlayerIdentifiers(source)) do 70 | if string.find(identifier, id_type) then 71 | return identifier 72 | end 73 | end 74 | return nil 75 | end 76 | 77 | function GetGuildId (guildName) 78 | local result = tostring(Config.Guild_ID) 79 | if guildName and Config.Guilds[guildName] then 80 | result = tostring(Config.Guilds[guildName]) 81 | end 82 | return result 83 | end 84 | 85 | function DiscordRequest(method, endpoint, jsondata, reason) 86 | local data = nil 87 | PerformHttpRequest("https://discord.com/api/"..endpoint, function(errorCode, resultData, resultHeaders) 88 | data = {data=resultData, code=errorCode, headers=resultHeaders} 89 | end, method, #jsondata > 0 and jsondata or "", {["Content-Type"] = "application/json", ["Authorization"] = FormattedToken, ['X-Audit-Log-Reason'] = reason}) 90 | 91 | while data == nil do 92 | Citizen.Wait(0) 93 | end 94 | 95 | return data 96 | end 97 | 98 | function GetRoleIdFromRoleName(name, guild --[[optional]]) 99 | local guildId = GetGuildId(guild) 100 | if (Caches.RoleList[guildId] ~= nil) then 101 | return tonumber(Caches.RoleList[guildId][name]); 102 | else 103 | local roles = GetGuildRoleList(guild); 104 | return tonumber(roles[name]); 105 | end 106 | end 107 | 108 | function FetchRoleID(roleID2Check, guild --[[optional]]) 109 | -- You gave me an ID, here it is back to you. 110 | if type(roleID2Check) == "number" then return roleID2Check end 111 | -- You gave me a non-string, non-number. I can't help you. 112 | if type(roleID2Check) ~= "string" then return nil end 113 | 114 | if type(roleID2Check) == "string" then 115 | if (tonumber(roleID2Check) ~= nil) then 116 | return tonumber(roleID2Check); 117 | end 118 | end 119 | 120 | -- It's a string, therefore name -- search config rolelist 121 | local rolesListFromConfig = Config.RoleList 122 | if rolesListFromConfig[roleID2Check] then 123 | -- It's a named role in the config. Here you go! 124 | return tonumber(rolesListFromConfig[roleID2Check]) 125 | end 126 | -- Oops, didn't find in config rolelist, search by name in current guild 127 | if (guild ~= nil) then 128 | local fetchedRolesList = GetGuildRoleList(guild) 129 | if fetchedRolesList[roleID2Check] then 130 | -- We found it in the current guild. Here you go! 131 | return tonumber(fetchedRolesList[roleID2Check]) 132 | end 133 | end 134 | -- Okay, still no luck. Search Main guild for role by name (if main isn't current guild) 135 | if GetGuildId(guild) ~= tostring(Config.Guild_ID) then 136 | local mainRolesList = GetGuildRoleList() 137 | if mainRolesList[roleID2Check] then 138 | -- We found it in the current guild. Here you go! 139 | return tonumber(mainRolesList[roleID2Check]) 140 | end 141 | end 142 | -- Big oops, didn't find in current guild, or main guild. Search by name in all guilds! 143 | --[[ 144 | -- Due to a security flaw in the below code, it was redacted for good reason... 145 | if (Config.Multiguild and not roleFound) then 146 | for guildName, guildID in pairs(Config.Guilds) do 147 | local thisRolesList = GetGuildRoleList(guildName) 148 | if thisRolesList[roleID2Check] then 149 | -- We found it in the current guild. Here you go! 150 | return tonumber(thisRolesList[roleID2Check]) 151 | end 152 | end 153 | end 154 | ]]-- 155 | return nil -- Sorry, couldn't find anywhere 156 | end 157 | 158 | function CheckEqual(role1, role2, guild --[[optional]]) 159 | local roleID1 = FetchRoleID(role1, guild); 160 | local roleID2 = FetchRoleID(role2, guild); 161 | -- If they are the same exact name or ID & same type, they are equal 162 | if (type(roleID1) ~= "nil" and type(roleID2) ~= "nil") and roleID1 == roleID2 then 163 | return true 164 | end 165 | -- If they can be forced to number and they are the same ID, they are equal 166 | if ((tonumber(roleID1) ~= nil) and (tonumber(roleID1) == tonumber(roleID2))) then 167 | return true 168 | end 169 | 170 | return false 171 | end 172 | 173 | function IsDiscordEmailVerified(user) 174 | local discordId = nil 175 | local isVerified = false; 176 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 177 | if string.match(id, "discord:") then 178 | discordId = string.gsub(id, "discord:", "") 179 | break 180 | end 181 | end 182 | if discordId then 183 | local endpoint = ("users/%s"):format(discordId) 184 | local member = DiscordRequest("GET", endpoint, {}) 185 | if member.code == 200 then 186 | local data = json.decode(member.data) 187 | if data ~= nil then 188 | -- It is valid data 189 | isVerified = data.verified; 190 | end 191 | else 192 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. DETAILS: " .. error_codes_defined[member.code]); 193 | end 194 | end 195 | return isVerified; 196 | end 197 | 198 | function GetDiscordEmail(user) 199 | local discordId = nil 200 | local emailData = nil; 201 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 202 | if string.match(id, "discord:") then 203 | discordId = string.gsub(id, "discord:", "") 204 | break 205 | end 206 | end 207 | if discordId then 208 | local endpoint = ("users/%s"):format(discordId) 209 | local member = DiscordRequest("GET", endpoint, {}) 210 | if member.code == 200 then 211 | local data = json.decode(member.data) 212 | if data ~= nil then 213 | -- It is valid data 214 | emailData = data.email; 215 | end 216 | else 217 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. DETAILS: " .. error_codes_defined[member.code]) 218 | end 219 | end 220 | return emailData; 221 | end 222 | 223 | function GetDiscordName(user) 224 | local discordId = nil 225 | local nameData = nil; 226 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 227 | if string.match(id, "discord:") then 228 | discordId = string.gsub(id, "discord:", "") 229 | break 230 | end 231 | end 232 | if discordId then 233 | local endpoint = ("users/%s"):format(discordId) 234 | local member = DiscordRequest("GET", endpoint, {}) 235 | if member.code == 200 then 236 | local data = json.decode(member.data) 237 | if data ~= nil then 238 | -- It is valid data 239 | if data.discriminator == 0 or data.discriminator == "0" then 240 | return data.username 241 | end 242 | nameData = data.username .. "#" .. data.discriminator; 243 | end 244 | else 245 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. DETAILS: " .. error_codes_defined[member.code]) 246 | end 247 | end 248 | return nameData; 249 | end 250 | 251 | function GetGuildIcon(guild --[[optional]]) 252 | local guildId = GetGuildId(guild) 253 | local guild = DiscordRequest("GET", "guilds/"..guildId, {}) 254 | if guild.code == 200 then 255 | local data = json.decode(guild.data) 256 | if (data.icon:sub(1, 1) and data.icon:sub(2, 2) == "_") then 257 | -- It's a gif 258 | return 'https://cdn.discordapp.com/icons/' .. Config.Guild_ID .. "/" .. data.icon .. ".gif"; 259 | else 260 | -- Image 261 | return 'https://cdn.discordapp.com/icons/' .. Config.Guild_ID .. "/" .. data.icon .. ".png"; 262 | end 263 | else 264 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 265 | end 266 | return nil; 267 | end 268 | 269 | function GetGuildSplash(guild --[[optional]]) 270 | local guildId = GetGuildId(guild) 271 | local guild = DiscordRequest("GET", "guilds/"..guildId, {}) 272 | if guild.code == 200 then 273 | local data = json.decode(guild.data) 274 | -- Image 275 | return 'https://cdn.discordapp.com/splashes/' .. Config.Guild_ID .. "/" .. data.icon .. ".png"; 276 | else 277 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 278 | end 279 | return nil; 280 | end 281 | 282 | function GetGuildName(guild --[[optional]]) 283 | local guildId = GetGuildId(guild) 284 | local guild = DiscordRequest("GET", "guilds/"..guildId, {}) 285 | if guild.code == 200 then 286 | local data = json.decode(guild.data) 287 | -- Image 288 | return data.name; 289 | else 290 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 291 | end 292 | return nil; 293 | end 294 | 295 | function GetGuildDescription(guild --[[optional]]) 296 | local guildId = GetGuildId(guild) 297 | local guild = DiscordRequest("GET", "guilds/"..guildId, {}) 298 | if guild.code == 200 then 299 | local data = json.decode(guild.data) 300 | -- Image 301 | return data.description; 302 | else 303 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 304 | end 305 | return nil; 306 | end 307 | 308 | function GetGuildMemberCount(guild --[[optional]]) 309 | local guildId = GetGuildId(guild) 310 | local guild = DiscordRequest("GET", "guilds/"..guildId.."?with_counts=true", {}) 311 | if guild.code == 200 then 312 | local data = json.decode(guild.data) 313 | -- Image 314 | return data.approximate_member_count; 315 | else 316 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 317 | end 318 | return nil; 319 | end 320 | 321 | function GetGuildOnlineMemberCount(guild --[[optional]]) 322 | local guildId = GetGuildId(guild) 323 | local guild = DiscordRequest("GET", "guilds/"..guildId.."?with_counts=true", {}) 324 | if guild.code == 200 then 325 | local data = json.decode(guild.data) 326 | return data.approximate_presence_count; 327 | else 328 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 329 | end 330 | return nil; 331 | end 332 | 333 | function GetDiscordAvatar(user) 334 | local discordId = nil 335 | local imgURL = nil; 336 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 337 | if string.match(id, "discord:") then 338 | discordId = string.gsub(id, "discord:", "") 339 | break 340 | end 341 | end 342 | if discordId then 343 | if Caches.Avatars[discordId] == nil then 344 | local endpoint = ("users/%s"):format(discordId) 345 | local member = DiscordRequest("GET", endpoint, {}) 346 | if member.code == 200 then 347 | local data = json.decode(member.data) 348 | if data ~= nil and data.avatar ~= nil then 349 | -- It is valid data 350 | if (data.avatar:sub(1, 1) and data.avatar:sub(2, 2) == "_") then 351 | imgURL = "https://cdn.discordapp.com/avatars/" .. discordId .. "/" .. data.avatar .. ".gif"; 352 | else 353 | imgURL = "https://cdn.discordapp.com/avatars/" .. discordId .. "/" .. data.avatar .. ".png" 354 | end 355 | end 356 | else 357 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. DETAILS: " .. error_codes_defined[member.code]) 358 | end 359 | Caches.Avatars[discordId] = imgURL; 360 | else 361 | imgURL = Caches.Avatars[discordId]; 362 | end 363 | else 364 | sendDebugMessage("[Badger_Discord_API] ERROR: Discord ID was not found...") 365 | end 366 | return imgURL; 367 | end 368 | 369 | Caches = { 370 | Avatars = {}, 371 | RoleList = {} 372 | } 373 | function ResetCaches() 374 | Caches = { 375 | Avatars = {}, 376 | RoleList = {}, 377 | }; 378 | end 379 | 380 | function GetGuildRoleList(guild --[[optional]]) 381 | local guildId = GetGuildId(guild) 382 | if (Caches.RoleList[guildId] == nil) then 383 | local guild = DiscordRequest("GET", "guilds/"..guildId, {}) 384 | if guild.code == 200 then 385 | local data = json.decode(guild.data) 386 | -- Image 387 | local roles = data.roles; 388 | local roleList = {}; 389 | for i = 1, #roles do 390 | roleList[roles[i].name] = roles[i].id; 391 | end 392 | Caches.RoleList[guildId] = roleList; 393 | else 394 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data or guild.code)) 395 | Caches.RoleList[guildId] = nil; 396 | end 397 | end 398 | return Caches.RoleList[guildId]; 399 | end 400 | 401 | recent_role_cache = {} 402 | 403 | function ClearCache(discordId) 404 | if (discordId ~= nil) then 405 | recent_role_cache[discordId] = {}; 406 | end 407 | end 408 | 409 | function GetDiscordRoles(user, guild --[[optional]]) 410 | local discordId = nil 411 | local guildId = GetGuildId(guild) 412 | local roles = nil 413 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 414 | if string.match(id, "discord:") then 415 | discordId = string.gsub(id, "discord:", "") 416 | break; 417 | end 418 | end 419 | 420 | if discordId then 421 | -- Get roles for specified guild (or main guild if not specified) 422 | roles = GetUserRolesInGuild(discordId, guildId) 423 | -- If specified guild or disabled multiguild option, just return this one 424 | if guild or Config.Multiguild == false then 425 | return roles 426 | end 427 | 428 | -- MULTIGUILD SECTION 429 | -- Keep main guild roles so we can add the rest on top of this list 430 | 431 | -- For some reason, referencing roles again will use the global reference that is returned... 432 | -- because of that, we use this resetRoles list and repopulate. Probably a better way to do this. -- Needs to be looked into 433 | resetRoles = {} 434 | for _, role_id in pairs(roles) do 435 | table.insert(resetRoles, role_id); 436 | end 437 | roles = resetRoles 438 | local checkedGuilds = {} 439 | -- Loop through guilds in config and get the roles from each one. 440 | for _,id in pairs(Config.Guilds) do 441 | -- If it's the main guild, we already fetched these roles. NEXT! 442 | -- We don't really need this check, but maybe someone used their main guild in this config list.... 443 | if tostring(id) == guildId then goto skip end 444 | if checkedGuilds[id] then goto skip end 445 | -- Fetch roles for this guild 446 | local guildRoles = GetUserRolesInGuild(discordId, id) 447 | checkedGuilds[id] = true 448 | -- If it didnt return false due to error, add the roles to the list 449 | if type(guildRoles) == "table" then 450 | -- Insert each role into roles list 451 | for _,v in pairs(guildRoles) do 452 | table.insert(roles, v) 453 | end 454 | end 455 | ::skip:: 456 | end 457 | return roles 458 | else 459 | sendDebugMessage("[Badger_Discord_API] ERROR: Discord was not connected to user's Fivem account...") 460 | return false 461 | end 462 | return false 463 | end 464 | 465 | function GetUserRolesInGuild (user, guild) 466 | -- Error check before starting operation 467 | if not user then 468 | sendDebugMessage("[Badger_Discord_API] ERROR: GetUserRolesInGuild requires discord ID") 469 | return false 470 | end 471 | if not guild then 472 | sendDebugMessage("[Badger_Discord_API] ERROR: GetUserRolesInGuild requires guild ID") 473 | return false 474 | end 475 | 476 | -- Check for cached roles 477 | if Config.CacheDiscordRoles and recent_role_cache[user] and recent_role_cache[user][guild] then 478 | return recent_role_cache[user][guild] 479 | end 480 | 481 | -- Request roles for user id 482 | local endpoint = ("guilds/%s/members/%s"):format(guild, user) 483 | local member = DiscordRequest("GET", endpoint, {}) 484 | if member.code == 200 then 485 | local data = json.decode(member.data) 486 | local roles = data.roles 487 | if Config.CacheDiscordRoles then 488 | recent_role_cache[user] = recent_role_cache[user] or {} 489 | recent_role_cache[user][guild] = roles 490 | Citizen.SetTimeout(((Config.CacheDiscordRolesTime or 60)*1000), function() recent_role_cache[user][guild] = nil end) 491 | end 492 | return roles 493 | else 494 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached... Returning false. [Member Data NOT FOUND] DETAILS: " .. error_codes_defined[member.code]) 495 | return false 496 | end 497 | end 498 | 499 | function GetDiscordNickname(user, guild --[[optional]]) 500 | local discordId = nil 501 | local guildId = GetGuildId(guild) 502 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 503 | if string.match(id, "discord:") then 504 | discordId = string.gsub(id, "discord:", "") 505 | break 506 | end 507 | end 508 | 509 | if discordId then 510 | local endpoint = ("guilds/%s/members/%s"):format(guildId, discordId) 511 | local member = DiscordRequest("GET", endpoint, {}) 512 | if member.code == 200 then 513 | local data = json.decode(member.data) 514 | local nickname = data.nick 515 | return nickname; 516 | else 517 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. Error Code: " .. error_codes_defined[member.code]) 518 | return nil; 519 | end 520 | else 521 | sendDebugMessage("[Badger_Discord_API] ERROR: Discord was not connected to user's Fivem account...") 522 | return nil; 523 | end 524 | return nil; 525 | end 526 | 527 | function SetNickname(user, nickname, reason) 528 | local discordId = nil 529 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 530 | if string.match(id, 'discord:') then 531 | discordId = string.gsub(id, 'discord:', '') 532 | break 533 | end 534 | end 535 | 536 | if discordId then 537 | local name = nickname or "" 538 | local endpoint = ("guilds/%s/members/%s"):format(Config.Guild_ID, discordId) 539 | local member = DiscordRequest("PATCH", endpoint, json.encode({nick = tostring(name)}), reason) 540 | if member.code ~= 200 and member.code ~= 204 then 541 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. Error Code: " .. error_codes_defined[member.code]) 542 | end 543 | end 544 | end 545 | 546 | function AddRole(user, roleId, reason) 547 | local discordId = nil 548 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 549 | if string.match(id, 'discord:') then 550 | discordId = string.gsub(id, 'discord:', '') 551 | break 552 | end 553 | end 554 | 555 | if discordId then 556 | local roles = GetDiscordRoles(user) or {} 557 | local endpoint = ("guilds/%s/members/%s"):format(Config.Guild_ID, discordId) 558 | table.insert(roles, roleId) 559 | local member = DiscordRequest("PATCH", endpoint, json.encode({roles = roles}), reason) 560 | if member.code ~= 200 then 561 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. Error Code: " .. error_codes_defined[member.code]) 562 | end 563 | end 564 | end 565 | 566 | function RemoveRole(user, roleId, reason) 567 | local discordId = nil 568 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 569 | if string.match(id, 'discord:') then 570 | discordId = string.gsub(id, 'discord:', '') 571 | break 572 | end 573 | end 574 | 575 | if discordId then 576 | local roles = GetDiscordRoles(user) or {} 577 | local endpoint = ("guilds/%s/members/%s"):format(Config.Guild_ID, discordId) 578 | 579 | for k, v in pairs(roles) do 580 | if v == roleId then 581 | roles[k] = nil 582 | end 583 | end 584 | 585 | local member = DiscordRequest("PATCH", endpoint, json.encode({roles = roles}), reason) 586 | if member.code ~= 200 then 587 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. Error Code: " .. error_codes_defined[member.code]) 588 | end 589 | end 590 | end 591 | 592 | function SetRoles(user, roleList, reason) 593 | local discordId = nil 594 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 595 | if string.match(id, 'discord:') then 596 | discordId = string.gsub(id, 'discord:', '') 597 | break 598 | end 599 | end 600 | 601 | if discordId then 602 | local endpoint = ("guilds/%s/members/%s"):format(Config.Guild_ID, discordId) 603 | local member = DiscordRequest("PATCH", endpoint, json.encode({roles = roleList}), reason) 604 | if member.code ~= 200 then 605 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. Error Code: " .. error_codes_defined[member.code]) 606 | end 607 | end 608 | end 609 | 610 | function ChangeDiscordVoice(user, voice, reason) 611 | local discordId = nil 612 | for _, id in ipairs(GetPlayerIdentifiers(user)) do 613 | if string.match(id, "discord:") then 614 | discordId = string.gsub(id, "discord:", "") 615 | end 616 | end 617 | 618 | if discordId then 619 | local endpoint = ("guilds/%s/members/%s"):format(Config.Guild_ID, discordId) 620 | local member = DiscordRequest("PATCH", endpoint, json.encode({channel_id = voice}), reason) 621 | if member.code ~= 200 then 622 | sendDebugMessage("[Badger_Discord_API] ERROR: Code 200 was not reached. Error Code: " .. error_codes_defined[member.code]) 623 | end 624 | end 625 | end 626 | 627 | Citizen.CreateThread(function() 628 | local mguild = DiscordRequest("GET", "guilds/"..Config.Guild_ID, {}) 629 | if mguild.code == 200 then 630 | local data = json.decode(mguild.data) 631 | sendDebugMessage("[Badger_Discord_API] Successful connection to Guild : "..data.name.." ("..data.id..")") 632 | else 633 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(mguild.data and json.decode(mguild.data) or mguild.code)) 634 | end 635 | if (Config.Multiguild) then 636 | for _,guildID in pairs(Config.Guilds) do 637 | local guild = DiscordRequest("GET", "guilds/"..guildID, {}) 638 | if guild.code == 200 then 639 | local data = json.decode(guild.data) 640 | sendDebugMessage("[Badger_Discord_API] Successful connection to Guild : "..data.name.." ("..data.id..")") 641 | else 642 | sendDebugMessage("[Badger_Discord_API] An error occured, please check your config and ensure everything is correct. Error: "..(guild.data and json.decode(guild.data) or guild.code)) 643 | end 644 | end 645 | end 646 | end) 647 | -------------------------------------------------------------------------------- /version.txt: -------------------------------------------------------------------------------- 1 | 1.2 -------------------------------------------------------------------------------- /versionChecker.lua: -------------------------------------------------------------------------------- 1 | Citizen.CreateThread(function() 2 | updatePath = "/JaredScar/Badger_Discord_API" -- your git user/repo path 3 | resourceName = "Badger_Discord_API ("..GetCurrentResourceName()..")" -- the resource name 4 | 5 | function checkVersion(err,responseText, headers) 6 | curVersion = LoadResourceFile(GetCurrentResourceName(), "version.txt") -- make sure the "version" file actually exists in your resource root! 7 | 8 | if curVersion ~= responseText and tonumber(curVersion) < tonumber(responseText) then 9 | print("\n###############################") 10 | print("\n"..resourceName.." is outdated, should be: "..responseText.."\nis: "..curVersion.."\nplease update it from https://github.com"..updatePath.."") 11 | print("\n###############################") 12 | elseif tonumber(curVersion) > tonumber(responseText) then 13 | print("You somehow skipped a few versions of "..resourceName.." or the git went offline, if it's still online I advise you to update...") 14 | else 15 | print("\n"..resourceName.." is up to date!") 16 | end 17 | end 18 | 19 | PerformHttpRequest("https://raw.githubusercontent.com/JaredScar/Badger_Discord_API/main/version.txt", checkVersion, "GET") 20 | end) --------------------------------------------------------------------------------