11package org .togetherjava .tjbot .commands .tags ;
22
3- import net .dv8tion .jda .api .Permission ;
43import net .dv8tion .jda .api .entities .Member ;
4+ import net .dv8tion .jda .api .entities .Role ;
55import net .dv8tion .jda .api .events .interaction .SlashCommandEvent ;
66import net .dv8tion .jda .api .exceptions .ErrorResponseException ;
77import net .dv8tion .jda .api .interactions .Interaction ;
1515import org .togetherjava .tjbot .commands .SlashCommandAdapter ;
1616import org .togetherjava .tjbot .commands .SlashCommandVisibility ;
1717import org .togetherjava .tjbot .commands .utils .MessageUtils ;
18+ import org .togetherjava .tjbot .config .Config ;
1819
1920import java .util .Objects ;
2021import java .util .OptionalLong ;
2122import java .util .function .BiConsumer ;
2223import java .util .function .Consumer ;
24+ import java .util .function .Predicate ;
25+ import java .util .regex .Pattern ;
2326
2427/**
2528 * Implements the {@code /tag-manage} command which allows management of tags, such as creating,
@@ -45,6 +48,7 @@ public final class TagManageCommand extends SlashCommandAdapter {
4548 private static final String MESSAGE_ID_OPTION = "message-id" ;
4649 private static final String MESSAGE_ID_DESCRIPTION = "the id of the message to refer to" ;
4750 private final TagSystem tagSystem ;
51+ private final Predicate <String > hasRequiredRole ;
4852
4953 /**
5054 * Creates a new instance, using the given tag system as base.
@@ -55,6 +59,8 @@ public TagManageCommand(TagSystem tagSystem) {
5559 super ("tag-manage" , "Provides commands to manage all tags" , SlashCommandVisibility .GUILD );
5660
5761 this .tagSystem = tagSystem ;
62+ hasRequiredRole =
63+ Pattern .compile (Config .getInstance ().getTagManageRolePattern ()).asMatchPredicate ();
5864
5965 // TODO Think about adding a "Are you sure"-dialog to 'edit', 'edit-with-message' and
6066 // 'delete'
@@ -118,9 +124,8 @@ private static OptionalLong parseMessageIdAndHandle(@NotNull String messageId,
118124 public void onSlashCommand (@ NotNull SlashCommandEvent event ) {
119125 Member member = Objects .requireNonNull (event .getMember ());
120126
121- if (!member .hasPermission (Permission .MESSAGE_MANAGE )) {
122- event .reply (
123- "Tags can only be managed by users who have the 'MESSAGE_MANAGE' permission." )
127+ if (member .getRoles ().stream ().map (Role ::getName ).noneMatch (hasRequiredRole )) {
128+ event .reply ("Tags can only be managed by users with a corresponding role." )
124129 .setEphemeral (true )
125130 .queue ();
126131 return ;
0 commit comments