Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions client/discord.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
local config = require 'config.client'.discord
if not config.enabled then return end

local maxPlayers = GlobalState.MaxPlayers
local discord = require 'config.client'.discord

if not discord.enabled then return end
-- Update player count and show player's name in Rich Presence
AddStateBagChangeHandler('PlayerCount', nil, function(bagName, _, value)
if bagName ~= 'global' or not value then return end

AddStateBagChangeHandler('PlayerCount', '', function(bagName, _, value)
if bagName == 'global' and value then
SetRichPresence(('Players %s/%s'):format(value, maxPlayers))
end
local playerName = GetPlayerName(PlayerId())
SetRichPresence(('%s | %s/%s'):format(playerName, value, maxPlayers))
end)

SetDiscordAppId(discord.appId)
SetDiscordRichPresenceAsset(discord.largeIcon.icon)
SetDiscordRichPresenceAssetText(discord.largeIcon.text)
SetDiscordRichPresenceAssetSmall(discord.smallIcon.icon)
SetDiscordRichPresenceAssetSmallText(discord.smallIcon.text)
SetDiscordRichPresenceAction(0, discord.firstButton.text, discord.firstButton.link)
SetDiscordRichPresenceAction(1, discord.secondButton.text, discord.secondButton.link)
SetDiscordAppId(config.appId)
SetDiscordRichPresenceAsset(config.largeIcon.icon)
SetDiscordRichPresenceAssetText(config.largeIcon.text)

if config.smallIcon?.icon and config.smallIcon.icon:len() > 0 then
SetDiscordRichPresenceAssetSmall(config.smallIcon.icon)
SetDiscordRichPresenceAssetSmallText(config.smallIcon.text)
end

SetDiscordRichPresenceAction(0, config.buttons[1].text, config.buttons[1].url)
SetDiscordRichPresenceAction(1, config.buttons[2].text, config.buttons[2].url)