Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add copy discord id button to player menu #829

Merged
merged 8 commits into from
Mar 15, 2024

Conversation

Gravxd
Copy link
Contributor

@Gravxd Gravxd commented Mar 15, 2024

Adds a simple copy discord id button to the player menu inside player management.
Easy, convenient and helpful for server staff - primary identifier for most servers and allows staff to quickly find said player in a server log or if they need to assist them.

Adds new permission player.copydiscord but it doesn't even really need one as identifiers of players are public via the players.json endpoint - so up to you if we keep this permission, can be easily removed of course.

@Blumlaut
Copy link
Owner

doesn't player cache also include identifiers? we could probably remove the entire serverside portion of this, check if the player has a discord id available and then display the button and copy it to clipboard, i dont think we would really need a permission to do that

@Gravxd
Copy link
Contributor Author

Gravxd commented Mar 15, 2024

It does cache but it's an array of idents - maybe we can just have a cachedplayers.discord or something similar for ease of access because otherwise we'd have to get the idents, then loop and handle if it's present or not

@Blumlaut
Copy link
Owner

for i,identifier in pairs(CachedPlayers[playerId].identifiers) do
	if string.sub(identifier,1,8)=="discord:" then
		local copyDiscordItem = NativeUI.CreateItem(GetLocalisedText("copydiscord"), "")
		thisPlayer:AddItem(copyDiscordItem)
		copyDiscordItem.Activated = function(ParentMenu, SelectedItem)
			copyToClipboard(string.gsub(identifier, "discord:", ""))
			TriggerEvent("EasyAdmin:showNotification", GetLocalisedText("copiedtoclipboard"))
		end
	end
end

only issue i can think of is that this would break for clients that dont have access to cache (e.g. missing ban.temporary or ban.permanent)
hmm..

@Gravxd
Copy link
Contributor Author

Gravxd commented Mar 15, 2024

Take a look at those commits - it pulls the discord from the cache as requested, also cleaned up some un-needed loops in favour of quick local tables

@Blumlaut
Copy link
Owner

awesome! i'll quickly get fivem running on my windows partition and give it a whirl.

By the way, do you plan to do any more PRs in the near future -- just so i know if i should delay 7.2 until that's done or not.

@Gravxd
Copy link
Contributor Author

Gravxd commented Mar 15, 2024

No worries, i ran this on my local didn't notice any initial issues - and i'm not sure honestly i just get random ideas or for this case someone asked me for my code on this copy discord id as i have it in my server on a local fork and i was like might as well put it public as i assume many will want it - i wouldn't delay anything for now

@Blumlaut
Copy link
Owner

sounds good! i'll merge this within the hour and then push 7.2 in the coming days, thank you for your continued contributions, they are much appreciated!

@Gravxd
Copy link
Contributor Author

Gravxd commented Mar 15, 2024

No problem, thanks for your time - i've just managed to get into your discord as the invite wasn't working before, mind checking for me?

@Blumlaut Blumlaut merged commit 4c9574f into Blumlaut:master Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants