mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-28 17:37:52 +01:00
Ignore empty messages in message forwarding
This commit is contained in:
parent
3b02c662da
commit
7a69a805a3
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user