|
| 1 | +package net.javadiscord.javabot.systems.qotw.jobs; |
| 2 | + |
| 3 | +import lombok.RequiredArgsConstructor; |
| 4 | +import net.dv8tion.jda.api.JDA; |
| 5 | +import net.dv8tion.jda.api.entities.Guild; |
| 6 | +import net.dv8tion.jda.api.entities.Message; |
| 7 | +import net.javadiscord.javabot.data.config.BotConfig; |
| 8 | +import net.javadiscord.javabot.data.config.GuildConfig; |
| 9 | +import net.javadiscord.javabot.systems.notification.NotificationService; |
| 10 | + |
| 11 | +import java.util.EnumSet; |
| 12 | + |
| 13 | +import org.springframework.scheduling.annotation.Scheduled; |
| 14 | +import org.springframework.stereotype.Service; |
| 15 | + |
| 16 | +/** |
| 17 | + * Job which reminds reviewers to review QOTW if this has not been done already. |
| 18 | + */ |
| 19 | +@Service |
| 20 | +@RequiredArgsConstructor |
| 21 | +public class QOTWReviewReminderJob { |
| 22 | + private final JDA jda; |
| 23 | + private final NotificationService notificationService; |
| 24 | + private final BotConfig botConfig; |
| 25 | + |
| 26 | + /** |
| 27 | + * Reminds reviewers to review QOTW if this has not been done already. |
| 28 | + */ |
| 29 | + @Scheduled(cron = "0 0 7 * * 1") // Monday, 07:00 UTC |
| 30 | + public void execute() { |
| 31 | + for (Guild guild : jda.getGuilds()) { |
| 32 | + GuildConfig guildConfig = botConfig.get(guild); |
| 33 | + if (guildConfig.getModerationConfig().getLogChannel() == null || guildConfig.getQotwConfig().getSubmissionChannel()==null) { |
| 34 | + continue; |
| 35 | + } |
| 36 | + if (!guildConfig.getQotwConfig().getSubmissionChannel().getThreadChannels().isEmpty()) { |
| 37 | + notificationService |
| 38 | + .withGuild(guild) |
| 39 | + .sendToModerationLog(channel -> |
| 40 | + channel |
| 41 | + .sendMessageFormat("%s\n**Reminder**\nThe QOTW has not been reviewed yet.", |
| 42 | + guildConfig.getQotwConfig().getQOTWReviewRole().getAsMention()) |
| 43 | + .setAllowedMentions(EnumSet.of(Message.MentionType.ROLE)) |
| 44 | + ); |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments