Skip to content

Commit

Permalink
reformat code and optimize imports (IntelliJ internal function)
Browse files Browse the repository at this point in the history
  • Loading branch information
NotJansel committed Nov 27, 2024
1 parent fce192d commit 20da6a5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 17 deletions.
33 changes: 20 additions & 13 deletions src/main/kotlin/dev/jansel/feixiao/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import com.github.twitch4j.events.ChannelGoLiveEvent
import dev.jansel.feixiao.database.collections.StreamerCollection
import dev.jansel.feixiao.extensions.EventHooks
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.kordex.core.ExtensibleBot
import dev.kordex.core.i18n.SupportedLocales
Expand All @@ -19,7 +22,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking

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

suspend fun main() {
val bot = ExtensibleBot(token) {
Expand Down Expand Up @@ -51,22 +54,26 @@ suspend fun main() {

if (role != null) {
if (livemessage != null) {
channel?.createMessage(livemessage
.replace("{name}", it.channel.name)
.replace("{category}", it.stream.gameName)
.replace("{title}", it.stream.title)
.replace("{url}", "https://twitch.tv/${it.channel.name}")
.replace("{role}", "<@&$role>"))
channel?.createMessage(
livemessage
.replace("{name}", it.channel.name)
.replace("{category}", it.stream.gameName)
.replace("{title}", it.stream.title)
.replace("{url}", "https://twitch.tv/${it.channel.name}")
.replace("{role}", "<@&$role>")
)
} else {
channel?.createMessage("<@&$role> https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}")
}
} else {
if (livemessage != null) {
channel?.createMessage(livemessage
.replace("{name}", it.channel.name)
.replace("{category}", it.stream.gameName)
.replace("{title}", it.stream.title)
.replace("{url}", "https://twitch.tv/${it.channel.name}"))
channel?.createMessage(
livemessage
.replace("{name}", it.channel.name)
.replace("{category}", it.stream.gameName)
.replace("{title}", it.stream.title)
.replace("{url}", "https://twitch.tv/${it.channel.name}")
)
} else {
channel?.createMessage("https://twitch.tv/${it.channel.name} went live streaming ${it.stream.gameName}: ${it.stream.title}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class StreamerCollection : KordExKoinComponent {
suspend fun getData(channelName: String): StreamerData? =
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)
if (coll != null) {
collection.updateOne(
Expand All @@ -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)
if (coll != null) {
collection.updateOne(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dev.jansel.feixiao.twitchClient
import dev.kord.core.event.gateway.ReadyEvent
import dev.kordex.core.extensions.Extension
import dev.kordex.core.extensions.event
import org.litote.kmongo.deleteMany
import org.litote.kmongo.eq

class EventHooks : Extension() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ class StreamerCommand : Extension() {
}
action {
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)
respond {
content = "Added streamer $streamer"
Expand Down

0 comments on commit 20da6a5

Please sign in to comment.