Debug cmd fix, mcchat fix, config error fix

Also removed debug messages
The Minecraft chat didn't run if the command channel was different
The debug command didn't run if the mod role didn't exist
This commit is contained in:
Norbi Peti 2019-06-06 19:40:15 +02:00
parent 9edfcf6a3d
commit 34e3bb0ead
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 22 additions and 18 deletions

View file

@ -68,7 +68,7 @@ public class DiscordPlugin extends ButtonPlugin {
private ConfigData<Optional<Guild>> mainServer() { private ConfigData<Optional<Guild>> mainServer() {
return getIConfig().getDataPrimDef("mainServer", 0L, return getIConfig().getDataPrimDef("mainServer", 0L,
id -> { id -> {
System.out.println("WTF ID: " + id); //TODO: It attempts to get the default as well //It attempts to get the default as well
if ((long) id == 0L) if ((long) id == 0L)
return Optional.empty(); //Hack? return Optional.empty(); //Hack?
return dc.getGuildById(Snowflake.of((long) id)) return dc.getGuildById(Snowflake.of((long) id))
@ -81,6 +81,9 @@ public class DiscordPlugin extends ButtonPlugin {
return DPUtils.snowflakeData(getIConfig(), "commandChannel", 239519012529111040L); return DPUtils.snowflakeData(getIConfig(), "commandChannel", 239519012529111040L);
} }
/**
* If the role doesn't exist, then it will only allow for the owner.
*/
public ConfigData<Mono<Role>> modRole() { public ConfigData<Mono<Role>> modRole() {
return DPUtils.roleData(getIConfig(), "modRole", "Moderator"); return DPUtils.roleData(getIConfig(), "modRole", "Moderator");
} }
@ -138,10 +141,7 @@ public class DiscordPlugin extends ButtonPlugin {
private void handleReady(List<GuildCreateEvent> event) { private void handleReady(List<GuildCreateEvent> event) {
try { try {
System.out.println("w t f: " + mainServer);
mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards
System.out.println("Main server: " + mainServer);
System.out.println("wtf: " + mainServer().get());
if (mainServer == null) { if (mainServer == null) {
if (event.size() == 0) { if (event.size() == 0) {
getLogger().severe("Main server not found! Invite the bot and do /discord reset"); getLogger().severe("Main server not found! Invite the bot and do /discord reset");
@ -153,7 +153,8 @@ public class DiscordPlugin extends ButtonPlugin {
mainServer().set(Optional.of(mainServer)); //Save in config mainServer().set(Optional.of(mainServer)); //Save in config
} }
SafeMode = false; SafeMode = false;
DPUtils.disableIfConfigError(null, commandChannel(), modRole()); //Won't disable, just prints the warning here DPUtils.disableIfConfigErrorRes(null, commandChannel(), DPUtils.getMessageChannel(commandChannel()));
DPUtils.disableIfConfigError(null, modRole()); //Won't disable, just prints the warning here
Component.registerComponent(this, new GeneralEventBroadcasterModule()); Component.registerComponent(this, new GeneralEventBroadcasterModule());
Component.registerComponent(this, new MinecraftChatModule()); Component.registerComponent(this, new MinecraftChatModule());

View file

@ -17,7 +17,8 @@ public class DebugCommand extends ICommand2DC {
.map(u -> u.asMember(DiscordPlugin.mainServer.getId())) .map(u -> u.asMember(DiscordPlugin.mainServer.getId()))
.orElse(Mono.empty())) .orElse(Mono.empty()))
.flatMap(m -> DiscordPlugin.plugin.modRole().get() .flatMap(m -> DiscordPlugin.plugin.modRole().get()
.map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId())))) .map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId())))
.switchIfEmpty(Mono.fromSupplier(() -> DiscordPlugin.mainServer.getOwnerId().asLong() == m.getId().asLong()))) //Role not found
.subscribe(success -> { .subscribe(success -> {
if (success) if (success)
sender.sendMessage("debug " + (CommonListeners.debug() ? "enabled" : "disabled")); sender.sendMessage("debug " + (CommonListeners.debug() ? "enabled" : "disabled"));

View file

@ -47,11 +47,13 @@ public class CommonListeners {
return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch -> return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch ->
(commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat (commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat
|| mch instanceof PrivateChannel || mch instanceof PrivateChannel
|| event.getMessage().getContent().orElse("").contains("channelcon"))) //Only 'channelcon' is allowed in other channels || event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels
.filterWhen(ch -> { //Only continue if this doesn't handle the event .flatMap(shouldRun -> { //Only continue if this doesn't handle the event
if (!shouldRun)
return Mono.just(true); //The condition is only for the first command execution, not mcchat
timings.printElapsed("Run command 1"); timings.printElapsed("Run command 1");
return CommandListener.runCommand(event.getMessage(), ch, true); //#bot is handled here return CommandListener.runCommand(event.getMessage(), ch, true); //#bot is handled here
}).filterWhen(ch -> { })).filterWhen(ch -> {
timings.printElapsed("mcchat"); timings.printElapsed("mcchat");
val mcchat = Component.getComponents().get(MinecraftChatModule.class); val mcchat = Component.getComponents().get(MinecraftChatModule.class);
if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again