@@ -75,6 +75,7 @@ public class CommandClientImpl implements CommandClient, EventListener
75
75
private final String altprefix ;
76
76
private final String [] prefixes ;
77
77
private final Function <MessageReceivedEvent , String > prefixFunction ;
78
+ private final Function <MessageReceivedEvent , Boolean > commandPreProcessFunction ;
78
79
private final String serverInvite ;
79
80
private final HashMap <String , Integer > commandIndex ;
80
81
private final ArrayList <Command > commands ;
@@ -97,7 +98,7 @@ public class CommandClientImpl implements CommandClient, EventListener
97
98
private CommandListener listener = null ;
98
99
private int totalGuilds ;
99
100
100
- public CommandClientImpl (String ownerId , String [] coOwnerIds , String prefix , String altprefix , String [] prefixes , Function <MessageReceivedEvent , String > prefixFunction , Activity activity , OnlineStatus status , String serverInvite ,
101
+ public CommandClientImpl (String ownerId , String [] coOwnerIds , String prefix , String altprefix , String [] prefixes , Function <MessageReceivedEvent , String > prefixFunction , Function < MessageReceivedEvent , Boolean > commandPreProcessFunction , Activity activity , OnlineStatus status , String serverInvite ,
101
102
String success , String warning , String error , String carbonKey , String botsKey , ArrayList <Command > commands ,
102
103
boolean useHelp , boolean shutdownAutomatically , Consumer <CommandEvent > helpConsumer , String helpWord , ScheduledExecutorService executor ,
103
104
int linkedCacheSize , AnnotatedModuleCompiler compiler , GuildSettingsManager manager )
@@ -124,6 +125,7 @@ public CommandClientImpl(String ownerId, String[] coOwnerIds, String prefix, Str
124
125
this .altprefix = altprefix ==null || altprefix .isEmpty () ? null : altprefix ;
125
126
this .prefixes = prefixes ==null || prefixes .length == 0 ? null : prefixes ;
126
127
this .prefixFunction = prefixFunction ;
128
+ this .commandPreProcessFunction = commandPreProcessFunction ==null ? event -> true : commandPreProcessFunction ;
127
129
this .textPrefix = prefix ;
128
130
this .activity = activity ;
129
131
this .status = status ;
@@ -592,7 +594,10 @@ else if(event.isFromType(ChannelType.PRIVATE) || event.getTextChannel().canTalk(
592
594
if (listener != null )
593
595
listener .onCommand (cevent , command );
594
596
uses .put (command .getName (), uses .getOrDefault (command .getName (), 0 ) + 1 );
595
- command .run (cevent );
597
+ if (commandPreProcessFunction .apply (event ))
598
+ {
599
+ command .run (cevent );
600
+ }
596
601
return ; // Command is done
597
602
}
598
603
}
0 commit comments