1
1
package org .togetherjava .tjbot .commands .tags ;
2
2
3
- import net .dv8tion .jda .api .Permission ;
4
3
import net .dv8tion .jda .api .entities .Member ;
4
+ import net .dv8tion .jda .api .entities .Role ;
5
5
import net .dv8tion .jda .api .events .interaction .SlashCommandEvent ;
6
6
import net .dv8tion .jda .api .exceptions .ErrorResponseException ;
7
7
import net .dv8tion .jda .api .interactions .Interaction ;
15
15
import org .togetherjava .tjbot .commands .SlashCommandAdapter ;
16
16
import org .togetherjava .tjbot .commands .SlashCommandVisibility ;
17
17
import org .togetherjava .tjbot .commands .utils .MessageUtils ;
18
+ import org .togetherjava .tjbot .config .Config ;
18
19
19
20
import java .util .Objects ;
20
21
import java .util .OptionalLong ;
21
22
import java .util .function .BiConsumer ;
22
23
import java .util .function .Consumer ;
24
+ import java .util .function .Predicate ;
25
+ import java .util .regex .Pattern ;
23
26
24
27
/**
25
28
* Implements the {@code /tag-manage} command which allows management of tags, such as creating,
@@ -45,6 +48,7 @@ public final class TagManageCommand extends SlashCommandAdapter {
45
48
private static final String MESSAGE_ID_OPTION = "message-id" ;
46
49
private static final String MESSAGE_ID_DESCRIPTION = "the id of the message to refer to" ;
47
50
private final TagSystem tagSystem ;
51
+ private final Predicate <String > hasRequiredRole ;
48
52
49
53
/**
50
54
* Creates a new instance, using the given tag system as base.
@@ -55,6 +59,8 @@ public TagManageCommand(TagSystem tagSystem) {
55
59
super ("tag-manage" , "Provides commands to manage all tags" , SlashCommandVisibility .GUILD );
56
60
57
61
this .tagSystem = tagSystem ;
62
+ hasRequiredRole =
63
+ Pattern .compile (Config .getInstance ().getTagManageRolePattern ()).asMatchPredicate ();
58
64
59
65
// TODO Think about adding a "Are you sure"-dialog to 'edit', 'edit-with-message' and
60
66
// 'delete'
@@ -118,9 +124,8 @@ private static OptionalLong parseMessageIdAndHandle(@NotNull String messageId,
118
124
public void onSlashCommand (@ NotNull SlashCommandEvent event ) {
119
125
Member member = Objects .requireNonNull (event .getMember ());
120
126
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." )
124
129
.setEphemeral (true )
125
130
.queue ();
126
131
return ;
0 commit comments