1
0

optimize code and imports

This commit is contained in:
Jannik Reimers 2024-12-05 18:31:48 +01:00
parent 5728ac716c
commit 76f775d292
Signed by: jansel
GPG Key ID: 39C62D7D5233CFD0
6 changed files with 27 additions and 23 deletions

10
.idea/material_theme_project_new.xml generated Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="-7d6c680f:19397de9638:-7fff" />
</MTProjectMetadataState>
</option>
</component>
</project>

View File

@ -1,6 +1,3 @@
/*
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package dev.jansel.feixiao package dev.jansel.feixiao
import com.github.twitch4j.TwitchClient import com.github.twitch4j.TwitchClient
@ -8,14 +5,14 @@ import dev.jansel.feixiao.extensions.EventHooks
import dev.jansel.feixiao.extensions.StreamerCommand import dev.jansel.feixiao.extensions.StreamerCommand
import dev.jansel.feixiao.utils.database import dev.jansel.feixiao.utils.database
import dev.jansel.feixiao.utils.token import dev.jansel.feixiao.utils.token
import dev.jansel.feixiao.utils.twitch
import dev.kordex.core.ExtensibleBot import dev.kordex.core.ExtensibleBot
import dev.kordex.core.i18n.SupportedLocales import dev.kordex.core.i18n.SupportedLocales
import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.KotlinLogging
import dev.jansel.feixiao.utils.twitch
var twitchClient: TwitchClient? = null var twitchClient: TwitchClient? = null
val logger = KotlinLogging.logger { } val logger = KotlinLogging.logger { }
var botRef : ExtensibleBot? = null var botRef: ExtensibleBot? = null
suspend fun main() { suspend fun main() {
botRef = ExtensibleBot(token) { botRef = ExtensibleBot(token) {

View File

@ -6,7 +6,6 @@ import dev.jansel.feixiao.database.entities.StreamerData
import dev.kord.common.entity.Snowflake import dev.kord.common.entity.Snowflake
import dev.kordex.core.koin.KordExKoinComponent import dev.kordex.core.koin.KordExKoinComponent
import org.koin.core.component.inject import org.koin.core.component.inject
import org.litote.kmongo.elemMatch
import org.litote.kmongo.eq import org.litote.kmongo.eq
import org.litote.kmongo.setValue import org.litote.kmongo.setValue
@ -54,7 +53,7 @@ class StreamerCollection : KordExKoinComponent {
streamerName: String, streamerName: String,
roleId: Snowflake, roleId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
noOverload : Boolean = false // this is needed to avoid a conflict with the other updateData function noOverload: Boolean = false // this is needed to avoid a conflict with the other updateData function
): Int { ): Int {
val coll = collection.findOne(StreamerData::name eq streamerName) val coll = collection.findOne(StreamerData::name eq streamerName)
if (coll != null) { if (coll != null) {
@ -62,7 +61,10 @@ class StreamerCollection : KordExKoinComponent {
if (temp == null) return 1 if (temp == null) return 1
collection.updateMany( collection.updateMany(
StreamerData::name eq streamerName, StreamerData::name eq streamerName,
setValue(StreamerData::servers, coll.servers - temp + Server(guildId, temp.channelId, roleId, temp.liveMessage)) setValue(
StreamerData::servers,
coll.servers - temp + Server(guildId, temp.channelId, roleId, temp.liveMessage)
)
) )
return 0 return 0
} }
@ -87,7 +89,10 @@ class StreamerCollection : KordExKoinComponent {
if (temp == null) return 1 if (temp == null) return 1
collection.updateMany( collection.updateMany(
StreamerData::name eq streamerName, StreamerData::name eq streamerName,
setValue(StreamerData::servers, coll.servers - temp + Server(guildId, temp.channelId, temp.roleId, liveMessage)) setValue(
StreamerData::servers,
coll.servers - temp + Server(guildId, temp.channelId, temp.roleId, liveMessage)
)
) )
return 0 return 0
} }
@ -112,7 +117,10 @@ class StreamerCollection : KordExKoinComponent {
if (temp == null) return 1 if (temp == null) return 1
collection.updateMany( collection.updateMany(
StreamerData::name eq streamerName, StreamerData::name eq streamerName,
setValue(StreamerData::servers, coll.servers - temp + Server(guildId, channelId, temp.roleId, temp.liveMessage)) setValue(
StreamerData::servers,
coll.servers - temp + Server(guildId, channelId, temp.roleId, temp.liveMessage)
)
) )
return 0 return 0
} }

View File

@ -2,7 +2,6 @@ package dev.jansel.feixiao.extensions
import dev.jansel.feixiao.database.collections.StreamerCollection import dev.jansel.feixiao.database.collections.StreamerCollection
import dev.jansel.feixiao.database.entities.StreamerData import dev.jansel.feixiao.database.entities.StreamerData
import dev.jansel.feixiao.extensions.StreamerCommand.UpdateStreamerArgs
import dev.jansel.feixiao.i18n.Translations import dev.jansel.feixiao.i18n.Translations
import dev.jansel.feixiao.twitchClient import dev.jansel.feixiao.twitchClient
import dev.kord.common.entity.Permission import dev.kord.common.entity.Permission
@ -10,11 +9,7 @@ import dev.kordex.core.checks.anyGuild
import dev.kordex.core.checks.hasPermission import dev.kordex.core.checks.hasPermission
import dev.kordex.core.commands.Arguments import dev.kordex.core.commands.Arguments
import dev.kordex.core.commands.application.slash.publicSubCommand import dev.kordex.core.commands.application.slash.publicSubCommand
import dev.kordex.core.commands.converters.impl.channel import dev.kordex.core.commands.converters.impl.*
import dev.kordex.core.commands.converters.impl.optionalChannel
import dev.kordex.core.commands.converters.impl.optionalRole
import dev.kordex.core.commands.converters.impl.optionalString
import dev.kordex.core.commands.converters.impl.string
import dev.kordex.core.extensions.Extension import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.publicSlashCommand import dev.kordex.core.extensions.publicSlashCommand
import org.litote.kmongo.eq import org.litote.kmongo.eq

View File

@ -63,5 +63,4 @@ class Twitch : KordExKoinComponent {
} }
} }

View File

@ -1,17 +1,12 @@
package dev.jansel.feixiao.utils package dev.jansel.feixiao.utils
import com.github.twitch4j.TwitchClientBuilder
import com.github.twitch4j.events.ChannelGoLiveEvent
import dev.jansel.feixiao.database.Database import dev.jansel.feixiao.database.Database
import dev.jansel.feixiao.database.collections.MetaCollection import dev.jansel.feixiao.database.collections.MetaCollection
import dev.jansel.feixiao.database.collections.StreamerCollection import dev.jansel.feixiao.database.collections.StreamerCollection
import dev.jansel.feixiao.twitchClient
import dev.kord.common.entity.Snowflake import dev.kord.common.entity.Snowflake
import dev.kord.core.entity.channel.GuildMessageChannel
import dev.kordex.core.builders.ExtensibleBotBuilder import dev.kordex.core.builders.ExtensibleBotBuilder
import dev.kordex.core.utils.env import dev.kordex.core.utils.env
import dev.kordex.core.utils.loadModule import dev.kordex.core.utils.loadModule
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.koin.dsl.bind import org.koin.dsl.bind