Skip to content

Commit

Permalink
optimize code and imports
Browse files Browse the repository at this point in the history
  • Loading branch information
NotJansel committed Dec 5, 2024
1 parent 5728ac7 commit 76f775d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
10 changes: 10 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions src/main/kotlin/dev/jansel/feixiao/App.kt
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
/*
* This Kotlin source file was generated by the Gradle 'init' task.
*/
package dev.jansel.feixiao

import com.github.twitch4j.TwitchClient
import dev.jansel.feixiao.extensions.EventHooks
import dev.jansel.feixiao.extensions.StreamerCommand
import dev.jansel.feixiao.utils.database
import dev.jansel.feixiao.utils.token
import dev.jansel.feixiao.utils.twitch
import dev.kordex.core.ExtensibleBot
import dev.kordex.core.i18n.SupportedLocales
import io.github.oshai.kotlinlogging.KotlinLogging
import dev.jansel.feixiao.utils.twitch

var twitchClient: TwitchClient? = null
val logger = KotlinLogging.logger { }
var botRef : ExtensibleBot? = null
val logger = KotlinLogging.logger { }
var botRef: ExtensibleBot? = null

suspend fun main() {
botRef = ExtensibleBot(token) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import dev.jansel.feixiao.database.entities.StreamerData
import dev.kord.common.entity.Snowflake
import dev.kordex.core.koin.KordExKoinComponent
import org.koin.core.component.inject
import org.litote.kmongo.elemMatch
import org.litote.kmongo.eq
import org.litote.kmongo.setValue

Expand Down Expand Up @@ -54,15 +53,18 @@ class StreamerCollection : KordExKoinComponent {
streamerName: String,
roleId: 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 {
val coll = collection.findOne(StreamerData::name eq streamerName)
if (coll != null) {
val temp = coll.servers.find { server -> server.guildId == guildId }
if (temp == null) return 1
collection.updateMany(
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
}
Expand All @@ -87,7 +89,10 @@ class StreamerCollection : KordExKoinComponent {
if (temp == null) return 1
collection.updateMany(
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
}
Expand All @@ -112,7 +117,10 @@ class StreamerCollection : KordExKoinComponent {
if (temp == null) return 1
collection.updateMany(
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@ package dev.jansel.feixiao.extensions

import dev.jansel.feixiao.database.collections.StreamerCollection
import dev.jansel.feixiao.database.entities.StreamerData
import dev.jansel.feixiao.extensions.StreamerCommand.UpdateStreamerArgs
import dev.jansel.feixiao.i18n.Translations
import dev.jansel.feixiao.twitchClient
import dev.kord.common.entity.Permission
import dev.kordex.core.checks.anyGuild
import dev.kordex.core.checks.hasPermission
import dev.kordex.core.commands.Arguments
import dev.kordex.core.commands.application.slash.publicSubCommand
import dev.kordex.core.commands.converters.impl.channel
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.commands.converters.impl.*
import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.publicSlashCommand
import org.litote.kmongo.eq
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/dev/jansel/feixiao/utils/Twitch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@ class Twitch : KordExKoinComponent {
}



}
5 changes: 0 additions & 5 deletions src/main/kotlin/dev/jansel/feixiao/utils/_Utils.kt
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
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.collections.MetaCollection
import dev.jansel.feixiao.database.collections.StreamerCollection
import dev.jansel.feixiao.twitchClient
import dev.kord.common.entity.Snowflake
import dev.kord.core.entity.channel.GuildMessageChannel
import dev.kordex.core.builders.ExtensibleBotBuilder
import dev.kordex.core.utils.env
import dev.kordex.core.utils.loadModule
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.koin.dsl.bind

Expand Down

0 comments on commit 76f775d

Please sign in to comment.