Plan icon indicating copy to clipboard operation
Plan copied to clipboard

Setting player activity as a rank/sync with DiscordSRV

Open TomLewis opened this issue 2 years ago • 6 comments

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%

TomLewis avatar Sep 13 '23 12:09 TomLewis

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 avatar Sep 13 '23 13:09 AuroraLS3

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

AuroraLS3 avatar Sep 13 '23 13:09 AuroraLS3

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

Vankka avatar Oct 04 '23 19:10 Vankka

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

TomLewis avatar Oct 09 '23 11:10 TomLewis

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? :)

AuroraLS3 avatar Oct 09 '23 12:10 AuroraLS3

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.

TomLewis avatar Oct 10 '23 13:10 TomLewis

I started to try make a plugin out of this but forgot about it and it has been sitting there for a year so I probably won't finish it.

Here's the source code if you feel like taking a crack at it. Plan-Autorank.zip

I'll close this for now since I don't have time to implement it.

AuroraLS3 avatar Aug 21 '24 17:08 AuroraLS3