Skip to content

Commit 7b79463

Browse files
authored
Merge pull request #529 from danthe1st/restrict-default-mentions
reduce default mentionable entities set
2 parents 16464c3 + 750d35a commit 7b79463

File tree

9 files changed

+14
-12
lines changed

9 files changed

+14
-12
lines changed

src/main/java/net/discordjug/javabot/Bot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void onApplicationEvent(ApplicationReadyEvent event) {
101101
*/
102102
public static void main(String[] args) throws Exception {
103103
TimeZone.setDefault(TimeZone.getTimeZone(ZoneOffset.UTC));
104-
MessageRequest.setDefaultMentions(EnumSet.of(Message.MentionType.ROLE, Message.MentionType.CHANNEL, Message.MentionType.USER, Message.MentionType.EMOJI));
104+
MessageRequest.setDefaultMentions(EnumSet.of(Message.MentionType.CHANNEL, Message.MentionType.USER, Message.MentionType.EMOJI));
105105
SpringApplication.run(Bot.class, args);
106106
}
107107

src/main/java/net/discordjug/javabot/systems/moderation/report/ReportManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ private void createReportThread(Message message, long targetId, ModerationConfig
261261
message.createThreadChannel(message.getEmbeds().get(0).getTitle()).queue(
262262
thread -> {
263263
thread.sendMessage(config.getStaffRole().getAsMention())
264+
.mention(config.getStaffRole())
264265
.setComponents(setComponents(targetId, thread.getIdLong()))
265266
.queue();
266267
onSuccess.accept(thread);

src/main/java/net/discordjug/javabot/systems/moderation/server_lock/ServerLockManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public void lockServer(Guild guild, @NotNull Collection<Member> potentialRaiders
257257
config.getModerationConfig().getStaffRole().getAsMention(),
258258
potentialRaiders.size(),
259259
membersString
260-
));
260+
).mention(config.getModerationConfig().getStaffRole()));
261261
} else {
262262
notification.sendToModerationLog(c -> c.sendMessage("Server locked by " + lockedBy.getAsMention()));
263263
}

src/main/java/net/discordjug/javabot/systems/qotw/commands/questions_queue/ListQuestionsSubcommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import net.discordjug.javabot.util.Responses;
77
import net.discordjug.javabot.util.UserUtils;
88
import net.dv8tion.jda.api.EmbedBuilder;
9+
import net.dv8tion.jda.api.entities.UserSnowflake;
910
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
1011
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
1112
import net.dv8tion.jda.api.interactions.commands.OptionType;
@@ -67,7 +68,7 @@ protected InteractionCallbackAction<?> handleCommand(@NotNull SlashCommandIntera
6768
"> %s\nPriority: **%d**\nCreated by: %s\nCreated at: <t:%s:D>",
6869
question.getText(),
6970
question.getPriority(),
70-
event.getJDA().retrieveUserById(question.getCreatedBy()).complete().getAsMention(),
71+
UserSnowflake.fromId(question.getCreatedBy()).getAsMention(),
7172
question.getCreatedAt().toEpochSecond(ZoneOffset.UTC)
7273
),
7374
false

