Add logging 'proxy', centralize insufficient permission handling, improved toString, equals and hashCode implementations of 1st party Discord api entities

This commit is contained in:
Vankka 2022-01-15 14:45:50 +02:00
parent d3faafcece
commit 1068150f77
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
37 changed files with 236 additions and 191 deletions

View File

@ -84,7 +84,7 @@ public class BukkitDiscordSRV extends ServerDiscordSRV<BukkitConfig, BukkitConne
} }
@Override @Override
public Logger logger() { public Logger platformLogger() {
return logger; return logger;
} }

View File

@ -20,7 +20,7 @@ package com.discordsrv.bukkit;
import com.discordsrv.common.dependency.InitialDependencyLoader; import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.JavaLoggerImpl; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import dev.vankka.mcdependencydownload.bukkit.bootstrap.BukkitBootstrap; import dev.vankka.mcdependencydownload.bukkit.bootstrap.BukkitBootstrap;
import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader; import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;

View File

@ -21,8 +21,8 @@ package com.discordsrv.bukkit.console;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.JavaLoggerImpl; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -70,7 +70,7 @@ public class BungeeDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionConf
} }
@Override @Override
public Logger logger() { public Logger platformLogger() {
return logger; return logger;
} }

View File

@ -20,7 +20,7 @@ package com.discordsrv.bungee;
import com.discordsrv.common.dependency.InitialDependencyLoader; import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.JavaLoggerImpl; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import dev.vankka.mcdependencydownload.bungee.bootstrap.BungeeBootstrap; import dev.vankka.mcdependencydownload.bungee.bootstrap.BungeeBootstrap;
import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader; import dev.vankka.mcdependencydownload.classloader.JarInJarClassLoader;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;

View File

