Skip to content

Commit

Permalink
Fix common interceptors not found issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ShindouMihou committed Mar 5, 2022
1 parent ca6b488 commit b904373
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
3 changes: 3 additions & 0 deletions src/main/java/pw/mihou/nexus/core/NexusCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import pw.mihou.nexus.features.command.core.NexusBaseCommandImplementation;
import pw.mihou.nexus.features.command.core.NexusCommandCore;
import pw.mihou.nexus.features.command.facade.NexusCommand;
import pw.mihou.nexus.features.command.interceptors.commons.NexusCommonInterceptors;
import pw.mihou.nexus.features.command.interceptors.commons.core.NexusCommonInterceptorsCore;
import pw.mihou.nexus.features.command.responders.NexusResponderRepository;
import pw.mihou.nexus.features.command.synchronizer.NexusSynchronizer;
import pw.mihou.nexus.features.messages.defaults.NexusDefaultMessageConfiguration;
Expand Down Expand Up @@ -60,6 +62,7 @@ public NexusCore(
this.shardManager = new NexusShardManager(this);
this.nexusConfiguration = nexusConfiguration;
this.messageConfiguration = Objects.requireNonNullElseGet(messageConfiguration, NexusDefaultMessageConfiguration::new);
NexusCommonInterceptorsCore.addAll();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package pw.mihou.nexus.features.command.interceptors.commons;

import pw.mihou.nexus.features.command.interceptors.facades.NexusCommandInterceptor;
import pw.mihou.nexus.features.messages.facade.NexusMessage;
import pw.mihou.nexus.features.ratelimiter.core.NexusRatelimiterCore;

/**
* This class exists purely to separate the static function of adding
* all the common interceptors. You can use this as a reference for all built-in Nexus middlewares
Expand All @@ -17,20 +13,4 @@ public class NexusCommonInterceptors {
public static final String NEXUS_GATE_DMS = "nexus.gate.dms";
public static final String NEXUS_RATELIMITER = "nexus.ratelimiter";

static {
NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_BOT_OWNER_MIDDLEWARE, event -> event.stopIf(
!event.getUser().isBotOwner(),
NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the bot owner to execute this command.")
));

NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_SERVER_OWNER_MIDDLEWARE, event -> event.stopIf(
event.getServer().isPresent() && event.getServer().get().isOwner(event.getUser()),
NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the server owner to execute this command.")
));

NexusCommandInterceptor.addMiddleware(NEXUS_GATE_SERVER, event -> event.stopIf(event.getServer().isEmpty()));
NexusCommandInterceptor.addMiddleware(NEXUS_GATE_DMS, event -> event.stopIf(event.getServer().isPresent()));
NexusCommandInterceptor.addMiddleware(NEXUS_RATELIMITER, new NexusRatelimiterCore());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pw.mihou.nexus.features.command.interceptors.commons.core;

import pw.mihou.nexus.features.command.interceptors.commons.NexusCommonInterceptors;
import pw.mihou.nexus.features.command.interceptors.facades.NexusCommandInterceptor;
import pw.mihou.nexus.features.messages.facade.NexusMessage;
import pw.mihou.nexus.features.ratelimiter.core.NexusRatelimiterCore;

public class NexusCommonInterceptorsCore extends NexusCommonInterceptors {

public static void addAll() {
NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_BOT_OWNER_MIDDLEWARE, event -> event.stopIf(
!event.getUser().isBotOwner(),
NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the bot owner to execute this command.")
));

NexusCommandInterceptor.addMiddleware(NEXUS_AUTH_SERVER_OWNER_MIDDLEWARE, event -> event.stopIf(
event.getServer().isPresent() && event.getServer().get().isOwner(event.getUser()),
NexusMessage.fromEphemereal("**PERMISSION DENIED**\nYou need to be the server owner to execute this command.")
));

NexusCommandInterceptor.addMiddleware(NEXUS_GATE_SERVER, event -> event.stopIf(event.getServer().isEmpty()));
NexusCommandInterceptor.addMiddleware(NEXUS_GATE_DMS, event -> event.stopIf(event.getServer().isPresent()));
NexusCommandInterceptor.addMiddleware(NEXUS_RATELIMITER, new NexusRatelimiterCore());
}

}

0 comments on commit b904373

Please sign in to comment.