Skip to content

Commit

Permalink
new features in scheduling
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkyAI committed Nov 12, 2024
1 parent fb0c2f9 commit 32b896b
Show file tree
Hide file tree
Showing 3 changed files with 345 additions and 369 deletions.
12 changes: 11 additions & 1 deletion src/main/kotlin/moe/nikky/LocalTimeExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,22 @@ import kotlinx.datetime.TimeZone
import kotlinx.datetime.offsetAt
import kotlinx.datetime.toLocalDateTime
import kotlinx.serialization.Serializable
import org.koin.dsl.module
import kotlin.time.Duration
import kotlin.time.Duration.Companion.ZERO
import kotlin.time.Duration.Companion.seconds

class LocalTimeExtension : Extension(), Klogging {
override val name: String = "localtime"
init {
bot.getKoin().loadModules(
listOf(
module {
single { this@LocalTimeExtension }
}
)
)
}

private val userConfig = StorageUnit(
StorageType.Config,
Expand All @@ -40,7 +50,7 @@ class LocalTimeExtension : Extension(), Klogging {
TimezoneConfig::class
)

private fun GuildBehavior.config(userId: Snowflake) =
fun GuildBehavior.config(userId: Snowflake) =
userConfig
.withGuild(id)
.withUser(userId)
Expand Down
47 changes: 2 additions & 45 deletions src/main/kotlin/moe/nikky/RoleManagementExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,6 @@ class RoleManagementExtension : Extension(), Klogging {
event<GuildCreateEvent> {
action {
withLogContext(event, event.guild) { guild ->
migrateConfig(guild)

// val textChannels = guild.channels.filter { it is TextChannel }

Expand Down Expand Up @@ -738,7 +737,7 @@ class RoleManagementExtension : Extension(), Klogging {
}
}

val (key, roleChooserConfig) = configUnit.get()!!.find(
val (key, roleChooserConfig) = configUnit.get()?.find(
section = arguments.newSection,
channelId = channel.id
) ?: relayError("no roleselection section ${arguments.oldSection}")
Expand All @@ -752,7 +751,7 @@ class RoleManagementExtension : Extension(), Klogging {
) ?: relayError("failed to update config")
)

val (_, newRoleChooserConfig) = configUnit.get()!!.find(
val (_, newRoleChooserConfig) = configUnit.get()?.find(
section = arguments.newSection,
channelId = channel.id
) ?: relayError("no roleselection section ${arguments.newSection}")
Expand Down Expand Up @@ -867,48 +866,6 @@ class RoleManagementExtension : Extension(), Klogging {
suspend fun loadConfig(guild: GuildBehavior): RoleManagementConfig? {
return guild.config().get()
}

suspend fun migrateConfig(guild: GuildBehavior) {
// try {
// val oldConfig = StorageUnit(
// storageType = StorageType.Config,
// namespace = name,
// identifier = "role-management",
// dataType = RoleManagementConfig::class
// ).withGuild(guild).get() ?: return
//
// val newData = RoleManagementConfig(
// roleChoosers = oldConfig.roleChoosers.mapValues { (_, roleChooserConfig) ->
// roleChooserConfig.copy(
// roleMapping = roleChooserConfig.roleMapping.map { mapping ->
//
// val emoji = if(mapping.emoji.startsWith("<") && mapping.emoji.endsWith(">")) {
// val id = mapping.emoji.substringAfterLast(":").substringBefore(">")
// guild.emojis.firstOrNull { it.id.toString() == id }
// } else {
// guild.emojis.firstOrNull { it.name == mapping.emoji || it.id.toString() == mapping.emoji }
// }
// if(emoji != null) {
// mapping.copy(
// emojiName = emoji.name,
// emoji = emoji.id.toString(),
// )
// } else {
// mapping.copy(
// emojiName = mapping.emoji
// )
// }
// }
// )
// }
// )
// guild.config().save(newData)
// return
// } catch (e: Exception) {
//
// }

}
}

@Serializable
Expand Down
Loading

0 comments on commit 32b896b

Please sign in to comment.