Make trivia loop through all questions
This commit is contained in:
@@ -10,6 +10,7 @@ import net.dv8tion.jda.api.requests.RestAction;
|
||||
import wtf.beatrice.hidekobot.Cache;
|
||||
import wtf.beatrice.hidekobot.HidekoBot;
|
||||
import wtf.beatrice.hidekobot.datasources.DatabaseSource;
|
||||
import wtf.beatrice.hidekobot.util.CommandUtil;
|
||||
import wtf.beatrice.hidekobot.util.Logger;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -63,93 +64,9 @@ public class ExpiredMessageTask implements Runnable {
|
||||
if(now.isAfter(expiryDate))
|
||||
{
|
||||
if(Cache.isVerbose()) logger.log("expired: " + messageId);
|
||||
disableExpired(messageId);
|
||||
CommandUtil.disableExpired(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void disableExpired(String messageId)
|
||||
{
|
||||
String channelId = databaseSource.getQueuedExpiringMessageChannel(messageId);
|
||||
|
||||
// todo: warning, the following method + related if check are thread-locking.
|
||||
// todo: we should probably merge the two tables somehow, since they have redundant information.
|
||||
ChannelType msgChannelType = databaseSource.getTrackedMessageChannelType(messageId);
|
||||
|
||||
MessageChannel textChannel = null;
|
||||
|
||||
// this should never happen, but only message channels are supported.
|
||||
if(!msgChannelType.isMessage())
|
||||
{
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
return;
|
||||
}
|
||||
|
||||
// if this is a DM
|
||||
if(!(msgChannelType.isGuild()))
|
||||
{
|
||||
String userId = databaseSource.getTrackedReplyUserId(messageId);
|
||||
User user = userId == null ? null : HidekoBot.getAPI().retrieveUserById(userId).complete();
|
||||
if(user == null)
|
||||
{
|
||||
// if user is not found, consider it expired
|
||||
// (deleted profile, or blocked the bot)
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
return;
|
||||
}
|
||||
|
||||
textChannel = user.openPrivateChannel().complete();
|
||||
}
|
||||
else
|
||||
{
|
||||
String guildId = databaseSource.getQueuedExpiringMessageGuild(messageId);
|
||||
Guild guild = guildId == null ? null : HidekoBot.getAPI().getGuildById(guildId);
|
||||
if(guild == null)
|
||||
{
|
||||
// if guild is not found, consider it expired
|
||||
// (server was deleted or bot was kicked)
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
return;
|
||||
}
|
||||
textChannel = guild.getTextChannelById(channelId);
|
||||
}
|
||||
|
||||
if(textChannel == null)
|
||||
{
|
||||
// if channel is not found, count it as expired
|
||||
// (channel was deleted or bot permissions restricted)
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
return;
|
||||
}
|
||||
|
||||
RestAction<Message> retrieveAction = textChannel.retrieveMessageById(messageId);
|
||||
|
||||
|
||||
if(Cache.isVerbose()) logger.log("cleaning up: " + messageId);
|
||||
|
||||
retrieveAction.queue(
|
||||
message -> {
|
||||
if(message == null)
|
||||
{
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
return;
|
||||
}
|
||||
|
||||
List<LayoutComponent> components = message.getComponents();
|
||||
List<LayoutComponent> newComponents = new ArrayList<>();
|
||||
for (LayoutComponent component : components)
|
||||
{
|
||||
component = component.asDisabled();
|
||||
newComponents.add(component);
|
||||
}
|
||||
|
||||
message.editMessageComponents(newComponents).queue();
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
},
|
||||
|
||||
(error) -> {
|
||||
databaseSource.untrackExpiredMessage(messageId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user