manusaurio / sheska

MIT License
0 stars 0 forks source link

use enumEntries() (Kotlin >= 1.9) #71

Closed github-actions[bot] closed 11 months ago

github-actions[bot] commented 11 months ago

https://github.com/manusaurio/sheska/blob/56834a269be8fce56ead8287149e40f264a3c48a/src/main/kotlin/ar/pelotude/ohhsugoi/bot/UtilsExtension.kt#L79


import com.kotlindiscord.kord.extensions.commands.application.slash.ephemeralSubCommand
import com.kotlindiscord.kord.extensions.commands.application.slash.publicSubCommand
import com.kotlindiscord.kord.extensions.commands.converters.impl.long
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalBoolean
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalLong
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalRole
import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalString
import com.kotlindiscord.kord.extensions.commands.converters.impl.role
import com.kotlindiscord.kord.extensions.commands.converters.impl.string
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import com.kotlindiscord.kord.extensions.extensions.Extension
import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand
import com.kotlindiscord.kord.extensions.extensions.event
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import com.kotlindiscord.kord.extensions.types.respond
import com.kotlindiscord.kord.extensions.types.respondingPaginator
import dev.kord.common.entity.ButtonStyle
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.behavior.edit
import dev.kord.core.behavior.interaction.respondEphemeral
import dev.kord.core.behavior.interaction.response.respond
import dev.kord.core.behavior.interaction.suggestString
import dev.kord.core.behavior.interaction.updateEphemeralMessage
import dev.kord.core.entity.Guild
import dev.kord.core.entity.channel.TextChannel
import dev.kord.core.entity.interaction.AutoCompleteInteraction
import dev.kord.core.event.interaction.AutoCompleteInteractionCreateEvent
import dev.kord.core.event.interaction.GuildButtonInteractionCreateEvent
import dev.kord.core.exception.EntityNotFoundException
import dev.kord.core.kordLogger
import dev.kord.rest.builder.message.create.actionRow
import dev.kord.rest.builder.message.create.embed
import dev.kord.rest.request.RestRequestException
import io.ktor.client.request.forms.*
import io.ktor.utils.io.*
import io.ktor.utils.io.jvm.javaio.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.withContext
import org.koin.core.component.get
import org.koin.core.component.inject
import org.koin.core.qualifier.named
import java.time.Instant
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.*

enum class InteractionIDType(val prefix: String) {
    POLL_VOTE_OPTION("p-vo#"),
    POLL_FINISH_POLL_MENU("p-fpm#"),
    POLL_FINISH_POLL_QUIETLY("p-fpq#"),
    POLL_FINISH_POLL_LOUDLY("p-fpl#");

    fun preppendTo(str: String) = "$prefix$str"

    companion object {
        fun takeFromStringOrNull(str: String): InteractionIDType? {
            // TODO: use enumEntries() (Kotlin >= 1.9)
            return values().find {
                str.startsWith(it.prefix)
            }
        }

        fun removeFromString(str: String) = str.substringAfter('#')
    }
}

class UtilsExtension<T : Any> : Extension(), KordExKoinComponent, SchedulerEventHandler<T> {
    override val name = "utils"

    private val db: MangaDatabase by inject()
    private val pollsDb: PollsDatabase by inject()

    private val scheduler: Scheduler<T> = get<Scheduler<T>>().apply { subscribe(this@UtilsExtension) }
    private val usersDatabase: UsersDatabase by inject()
github-actions[bot] commented 11 months ago

Closed in cb047e58d3a89838e17ba279f722a94183c36325