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

Setting player activity as a rank/sync with DiscordSRV #3208

Open
TomLewis opened this issue Sep 13, 2023 · 6 comments
Open

Setting player activity as a rank/sync with DiscordSRV #3208

TomLewis opened this issue Sep 13, 2023 · 6 comments

Comments

@TomLewis
Copy link

TomLewis commented Sep 13, 2023

I would like to be able to..

Ahoy!

Activity as Group/rank & Discord role

I would like to be able to have roles on my discord server that are 1:1 copies of player activity on Plan.

DiscordSRV can sync ranks, so it could be as simple as manually creating ranks in Luckperms and then having Plan set the rank when they log in to their Activity status, this could be a simple array in the plan configs, for example "Very Active = VeryActiveRank" then in the DiscordSRV settings have that rank sync to a discord role.

Reasoning

This would provide fantastic insight into the activity of a player if they are ranting or posting on a discord which is seperate from in-game, for example servers with a lot of players will still have hundreads of peolpe in the discord that no longer play on the server!

Is your feature request related to a problem? Please describe.

  1. Ex-players or inactive players would be shown as a muted grey color so people understand their views may be outdated as they no longer play.
  2. Being able to limit discord channels based on activity, for exmaple suggestions channel could be for Very Active players only

Considered Options

You have an activity placeholder, I was going to just try and script this in commandhelper, that when players log in, it grabs their Activity and sets them at the correct LP group if its changed, BUT I cant get the placeholder to display the first time its used, I tested it in chat and it takes a few times of spamming it to actually pull the activity of a player, otherwise it just displays as the placeholder text.

I have set %player_activity_group% in Load_these_placeholders_on_join with no change in having to spam it to work. Via https://github.com/plan-player-analytics/Plan/wiki/PlaceholderAPI

    PlaceholderAPI:
        Tracked_player_placeholders:
          - %example_placeholder%
        Enabled: true
        Load_these_placeholders_on_join:
          - %plan_server_uuid%
          - %player_activity_group%
@AuroraLS3
Copy link
Collaborator

AuroraLS3 commented Sep 13, 2023

This behavior of the placeholder occurs when stuff is executed on the server thread. If it is possible to switch command helper to execute async task it will wait until value is available to do the replacement. Async way it's always replaced on first try.

(This is to not crash the server.)

If you have a plugin doing it, the common queries in Query API can fetch the activity index of a player, skipping the placeholder api middleman

@AuroraLS3
Copy link
Collaborator

This sounds like a 3rd plugin needs to be implemented using apis of LuckPerms (or discordSRV) and Plan

@Vankka
Copy link
Contributor

Vankka commented Oct 4, 2023

You might be able to do this with ExtraContexts (specifically it's PlaceholderAPI integration) then granting the discordsrv.sync.<group name> permission to grant the specific group-role pair for synchronization

Something like this (entirely untested),

DiscordSRV synchronization.yaml

GroupRoleSynchronizationGroupsAndRolesToSync: {"veryactive": "...", "active": "..."}

ExtraContexts config

placeholderapi-placeholders:
  activitygroup: "%plan_player_activity_group%"

LuckPerms permissions

/lp group default permission set discordsrv.sync.veryactive true activitygroup=VeryActive
/lp group default permission set discordsrv.sync.active true activitygroup=Active

@TomLewis
Copy link
Author

TomLewis commented Oct 9, 2023

That could be another option, I would just need %plan_player_activity_group% to work when its called first time!
Any ideas?

@AuroraLS3
Copy link
Collaborator

I think Luckperms updates context on the server thread (not 100% sure), and trying to load data from database on the server thread will crash the server.

Because Plan placeholders lookup database stuff, when something on server thread tries to look up the value it instead returns early and runs a task to get the data asynchronously. This is why it works 2nd time.

Placing the value in Load_these_placeholders_on_join will make Plan lookup the placeholder value as soon as player joins, asynchronously. Before the data is available the placeholder can't return anything.

If the other plugin does the placeholder thing asynchronously then Plan can safely wait for the query to finish and it'll return the value on 1st try.

Did you test out extracontexts yet? :)

@TomLewis
Copy link
Author

I cant test out ExtraContexts until get that placeholder to work when its used, in the inital ticket I already tested with Load_these_placeholders_on_join and it made no difference, I was curious if it was because its based per player or how I could fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: INBOX
Development

No branches or pull requests

3 participants