|
| 1 | +package net.javadiscord.javabot.systems.qotw; |
| 2 | + |
| 3 | +import net.dv8tion.jda.api.JDA; |
| 4 | +import net.dv8tion.jda.api.entities.Guild; |
| 5 | +import net.dv8tion.jda.api.entities.TextChannel; |
| 6 | +import net.javadiscord.javabot.Bot; |
| 7 | +import net.javadiscord.javabot.data.config.guild.QOTWConfig; |
| 8 | +import net.javadiscord.javabot.systems.qotw.submissions.SubmissionManager; |
| 9 | +import net.javadiscord.javabot.systems.qotw.submissions.model.QOTWSubmission; |
| 10 | +import net.javadiscord.javabot.systems.user_preferences.UserPreferenceManager; |
| 11 | +import net.javadiscord.javabot.systems.user_preferences.model.Preference; |
| 12 | +import net.javadiscord.javabot.systems.user_preferences.model.UserPreference; |
| 13 | +import net.javadiscord.javabot.tasks.jobs.DiscordApiJob; |
| 14 | +import org.jetbrains.annotations.NotNull; |
| 15 | +import org.quartz.JobExecutionContext; |
| 16 | +import org.quartz.JobExecutionException; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +/** |
| 21 | + * Checks that there's a question in the QOTW queue ready for posting soon. |
| 22 | + */ |
| 23 | +public class QOTWUserReminderJob extends DiscordApiJob { |
| 24 | + @Override |
| 25 | + protected void execute(JobExecutionContext context, @NotNull JDA jda) throws JobExecutionException { |
| 26 | + for (Guild guild : jda.getGuilds()) { |
| 27 | + QOTWConfig config = Bot.getConfig().get(guild).getQotwConfig(); |
| 28 | + List<QOTWSubmission> submissions = new SubmissionManager(config).getActiveSubmissionThreads(); |
| 29 | + for (QOTWSubmission submission : submissions) { |
| 30 | + UserPreferenceManager manager = new UserPreferenceManager(Bot.getDataSource()); |
| 31 | + UserPreference preference = manager.getOrCreate(submission.getAuthorId(), Preference.QOTW_REMINDER); |
| 32 | + if (preference.isEnabled()) { |
| 33 | + TextChannel channel = config.getSubmissionChannel(); |
| 34 | + channel.getThreadChannels().stream().filter(t -> t.getIdLong() == submission.getThreadId()).forEach(t -> { |
| 35 | + if (t.getMessageCount() <= 1) { |
| 36 | + t.sendMessageFormat("**Question of the Week Reminder**\nHey <@%s>! You still have some time left to submit your answer!", submission.getAuthorId()) |
| 37 | + .queue(); |
| 38 | + } |
| 39 | + }); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | +} |
0 commit comments