[Feature] Self-assigned roles
See original GitHub issueThis recommendation comes from discussion in the C# server and is something I designed in a custom bot of my own. This issue is being opened for discussion, particularly for generalization, since the current system was built strictly with my guild in mind. As such, the description below will cover how it’s set up with my bot.
This system allows for specified roles to be opted-into by the user. This can be used purely for cosmetics or for opting-in to notifications or the ability to read or write to particular channels- essentially whatever can be done by assigning a role to a user.
On the user’s end, they need only worry about three commands: !iam
, !iamnot
, and !roles
. The !iam
and !iamnot
commands accept a list of roles (with params
) as an argument. Both commands operate in exactly the same manner up until the last operation:
- Iterate through each of the requested roles and cast them to an
AssignableRole
. Should casting fail, the role is assumed to not be assignable. - Check the
AssignmentMethod
property - an enum which allows you to temporarily disable certain roles. - If assigning, check for prerequisites on the AssignableRole - should those exist and they are satisfied, assign the role. If removing, skip the prerequisite check and just remove the role.
Prerequisite types available for roles are role
(stored as the role’s ulong) and Period
from NodaTime. This allows me to configure a prerequisite for another role (for instance, in my server, you can opt-in to the NSFW role, but you can only do so if you already have the 18+ role, the latter of which is granted by a mod), or a duration (for instance, requiring users to be present for 24 hours before allowing them to get a certain role).
Admin side is nothing interesting. Just the standard accoutrement of commands mapped to the particular property you wish to modify on an existing AssignableRole, or creating or destroying such. Overall, it works pretty well for my purposes.
Here’s a view of the output of the !roles
command, page 5, from my server. Note the category (just above the listing)
Adding a role:
Artist
is not assignable:
How categories are used. These are the roles I have on my account: (all the free demographic information)
Some topics for discussion:
- Role Categories Role Categories on my guild are granted when the user first joins the server (as defined by an AutoIssue flag). They can also be assigned when a user opts-into a role under that category. However, no code yet exists to remove an empty category as I don’t use that option.
- Prerequisite Handling Currently, I have two types of prerequisites, each as their own property on the AssignableRole object. Should this remain as-is or should it be moved to a
List<IPrerequisite>
of some sort to allow users to define their own (perhaps hooking into the proposed plugin feature which doesn’t have an issue yet?) - AssignmentMethod enum Currently this is only used to disable the role, though it can possibly be extended.
- Description I started building this in but I’ve not yet finished it. Each assignable role has a Description (
string
) property which is planned to be displayed next to the role name in the listing.
Code documents of relevance for this bot: IAssignableRole, AssignableRole
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
I’m swooping this up if nobody has any objections 😃
So, stripping out the implementation, all this really is is a way for users to assign cosmetic-only roles to themselves, yes?
This sounds stupid simple, given our current architecture. Simply add a new
DesignatedRoleType
ofSelfAssignable
orTag
or something similar, and then we just need the commands to allow users to assign and unassign them.Definitely add
AuthorizationClaim
values for these commands as well. Although you might want to allow any and everyone to use them, I think in the main C# server, we’ll probably limit it to at least Regular and above.