Skip to content

Commit

Permalink
Revert "Hopefully fix access error in startup thread startup hook"
Browse files Browse the repository at this point in the history
This reverts commit 33a359b.
  • Loading branch information
NoComment1105 committed Jun 4, 2022
1 parent fb4b56b commit 01b9cc2
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/main/kotlin/net/irisshaders/lilybot/utils/DatabaseHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package net.irisshaders.lilybot.utils

import dev.kord.common.entity.Snowflake
import dev.kord.core.Kord
import dev.kord.core.entity.Message
import dev.kord.core.entity.channel.thread.TextChannelThread
import dev.kord.rest.request.KtorRequestException
import kotlinx.coroutines.runBlocking
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
Expand Down Expand Up @@ -300,15 +298,9 @@ object DatabaseHelper {
val collection = database.getCollection<ThreadData>()
val threads = collection.find().toList()
var deletedThreads = 0
for (it in threads) {
val thread: TextChannelThread
val latestMessage: Message
try {
thread = kordInstance.getChannel(it.threadId) as TextChannelThread? ?: continue
latestMessage = thread.getLastMessage() ?: continue
} catch (e: KtorRequestException) {
continue
}
threads.forEach {
val thread = kordInstance.getChannel(it.threadId) as TextChannelThread? ?: return@forEach
val latestMessage = thread.getLastMessage() ?: return@forEach
val timeSinceLatestMessage = Clock.System.now() - latestMessage.id.timestamp
if (timeSinceLatestMessage.inWholeDays > 7) {
collection.deleteOne(ThreadData::threadId eq thread.id)
Expand Down

0 comments on commit 01b9cc2

Please sign in to comment.