Skip to content

Commit 0556dda

Browse files
committed
Disallow attaching forms to messages not sent by the bot
1 parent d8304fd commit 0556dda

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/commands/AttachFormSubcommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.dv8tion.jda.api.components.buttons.Button;
1717
import net.dv8tion.jda.api.components.buttons.ButtonStyle;
1818
import net.dv8tion.jda.api.entities.Message;
19+
import net.dv8tion.jda.api.entities.SelfUser;
1920
import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel;
2021
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
2122
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
@@ -115,6 +116,11 @@ public void execute(SlashCommandInteractionEvent event) {
115116
});
116117

117118
msgChannel.retrieveMessageById(messageId).queue(message -> {
119+
SelfUser self = message.getJDA().getSelfUser();
120+
if (message.getAuthor().getIdLong() != self.getIdLong()) {
121+
Responses.error(event, "You can only attach forms to messages sent by " + self.getAsMention()).queue();
122+
return;
123+
}
118124
attachFormToMessage(message, buttonLabel, style, form);
119125
formsRepo.attachForm(form, msgChannel, message);
120126
event.reply("Successfully attached the form to the [message](" + message.getJumpUrl() + ")!")

0 commit comments

Comments
 (0)