|
| 1 | +package net.javadiscord.javabot.listener; |
| 2 | + |
| 3 | +import lombok.RequiredArgsConstructor; |
| 4 | +import net.dv8tion.jda.api.entities.channel.ChannelType; |
| 5 | +import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; |
| 6 | +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
| 7 | +import net.dv8tion.jda.api.hooks.ListenerAdapter; |
| 8 | +import net.dv8tion.jda.api.interactions.components.buttons.Button; |
| 9 | +import net.javadiscord.javabot.data.config.BotConfig; |
| 10 | +import net.javadiscord.javabot.data.config.guild.QOTWConfig; |
| 11 | +import net.javadiscord.javabot.util.InteractionUtils; |
| 12 | +import org.jetbrains.annotations.NotNull; |
| 13 | + |
| 14 | +/** |
| 15 | + * Listens for new messages inside QOTW submissions and warns the author about the webhook limitations. |
| 16 | + */ |
| 17 | +@RequiredArgsConstructor |
| 18 | +public class QOTWSubmissionListener extends ListenerAdapter { |
| 19 | + private final BotConfig config; |
| 20 | + |
| 21 | + @Override |
| 22 | + public void onMessageReceived(@NotNull MessageReceivedEvent event) { |
| 23 | + if (!event.isFromGuild() || !event.isFromThread() || event.getChannelType() != ChannelType.GUILD_PRIVATE_THREAD) { |
| 24 | + return; |
| 25 | + } |
| 26 | + QOTWConfig qotwConfig = config.get(event.getGuild()).getQotwConfig(); |
| 27 | + ThreadChannel thread = event.getChannel().asThreadChannel(); |
| 28 | + if (thread.getParentChannel().getIdLong() != qotwConfig.getSubmissionChannelId()) { |
| 29 | + return; |
| 30 | + } |
| 31 | + if (event.getMessage().getContentRaw().length() > 2000) { |
| 32 | + event.getChannel().sendMessageFormat(""" |
| 33 | + Hey %s! |
| 34 | + Please keep in mind that messages **over 2000 characters** get split in half due to webhook limitations. |
| 35 | + If you want to make sure that your submission is properly formatted, split your message into smaller chunks instead.""", |
| 36 | + event.getAuthor().getAsMention()) |
| 37 | + .setActionRow(Button.secondary(InteractionUtils.DELETE_ORIGINAL_TEMPLATE, "\uD83D\uDDD1️")) |
| 38 | + .queue(); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
0 commit comments