Skip to content

Commit

Permalink
More bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 24, 2024
1 parent c04166e commit c801858
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
17 changes: 17 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public data class Poll(
public val votes: List<Vote>,
public val messages: List<Message>,
public val createdAt: Instant,
public val settings: FinalPollSettings
public val settings: FinalPollSettings,
public val excludedFromScheduling: Boolean = false
) {
/**
* All [actual options][Option.ActualOption] sorted by [Option.position].
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "2.0.21"
mikbot = "3.37.9"
mikbot = "3.37.10"
ktor = "3.0.0"

[libraries]
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/space/votebot/core/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class VoteBotModule : Extension() {

event<ReadyEvent> {
action {
//rescheduleAllPollExpires(kord)
rescheduleAllPollExpires(kord)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/space/votebot/core/VoteExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import dev.kord.core.event.interaction.GuildButtonInteractionCreateEvent
import dev.kord.x.emoji.Emojis
import dev.schlaubi.mikbot.plugin.api.util.MessageSender
import dev.schlaubi.mikbot.plugin.api.util.Translator
import dev.schlaubi.mikbot.plugin.api.util.discordError
import io.ktor.client.request.forms.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -55,6 +54,7 @@ suspend fun Poll.close(
)

if (messageUpdateFailed) {
VoteBotDatabase.polls.save(copy(excludedFromScheduling = true))
if (isRetry) {
sendMessage {
content = translate("vote.close.error.again", "votebot")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.datetime.Clock
import org.litote.kmongo.and
import org.litote.kmongo.div
import org.litote.kmongo.eq
import org.litote.kmongo.not
Expand All @@ -20,7 +21,7 @@ internal val ExpirationScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
private val expirationCache = mutableMapOf<String, Job>()

suspend fun rescheduleAllPollExpires(kord: Kord) = coroutineScope {
VoteBotDatabase.polls.find(not(Poll::settings / FinalPollSettings::deleteAfter eq null))
VoteBotDatabase.polls.find(and(not(Poll::settings / FinalPollSettings::deleteAfter eq null), Poll::excludedFromScheduling eq false))
.toFlow()
.onEach { poll ->
poll.addExpirationListener(kord)
Expand Down

0 comments on commit c801858

Please sign in to comment.