1
0

reformat code and optimize imports (IntelliJ internal function)

This commit is contained in:
Jannik Reimers 2024-11-27 23:38:04 +01:00
parent fce192d295
commit 20da6a5dda
Signed by: jansel
GPG Key ID: 39C62D7D5233CFD0
4 changed files with 41 additions and 17 deletions

View File

@ -10,7 +10,10 @@ import com.github.twitch4j.events.ChannelGoLiveEvent
import dev.jansel.feixiao.database.collections.StreamerCollection import dev.jansel.feixiao.database.collections.StreamerCollection
import dev.jansel.feixiao.extensions.EventHooks import dev.jansel.feixiao.extensions.EventHooks
import dev.jansel.feixiao.extensions.StreamerCommand import dev.jansel.feixiao.extensions.StreamerCommand
import dev.jansel.feixiao.utils.* import dev.jansel.feixiao.utils.database
import dev.jansel.feixiao.utils.token
import dev.jansel.feixiao.utils.twitchcid
import dev.jansel.feixiao.utils.twitchcs
import dev.kord.core.entity.channel.GuildMessageChannel import dev.kord.core.entity.channel.GuildMessageChannel
import dev.kordex.core.ExtensibleBot import dev.kordex.core.ExtensibleBot
import dev.kordex.core.i18n.SupportedLocales import dev.kordex.core.i18n.SupportedLocales
@ -19,7 +22,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
var twitchClient: TwitchClient? = null var twitchClient: TwitchClient? = null
val logger = KotlinLogging.logger { } val logger = KotlinLogging.logger { }
suspend fun main() { suspend fun main() {
val bot = ExtensibleBot(token) { val bot = ExtensibleBot(token) {
@ -51,22 +54,26 @@ suspend fun main() {
if (role != null) { if (role != null) {
if (livemessage != null) { if (livemessage != null) {
channel?.createMessage(livemessage channel?.createMessage(
.replace("{name}", it.channel.name) livemessage
.replace("{category}", it.stream.gameName) .replace("{name}", it.channel.name)
.replace("{title}", it.stream.title) .replace("{category}", it.stream.gameName)
.replace("{url}", "https://twitch.tv/${it.channel.name}") .replace("{title}", it.stream.title)
.replace("{role}", "<@&$role>")) .replace("{url}", "https://twitch.tv/${it.channel.name}")
.replace("{role}", "<@&$role>")
)
} else { } else {
channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}")
} }
} else { } else {
if (livemessage != null) { if (livemessage != null) {
channel?.createMessage(livemessage channel?.createMessage(
.replace("{name}", it.channel.name) livemessage
.replace("{category}", it.stream.gameName) .replace("{name}", it.channel.name)
.replace("{title}", it.stream.title) .replace("{category}", it.stream.gameName)
.replace("{url}", "https://twitch.tv/${it.channel.name}")) .replace("{title}", it.stream.title)
.replace("{url}", "https://twitch.tv/${it.channel.name}")
)
} else { } else {
channel?.createMessage("https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}") channel?.createMessage("https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}")
} }

View File

@ -20,7 +20,13 @@ class StreamerCollection : KordExKoinComponent {
suspend fun getData(channelName: String): StreamerData? = suspend fun getData(channelName: String): StreamerData? =
collection.findOne(StreamerData::name eq channelName) collection.findOne(StreamerData::name eq channelName)
suspend fun updateData(guildId: Snowflake, channelId: Snowflake, streamerName: String, roleId: Snowflake?, liveMessage: String?) { suspend fun updateData(
guildId: Snowflake,
channelId: Snowflake,
streamerName: String,
roleId: Snowflake?,
liveMessage: String?
) {
val coll = collection.findOne(StreamerData::name eq streamerName) val coll = collection.findOne(StreamerData::name eq streamerName)
if (coll != null) { if (coll != null) {
collection.updateOne( collection.updateOne(
@ -34,7 +40,13 @@ class StreamerCollection : KordExKoinComponent {
} }
} }
suspend fun removeData(guildId: Snowflake, channelId: Snowflake, streamerName: String, roleId: Snowflake?, liveMessage: String?) { suspend fun removeData(
guildId: Snowflake,
channelId: Snowflake,
streamerName: String,
roleId: Snowflake?,
liveMessage: String?
) {
val coll = collection.findOne(StreamerData::name eq streamerName) val coll = collection.findOne(StreamerData::name eq streamerName)
if (coll != null) { if (coll != null) {
collection.updateOne( collection.updateOne(

View File

@ -7,7 +7,6 @@ import dev.jansel.feixiao.twitchClient
import dev.kord.core.event.gateway.ReadyEvent import dev.kord.core.event.gateway.ReadyEvent
import dev.kordex.core.extensions.Extension import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.event import dev.kordex.core.extensions.event
import org.litote.kmongo.deleteMany
import org.litote.kmongo.eq import org.litote.kmongo.eq
class EventHooks : Extension() { class EventHooks : Extension() {

View File

@ -31,7 +31,13 @@ class StreamerCommand : Extension() {
} }
action { action {
val streamer = arguments.streamer val streamer = arguments.streamer
StreamerCollection().updateData(guild!!.id, arguments.channel.id, streamer, arguments.role?.id, arguments.message) StreamerCollection().updateData(
guild!!.id,
arguments.channel.id,
streamer,
arguments.role?.id,
arguments.message
)
twitchClient!!.clientHelper.enableStreamEventListener(streamer) twitchClient!!.clientHelper.enableStreamEventListener(streamer)
respond { respond {
content = "Added streamer $streamer" content = "Added streamer $streamer"