@ -21,7 +21,7 @@ package com.discordsrv.bungee.console;
import com.discordsrv.bungee.BungeeDiscordSRV; import com.discordsrv.bungee.BungeeDiscordSRV;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.JavaLoggerImpl; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -18,6 +18,8 @@
package com.discordsrv.common.logging; package com.discordsrv.common.logging;
import java.util.Locale;
public interface LogLevel { public interface LogLevel {
LogLevel INFO = StandardLogLevel.INFO; LogLevel INFO = StandardLogLevel.INFO;
@ -28,7 +30,7 @@ public interface LogLevel {
static LogLevel of(String name) { static LogLevel of(String name) {
try { try {
return StandardLogLevel.valueOf(name); return StandardLogLevel.valueOf(name.toUpperCase(Locale.ROOT));
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
return new CustomLogLevel(name); return new CustomLogLevel(name);
} }

View File

@ -1,3 +1,21 @@
/*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/** /**
* DiscordSRV's own implementation of SLF4J (relocated during runtime) that forwards log messages to the server's logger. * DiscordSRV's own implementation of SLF4J (relocated during runtime) that forwards log messages to the server's logger.
*/ */

View File

@ -39,8 +39,10 @@ import com.discordsrv.common.discord.details.DiscordConnectionDetailsImpl;
import com.discordsrv.common.event.bus.EventBusImpl; import com.discordsrv.common.event.bus.EventBusImpl;
import com.discordsrv.common.function.CheckedRunnable; import com.discordsrv.common.function.CheckedRunnable;
import com.discordsrv.common.integration.LuckPermsIntegration; import com.discordsrv.common.integration.LuckPermsIntegration;
import com.discordsrv.common.logging.impl.DiscordSRVLogger;
import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.adapter.DependencyLoggerAdapter; import com.discordsrv.common.logging.adapter.DependencyLoggerAdapter;
import com.discordsrv.common.logging.dependency.DependencyLoggingHandler; import com.discordsrv.common.logging.impl.DependencyLoggingHandler;
import com.discordsrv.common.messageforwarding.discord.DiscordChatMessageModule; import com.discordsrv.common.messageforwarding.discord.DiscordChatMessageModule;
import com.discordsrv.common.messageforwarding.discord.DiscordMessageMirroringModule; import com.discordsrv.common.messageforwarding.discord.DiscordMessageMirroringModule;
import com.discordsrv.common.messageforwarding.game.JoinMessageModule; import com.discordsrv.common.messageforwarding.game.JoinMessageModule;
@ -82,6 +84,7 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
private DiscordConnectionDetails discordConnectionDetails; private DiscordConnectionDetails discordConnectionDetails;
// DiscordSRV // DiscordSRV
private final DiscordSRVLogger logger;
private ChannelConfigHelper channelConfig; private ChannelConfigHelper channelConfig;
private ModuleManager moduleManager; private ModuleManager moduleManager;
private DiscordConnectionManager discordConnectionManager; private DiscordConnectionManager discordConnectionManager;
@ -91,6 +94,7 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
public AbstractDiscordSRV() { public AbstractDiscordSRV() {
ApiInstanceUtil.setInstance(this); ApiInstanceUtil.setInstance(this);
this.logger = new DiscordSRVLogger(this);
} }
protected final void load() { protected final void load() {
@ -141,6 +145,11 @@ public abstract class AbstractDiscordSRV<C extends MainConfig, CC extends Connec
// DiscordSRV // DiscordSRV
@Override
public Logger logger() {
return logger;
}
@Override @Override
public ChannelConfigHelper channelConfig() { public ChannelConfigHelper channelConfig() {
return channelConfig; return channelConfig;

View File

@ -46,7 +46,7 @@ import java.util.concurrent.TimeUnit;
public interface DiscordSRV extends DiscordSRVApi { public interface DiscordSRV extends DiscordSRVApi {
// Platform // Platform
Logger logger(); Logger platformLogger();
Path dataDirectory(); Path dataDirectory();
Scheduler scheduler(); Scheduler scheduler();
Console console(); Console console();
@ -69,6 +69,9 @@ public interface DiscordSRV extends DiscordSRVApi {
@NotNull @NotNull
DiscordAPIImpl discordAPI(); DiscordAPIImpl discordAPI();
// Logger
Logger logger();
// Config // Config
ConnectionConfigManager<? extends ConnectionConfig> connectionConfigManager(); ConnectionConfigManager<? extends ConnectionConfig> connectionConfigManager();
ConnectionConfig connectionConfig(); ConnectionConfig connectionConfig();

View File

@ -94,6 +94,7 @@ public class ChannelUpdaterModule extends AbstractModule {
continue; continue;
} }
try {
ChannelManager<?, ?> manager = channel.getManager(); ChannelManager<?, ?> manager = channel.getManager();
boolean anythingChanged = false; boolean anythingChanged = false;
if (manager instanceof TextChannelManager && channel instanceof TextChannel if (manager instanceof TextChannelManager && channel instanceof TextChannel
@ -108,10 +109,17 @@ public class ChannelUpdaterModule extends AbstractModule {
} }
if (!anythingChanged) { if (!anythingChanged) {
discordSRV.logger().debug("Skipping updating channel " + channel + ": nothing changed");
continue; continue;
} }
manager.timeout(30, TimeUnit.SECONDS).queue(); manager.timeout(30, TimeUnit.SECONDS).queue(
null,
t -> discordSRV.logger().error("Failed to update channel " + channel, t)
);
} catch (Throwable t) {
discordSRV.logger().error("Failed to update channel " + channel, t);
}
} }
} }

View File

@ -51,7 +51,6 @@ import net.dv8tion.jda.api.entities.ThreadChannel;
import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.Webhook; import net.dv8tion.jda.api.entities.Webhook;
import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.exceptions.ErrorResponseException;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.dv8tion.jda.api.requests.ErrorResponse; import net.dv8tion.jda.api.requests.ErrorResponse;
import net.dv8tion.jda.api.requests.GatewayIntent; import net.dv8tion.jda.api.requests.GatewayIntent;
import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.index.qual.NonNegative;
@ -157,16 +156,10 @@ public class DiscordAPIImpl implements DiscordAPI {
} }
futures.add(future.handle((threadChannel, t) -> { futures.add(future.handle((threadChannel, t) -> {
if (t instanceof InsufficientPermissionException) { if (t != null) {
discordSRV.logger().error( discordSRV.logger().error("Failed to deliver message to thread \""
"Unable to send message to channel " + channel + threadConfig.threadName + "\" in channel " + channel, t);
+ " because the bot is lacking the " throw new RuntimeException(); // Just here to fail the future
+ ((InsufficientPermissionException) t).getPermission().getName()
+ " permission");
throw new RuntimeException();
} else if (t != null) {
discordSRV.logger().error("Failed to find thread in channel " + channel, t);
throw new RuntimeException();
} }
if (threadChannel != null) { if (threadChannel != null) {

View File

@ -98,4 +98,9 @@ public class DiscordUserImpl implements DiscordUser {
public String getAsMention() { public String getAsMention() {
return user.getAsMention(); return user.getAsMention();
} }
@Override
public String toString() {
return "User:" + getUsername() + "(" + Long.toUnsignedString(getId()) + ")";
}
} }

View File

@ -29,6 +29,7 @@ import com.discordsrv.common.discord.api.entity.message.util.SendableDiscordMess
import net.dv8tion.jda.api.entities.PrivateChannel; import net.dv8tion.jda.api.entities.PrivateChannel;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Objects;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public class DiscordDMChannelImpl extends DiscordMessageChannelImpl<PrivateChannel> implements DiscordDMChannel { public class DiscordDMChannelImpl extends DiscordMessageChannelImpl<PrivateChannel> implements DiscordDMChannel {
@ -85,4 +86,22 @@ public class DiscordDMChannelImpl extends DiscordMessageChannelImpl<PrivateChann
public PrivateChannel getAsJDAPrivateChannel() { public PrivateChannel getAsJDAPrivateChannel() {
return channel; return channel;
} }
@Override
public String toString() {
return "DMChannel:" + user + "(" + Long.toUnsignedString(getId()) + ")";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiscordDMChannelImpl that = (DiscordDMChannelImpl) o;
return Objects.equals(user.getId(), that.user.getId());
}
@Override
public int hashCode() {
return Objects.hash(user.getId());
}
} }

View File

@ -22,6 +22,8 @@ import com.discordsrv.api.discord.api.entity.channel.DiscordMessageChannel;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import java.util.Objects;
public abstract class DiscordMessageChannelImpl<T extends MessageChannel> public abstract class DiscordMessageChannelImpl<T extends MessageChannel>
implements DiscordMessageChannel { implements DiscordMessageChannel {
@ -56,4 +58,17 @@ public abstract class DiscordMessageChannelImpl<T extends MessageChannel>
public MessageChannel getAsJDAMessageChannel() { public MessageChannel getAsJDAMessageChannel() {
return channel; return channel;
} }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
DiscordGuildMessageChannelImpl<?> that = (DiscordGuildMessageChannelImpl<?>) o;
return Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
} }

View File

@ -34,4 +34,9 @@ public class DiscordNewsChannelImpl
public NewsChannel getAsJDANewsChannel() { public NewsChannel getAsJDANewsChannel() {
return channel; return channel;
} }
@Override
public String toString() {
return "NewsChannel:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
} }

View File

@ -39,4 +39,8 @@ public class DiscordTextChannelImpl extends DiscordGuildMessageChannelImpl<TextC
return channel; return channel;
} }
@Override
public String toString() {
return "TextChannel:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
} }

View File

@ -105,4 +105,9 @@ public class DiscordThreadChannelImpl extends DiscordMessageChannelImpl<ThreadCh
public ThreadChannel getAsJDAThreadChannel() { public ThreadChannel getAsJDAThreadChannel() {
return channel; return channel;
} }
@Override
public String toString() {
return "Thread:" + getName() + "(" + Long.toUnsignedString(getId()) + " in " + textChannel + ")";
}
} }

View File

@ -109,4 +109,9 @@ public class DiscordGuildImpl implements DiscordGuild {
public int hashCode() { public int hashCode() {
return Objects.hash(getId()); return Objects.hash(getId());
} }
@Override
public String toString() {
return "Guild:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
} }

View File

@ -127,4 +127,9 @@ public class DiscordGuildMemberImpl extends DiscordUserImpl implements DiscordGu
return ComponentUtil.join(Component.text(suffix), components); return ComponentUtil.join(Component.text(suffix), components);
} }
@Override
public String toString() {
return "ServerMember:" + super.toString() + "/" + getGuild();
}
} }

View File

@ -62,4 +62,9 @@ public class DiscordRoleImpl implements DiscordRole {
public String getAsMention() { public String getAsMention() {
return role.getAsMention(); return role.getAsMention();
} }
@Override
public String toString() {
return "ServerRole:" + getName() + "(" + Long.toUnsignedString(getId()) + ")";
}
} }

View File

@ -309,4 +309,9 @@ public class ReceivedDiscordMessageImpl extends SendableDiscordMessageImpl imple
return ComponentUtil.join(Component.text(suffix), components); return ComponentUtil.join(Component.text(suffix), components);
} }
@Override
public String toString() {
return "ReceivedMessage:" + Long.toUnsignedString(getId()) + "/" + getChannel();
}
} }

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.discordsrv.common.logging.impl; package com.discordsrv.common.logging.backend.impl;
import com.discordsrv.common.logging.LogLevel; import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.discordsrv.common.logging.impl; package com.discordsrv.common.logging.backend.impl;
import com.discordsrv.common.logging.LogLevel; import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.LogAppender; import com.discordsrv.common.logging.LogAppender;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.discordsrv.common.logging.impl; package com.discordsrv.common.logging.backend.impl;
import com.discordsrv.common.logging.LogLevel; import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;

