Skip to content

Commit

Permalink
Removed scheduler message deletion
Browse files Browse the repository at this point in the history
Are inaccurate and can cause crashes.
Todo: Find a better system for messages with a timed autodeletion.
  • Loading branch information
russellbanks committed Apr 14, 2022
1 parent f12ab42 commit ae4a44b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,24 @@ package extensions.joinleaveupdate

import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.event
import com.kotlindiscord.kord.extensions.utils.scheduling.Scheduler
import data.Database
import dev.kord.common.entity.ChannelType
import dev.kord.core.behavior.channel.MessageChannelBehavior
import dev.kord.core.event.guild.GuildCreateEvent
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlin.time.Duration.Companion.days

class NewGuildExtension: Extension() {

override val name = "new-guild"

override suspend fun setup() {
event<GuildCreateEvent> {
action {
if (Database.isNewGuild(event.guild)) {
Database.createGuild(event.guild)
val topTextChannel = event.guild.channels.filter { it.type == ChannelType.GuildText }.first()
Database.updateChannel(event.guild, topTextChannel)
val joinMessage = MessageChannelBehavior(topTextChannel.id, kord).createMessage("Thanks for inviting me! For now, I have set ${topTextChannel.mention} as the text channel for voice state notifications. This can be configured with `/configure channel`.")
Scheduler().schedule(7.days) { joinMessage.delete() }
MessageChannelBehavior(topTextChannel.id, kord).createMessage("Thanks for inviting me! For now, I have set ${topTextChannel.mention} as the text channel for voice state notifications. This can be configured with `/configure channel`.")
}
}
}
Expand Down
14 changes: 2 additions & 12 deletions src/main/kotlin/extensions/notify/NotifyChatExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import com.kotlindiscord.kord.extensions.checks.isNotBot
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.chatGroupCommand
import com.kotlindiscord.kord.extensions.utils.respond
import com.kotlindiscord.kord.extensions.utils.scheduling.Scheduler
import dev.kord.common.entity.Permission
import kotlin.time.Duration.Companion.hours

class NotifyChatExtension: Extension() {
override val name = "notify-chat"
Expand All @@ -25,13 +23,9 @@ class NotifyChatExtension: Extension() {
description = "Notify everyone online"

action {
val notifyMessage = message.respond {
message.respond {
content = member?.let { NotifyReply.getNotifyReply(it, NotifyTarget.HERE) }
}
Scheduler().schedule(5.hours) {
message.delete()
notifyMessage.delete()
}
}
}

Expand All @@ -40,13 +34,9 @@ class NotifyChatExtension: Extension() {
description = "Notify everyone"

action {
val notifyMessage = message.respond {
message.respond {
content = member?.let { NotifyReply.getNotifyReply(it, NotifyTarget.EVERYONE) }
}
Scheduler().schedule(5.hours) {
message.delete()
notifyMessage.delete()
}
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/extensions/notify/NotifyEphemeralExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ import com.kotlindiscord.kord.extensions.modules.unsafe.types.ackEphemeral
import com.kotlindiscord.kord.extensions.modules.unsafe.types.ackPublic
import com.kotlindiscord.kord.extensions.modules.unsafe.types.respondEphemeral
import com.kotlindiscord.kord.extensions.modules.unsafe.types.respondPublic
import com.kotlindiscord.kord.extensions.utils.scheduling.Scheduler
import dev.kord.common.entity.Permission
import kotlin.time.Duration.Companion.hours

class NotifyEphemeralExtension: Extension() {
override val name = "notify-ephemeral"
Expand Down

0 comments on commit ae4a44b

Please sign in to comment.