Ignore empty messages in message forwarding

This commit is contained in:
Vankka 2023-10-15 23:58:20 +03:00
parent 3b02c662da
commit 7a69a805a3
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
4 changed files with 21 additions and 2 deletions

View File

@ -141,6 +141,12 @@ public interface SendableDiscordMessage {
*/
SendableDiscordMessage withReplyingToMessageId(Long replyingToMessageId);
/**
* Checks if this message has any sendable content.
* @return {@code true} if there is no sendable content
*/
boolean isEmpty();
@SuppressWarnings("UnusedReturnValue") // API
interface Builder {

View File

@ -95,6 +95,11 @@ public class SendableDiscordMessageImpl implements SendableDiscordMessage {
);
}
@Override
public boolean isEmpty() {
return (content == null || content.isEmpty()) && embeds.isEmpty() && attachments.isEmpty() && actionRows.isEmpty();
}
@Override
public @Nullable String getContent() {
return content;

View File

@ -190,8 +190,13 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
message.replaceAll(ASCII_CONTROL_FILTER, "");
chatConfig.contentRegexFilters.forEach(message::replaceAll);
String finalMessage = message.toString();
if (StringUtils.isEmpty(finalMessage)) {
return;
}
Component messageComponent = DiscordSRVMinecraftRenderer.getWithContext(guild, chatConfig, () ->
discordSRV.componentFactory().minecraftSerializer().serialize(message.toString()));
discordSRV.componentFactory().minecraftSerializer().serialize(finalMessage));
GameTextBuilder componentBuilder = discordSRV.componentFactory()
.textBuilder(format)

View File

@ -107,7 +107,7 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
return discordSRV.discordAPI().findOrCreateDestinations(channelConfig, true, true).thenCompose(messageChannels -> {
SendableDiscordMessage.Builder format = moduleConfig.format();
if (format == null) {
if (format == null || format.isEmpty()) {
return CompletableFuture.completedFuture(null);
}
@ -178,6 +178,9 @@ public abstract class AbstractGameMessageModule<T extends IMessageConfig, E exte
SendableDiscordMessage discordMessage = formatter
.build();
if (discordMessage.isEmpty()) {
return Collections.emptyMap();
}
Map<CompletableFuture<ReceivedDiscordMessage>, DiscordGuildMessageChannel> futures = new LinkedHashMap<>();
for (DiscordGuildMessageChannel channel : channels) {