src/main/java/net/discordjug/javabot/systems/qotw/jobs/QOTWCloseSubmissionsJob.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ private void sendReviewInformation(Guild guild, QOTWConfig qotwConfig, TextChann
117117
.sendMessageFormat("%s%nIt's review time! There are **%s** threads to review",
118118
qotwConfig.getQOTWReviewRole().getAsMention(),
119119
qotwConfig.getSubmissionChannel().getThreadChannels().size())
120+
.mention(qotwConfig.getQOTWReviewRole())
120121
.flatMap(msg -> msg.createThreadChannel("QOTW review"))
121122
.queue(thread -> {
122123
for (ThreadChannel submission : qotwConfig.getSubmissionChannel().getThreadChannels()) {

src/main/java/net/discordjug/javabot/systems/qotw/jobs/QOTWJob.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void execute() throws SQLException {
4949
}
5050
Optional<QOTWQuestion> nextQuestion = questionQueueRepository.getNextQuestion(guild.getIdLong());
5151
if (nextQuestion.isEmpty()) {
52-
notificationService.withGuild(guild).sendToModerationLog(m -> m.sendMessageFormat("Warning! %s No available next question for QOTW!", config.getQotwConfig().getQOTWReviewRole().getAsMention()));
52+
notificationService.withGuild(guild).sendToModerationLog(m -> m.sendMessageFormat("Warning! %s No available next question for QOTW!", config.getQotwConfig().getQOTWReviewRole().getAsMention()).mention(config.getQotwConfig().getQOTWReviewRole()));
5353
} else {
5454
QOTWQuestion question = nextQuestion.get();
5555
QOTWConfig qotw = config.getQotwConfig();
@@ -70,6 +70,7 @@ public void execute() throws SQLException {
7070
NewsChannel questionChannel = qotw.getQuestionChannel();
7171
if (questionChannel != null) {
7272
questionChannel.sendMessage(qotw.getQOTWRole().getAsMention())
73+
.mention(qotw.getQOTWRole())
7374
.setEmbeds(this.buildQuestionEmbed(question))
7475
.setComponents(ActionRow.of(Button.success("qotw-submission:submit:" + question.getQuestionNumber(), "Submit your Answer")))
7576
.queue(msg -> questionChannel.crosspostMessageById(msg.getIdLong()).queue());

src/main/java/net/discordjug/javabot/systems/qotw/jobs/QOTWReminderJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void execute() throws SQLException {
3939
if (q.isEmpty()) {
4040
notificationService.withGuild(guild).sendToModerationLog(m -> m.sendMessageFormat(
4141
"Warning! %s There's no Question of the Week in the queue. Please add one before it's time to post!",
42-
config.getQOTWReviewRole().getAsMention()));
42+
config.getQOTWReviewRole().getAsMention()).mention(config.getQOTWReviewRole()));
4343
}
4444
}
4545
}

src/main/java/net/discordjug/javabot/systems/qotw/jobs/QOTWReviewReminderJob.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
import net.discordjug.javabot.systems.notification.NotificationService;
77
import net.dv8tion.jda.api.JDA;
88
import net.dv8tion.jda.api.entities.Guild;
9-
import net.dv8tion.jda.api.entities.Message;
10-
11-
import java.util.EnumSet;
129

1310
import org.springframework.scheduling.annotation.Scheduled;
1411
import org.springframework.stereotype.Service;
@@ -40,7 +37,7 @@ public void execute() {
4037
channel
4138
.sendMessageFormat("%s\n**Reminder**\nThe QOTW has not been reviewed yet.",
4239
guildConfig.getQotwConfig().getQOTWReviewRole().getAsMention())
43-
.setAllowedMentions(EnumSet.of(Message.MentionType.ROLE))
40+
.mention(guildConfig.getQotwConfig().getQOTWReviewRole())
4441
);
4542
}
4643
}

src/main/java/net/discordjug/javabot/util/Responses.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.Color;
44
import java.time.Instant;
55
import java.util.Arrays;
6+
import java.util.List;
67
import java.util.stream.Collectors;
78

89
import javax.annotation.CheckReturnValue;
@@ -120,17 +121,17 @@ private Responses() {
120121

121122
@CheckReturnValue
122123
public static @NotNull ReplyCallbackAction replyCannotInteract(IReplyCallback event, @NotNull IMentionable mentionable) {
123-
return error(event, "I am missing permissions in order to interact with that. (%s)", mentionable.getAsMention());
124+
return error(event, "I am missing permissions in order to interact with that. (%s)", mentionable.getAsMention()).setAllowedMentions(List.of());
124125
}
125126

126127
@CheckReturnValue
127128
public static @NotNull ReplyCallbackAction replyStaffOnly(IReplyCallback event, GuildConfig guildConfig) {
128-
return error(event, "This command may only be used by staff members. (%s)", guildConfig.getModerationConfig().getStaffRole().getAsMention());
129+
return error(event, "This command may only be used by staff members. (%s)", guildConfig.getModerationConfig().getStaffRole().getAsMention()).setAllowedMentions(List.of());
129130
}
130131

131132
@CheckReturnValue
132133
public static @NotNull ReplyCallbackAction replyAdminOnly(IReplyCallback event, GuildConfig guildConfig) {
133-
return error(event, "This command may only be used by admins. (%s)", guildConfig.getModerationConfig().getAdminRole().getAsMention());
134+
return error(event, "This command may only be used by admins. (%s)", guildConfig.getModerationConfig().getAdminRole().getAsMention()).setAllowedMentions(List.of());
134135
}
135136

136137
/**

0 commit comments

Comments
 (0)