View File

@ -16,7 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package com.discordsrv.common.logging.dependency; package com.discordsrv.common.logging.impl;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.logging.LogLevel; import com.discordsrv.common.logging.LogLevel;

View File

@ -0,0 +1,59 @@
/*
* This file is part of DiscordSRV, licensed under the GPLv3 License
* Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.discordsrv.common.logging.impl;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.logging.LogLevel;
import com.discordsrv.common.logging.Logger;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class DiscordSRVLogger implements Logger {
private final DiscordSRV discordSRV;
public DiscordSRVLogger(DiscordSRV discordSRV) {
this.discordSRV = discordSRV;
}
@Override
public void log(@NotNull LogLevel logLevel, @Nullable String message, @Nullable Throwable throwable) {
if (logLevel == LogLevel.DEBUG || logLevel == LogLevel.TRACE || logLevel instanceof LogLevel.CustomLogLevel) {
// TODO: handle debug/trace
return;
}
if (throwable instanceof InsufficientPermissionException) {
Permission permission = ((InsufficientPermissionException) throwable).getPermission();
String msg = "The bot is missing the \"" + permission.getName() + "\" permission";
if (message == null) {
message = msg;
} else {
message += ": " + msg;
}
discordSRV.platformLogger().log(logLevel, message, null);
discordSRV.logger().debug(throwable);
return;
}
discordSRV.platformLogger().log(logLevel, message, throwable);
}
}

View File

@ -36,13 +36,14 @@ import com.discordsrv.common.config.main.channels.base.IChannelConfig;
import com.discordsrv.common.discord.api.entity.message.ReceivedDiscordMessageClusterImpl; import com.discordsrv.common.discord.api.entity.message.ReceivedDiscordMessageClusterImpl;
import com.discordsrv.common.function.OrDefault; import com.discordsrv.common.function.OrDefault;
import com.discordsrv.common.module.type.AbstractModule; import com.discordsrv.common.module.type.AbstractModule;
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionException;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
@ -116,28 +117,21 @@ public abstract class AbstractGameMessageModule<T> extends AbstractModule {
} }
String message = convertMessage(config, ComponentUtil.fromAPI(event.getMessage())); String message = convertMessage(config, ComponentUtil.fromAPI(event.getMessage()));
List<CompletableFuture<ReceivedDiscordMessage>> messageFutures; Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> messageFutures;
messageFutures = sendMessageToChannels( messageFutures = sendMessageToChannels(
config, format, messageChannels, message, config, format, messageChannels, message,
// Context // Context
channelConfig, player channelConfig, player
); );
CompletableFuture.allOf(messageFutures.toArray(new CompletableFuture[0])) CompletableFuture.allOf(messageFutures.keySet().toArray(new CompletableFuture[0]))
.whenComplete((vo, t2) -> { .whenComplete((vo, t2) -> {
List<ReceivedDiscordMessage> messages = new ArrayList<>(); List<ReceivedDiscordMessage> messages = new ArrayList<>();
for (CompletableFuture<ReceivedDiscordMessage> future : messageFutures) { for (Map.Entry<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> entry : messageFutures.entrySet()) {
CompletableFuture<ReceivedDiscordMessage> future = entry.getKey();
if (future.isCompletedExceptionally()) { if (future.isCompletedExceptionally()) {
future.exceptionally(t -> { future.exceptionally(t -> {
if (t instanceof InsufficientPermissionException) { discordSRV.logger().error("Failed to deliver a message to the " + entry.getValue() + " channel", t);
discordSRV.logger().error(
"Unable to send message to a Discord channel"
+ " because the bot is lacking the "
+ ((InsufficientPermissionException) t).getPermission().getName()
+ " permission");
} else {
discordSRV.logger().error("Failed to deliver a message to Discord", t);
}
return null; return null;
}); });
// Ignore ones that failed // Ignore ones that failed
@ -171,7 +165,7 @@ public abstract class AbstractGameMessageModule<T> extends AbstractModule {
); );
} }
public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels( public Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> sendMessageToChannels(
OrDefault<T> config, OrDefault<T> config,
SendableDiscordMessage.Builder format, SendableDiscordMessage.Builder format,
List<DiscordMessageChannel> channels, List<DiscordMessageChannel> channels,
@ -184,9 +178,9 @@ public abstract class AbstractGameMessageModule<T> extends AbstractModule {
.applyPlaceholderService() .applyPlaceholderService()
.build(); .build();
List<CompletableFuture<ReceivedDiscordMessage>> futures = new ArrayList<>(); Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> futures = new LinkedHashMap<>();
for (DiscordMessageChannel channel : channels) { for (DiscordMessageChannel channel : channels) {
futures.add(channel.sendMessage(discordMessage)); futures.put(channel.sendMessage(discordMessage), channel);
} }
return futures; return futures;

View File

@ -115,7 +115,7 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
} }
@Override @Override
public List<CompletableFuture<ReceivedDiscordMessage>> sendMessageToChannels( public Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> sendMessageToChannels(
OrDefault<MinecraftToDiscordChatConfig> config, OrDefault<MinecraftToDiscordChatConfig> config,
SendableDiscordMessage.Builder format, SendableDiscordMessage.Builder format,
List<DiscordMessageChannel> channels, List<DiscordMessageChannel> channels,
@ -137,7 +137,7 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
.add(channel); .add(channel);
} }
List<CompletableFuture<ReceivedDiscordMessage>> futures = new ArrayList<>(); Map<CompletableFuture<ReceivedDiscordMessage>, DiscordMessageChannel> futures = new LinkedHashMap<>();
OrDefault<MinecraftToDiscordChatConfig.Mentions> mentionConfig = config.map(cfg -> cfg.mentions); OrDefault<MinecraftToDiscordChatConfig.Mentions> mentionConfig = config.map(cfg -> cfg.mentions);
// Format messages per-Guild // Format messages per-Guild
@ -179,13 +179,13 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
if (!text.isEmpty()) { if (!text.isEmpty()) {
SendableDiscordMessage finalMessage = discordMessage.build(); SendableDiscordMessage finalMessage = discordMessage.build();
for (DiscordMessageChannel channel : text) { for (DiscordMessageChannel channel : text) {
futures.add(channel.sendMessage(finalMessage)); futures.put(channel.sendMessage(finalMessage), channel);
} }
} }
if (!thread.isEmpty()) { if (!thread.isEmpty()) {
SendableDiscordMessage finalMessage = discordMessage.convertToNonWebhook().build(); SendableDiscordMessage finalMessage = discordMessage.convertToNonWebhook().build();
for (DiscordMessageChannel channel : thread) { for (DiscordMessageChannel channel : thread) {
futures.add(channel.sendMessage(finalMessage)); futures.put(channel.sendMessage(finalMessage), channel);
} }
} }
} }

View File

@ -24,7 +24,7 @@ import com.discordsrv.common.config.manager.ConnectionConfigManager;
import com.discordsrv.common.config.manager.MainConfigManager; import com.discordsrv.common.config.manager.MainConfigManager;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.JavaLoggerImpl; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl;
import com.discordsrv.common.player.provider.AbstractPlayerProvider; import com.discordsrv.common.player.provider.AbstractPlayerProvider;
import com.discordsrv.common.scheduler.Scheduler; import com.discordsrv.common.scheduler.Scheduler;
import com.discordsrv.common.scheduler.StandardScheduler; import com.discordsrv.common.scheduler.StandardScheduler;
@ -44,7 +44,7 @@ public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionCon
} }
@Override @Override
public Logger logger() { public Logger platformLogger() {
return logger; return logger;
} }

View File

@ -18,64 +18,30 @@
package com.discordsrv.config; package com.discordsrv.config;
import com.discordsrv.api.discord.connection.DiscordConnectionDetails; import com.discordsrv.common.AbstractDiscordSRV;
import com.discordsrv.api.event.bus.EventBus;
import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.channel.ChannelConfigHelper;
import com.discordsrv.common.component.ComponentFactory;
import com.discordsrv.common.config.connection.ConnectionConfig; import com.discordsrv.common.config.connection.ConnectionConfig;
import com.discordsrv.common.config.main.MainConfig; import com.discordsrv.common.config.main.MainConfig;
import com.discordsrv.common.config.manager.ConnectionConfigManager; import com.discordsrv.common.config.manager.ConnectionConfigManager;
import com.discordsrv.common.config.manager.MainConfigManager; import com.discordsrv.common.config.manager.MainConfigManager;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.discord.api.DiscordAPIImpl; import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.discord.connection.DiscordConnectionManager;
import com.discordsrv.common.module.type.AbstractModule;
import com.discordsrv.common.module.type.Module;
import com.discordsrv.common.placeholder.PlaceholderServiceImpl;
import com.discordsrv.common.player.provider.AbstractPlayerProvider; import com.discordsrv.common.player.provider.AbstractPlayerProvider;
import com.discordsrv.common.scheduler.Scheduler; import com.discordsrv.common.scheduler.Scheduler;
import com.discordsrv.common.logging.Logger;
import net.dv8tion.jda.api.JDA;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
public class MockDiscordSRV implements DiscordSRV { public class MockDiscordSRV extends AbstractDiscordSRV<MainConfig, ConnectionConfig> {
@Override @Override
public @NotNull Status status() { public Logger platformLogger() {
return null;
}
@Override
public @NotNull EventBus eventBus() {
return null;
}
@Override
public @NotNull Optional<JDA> jda() {
return Optional.empty();
}
@Override
public @NotNull DiscordConnectionDetails discordConnectionDetails() {
return null;
}
@Override
public Logger logger() {
return null; return null;
} }
@Override @Override
public Path dataDirectory() { public Path dataDirectory() {
return Paths.get(""); return null;
} }
@Override @Override
@ -93,98 +59,18 @@ public class MockDiscordSRV implements DiscordSRV {
return null; return null;
} }
@Override
public @NotNull ComponentFactory componentFactory() {
return null;
}
@Override
public @NotNull PlaceholderServiceImpl placeholderService() {
return null;
}
@Override @Override
public @NotNull AbstractPlayerProvider<?> playerProvider() { public @NotNull AbstractPlayerProvider<?> playerProvider() {
return null; return null;
} }
@Override @Override
public @NotNull DiscordAPIImpl discordAPI() { public ConnectionConfigManager<ConnectionConfig> connectionConfigManager() {
return null; return null;
} }
@Override @Override
public ConnectionConfigManager<? extends ConnectionConfig> connectionConfigManager() { public MainConfigManager<MainConfig> configManager() {
return null;
}
@Override
public ConnectionConfig connectionConfig() {
return null;
}
@Override
public MainConfigManager<? extends MainConfig> configManager() {
return null;
}
@Override
public MainConfig config() {
return null;
}
@Override
public ChannelConfigHelper channelConfig() {
return null;
}
@Override
public DiscordConnectionManager discordConnectionManager() {
return null;
}
@Override
public <T extends Module> T getModule(Class<T> moduleType) {
return null;
}
@Override
public void registerModule(AbstractModule module) {
}
@Override
public void unregisterModule(AbstractModule module) {
}
@Override
public Locale locale() {
return null;
}
@Override
public void setStatus(Status status) {
}
@Override
public void waitForStatus(Status status, long time, TimeUnit unit) throws InterruptedException {
}
@Override
public CompletableFuture<Void> invokeEnable() {
return null;
}
@Override
public CompletableFuture<Void> invokeDisable() {
return null;
}
@Override
public CompletableFuture<Void> invokeReload() {
return null; return null;
} }
} }

View File

@ -20,7 +20,7 @@ package com.discordsrv.sponge;
import com.discordsrv.common.dependency.InitialDependencyLoader; import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import com.discordsrv.sponge.bootstrap.ISpongeBootstrap; import com.discordsrv.sponge.bootstrap.ISpongeBootstrap;
import dev.vankka.mcdependencydownload.bootstrap.AbstractBootstrap; import dev.vankka.mcdependencydownload.bootstrap.AbstractBootstrap;
import dev.vankka.mcdependencydownload.bootstrap.classpath.JarInJarClasspathAppender; import dev.vankka.mcdependencydownload.bootstrap.classpath.JarInJarClasspathAppender;

View File

@ -71,7 +71,7 @@ public class SpongeDiscordSRV extends ServerDiscordSRV<MainConfig, ConnectionCon
} }
@Override @Override
public Logger logger() { public Logger platformLogger() {
return logger; return logger;
} }

View File

@ -20,7 +20,7 @@ package com.discordsrv.sponge.console;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import com.discordsrv.sponge.SpongeDiscordSRV; import com.discordsrv.sponge.SpongeDiscordSRV;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;

View File

@ -20,7 +20,7 @@ package com.discordsrv.velocity;
import com.discordsrv.common.dependency.InitialDependencyLoader; import com.discordsrv.common.dependency.InitialDependencyLoader;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;
import com.discordsrv.common.logging.impl.SLF4JLoggerImpl; import com.discordsrv.common.logging.backend.impl.SLF4JLoggerImpl;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;

View File

@ -72,7 +72,7 @@ public class VelocityDiscordSRV extends ProxyDiscordSRV<MainConfig, ConnectionCo
} }
@Override @Override
public Logger logger() { public Logger platformLogger() {
return logger; return logger;
} }

View File

@ -20,7 +20,7 @@ package com.discordsrv.velocity.console;
import com.discordsrv.common.console.Console; import com.discordsrv.common.console.Console;
import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.LoggingBackend;
import com.discordsrv.common.logging.impl.Log4JLoggerImpl; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl;
import com.discordsrv.velocity.VelocityDiscordSRV; import com.discordsrv.velocity.VelocityDiscordSRV;
import net.kyori.adventure.identity.Identity; import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;