Merge branch 'refactor/translations-and-latest-kordex' into root
This commit is contained in:
commit
c96e4f56ee
9 changed files with 102 additions and 43 deletions
|
@ -10,15 +10,19 @@ 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
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
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) {
|
||||
|
@ -27,6 +31,9 @@ suspend fun main() {
|
|||
add(::EventHooks)
|
||||
add(::StreamerCommand)
|
||||
}
|
||||
i18n {
|
||||
applicationCommandLocale(SupportedLocales.ENGLISH, SupportedLocales.GERMAN)
|
||||
}
|
||||
}
|
||||
twitchClient = TwitchClientBuilder.builder()
|
||||
.withEnableHelix(true)
|
||||
|
@ -47,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}")
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
@ -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(
|
||||
|
|
|
@ -11,7 +11,6 @@ import dev.kord.core.entity.channel.GuildMessageChannel
|
|||
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() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.jansel.feixiao.extensions
|
||||
|
||||
import dev.jansel.feixiao.database.collections.StreamerCollection
|
||||
import dev.jansel.feixiao.i18n.Translations
|
||||
import dev.jansel.feixiao.twitchClient
|
||||
import dev.kord.common.entity.Permission
|
||||
import dev.kordex.core.checks.anyGuild
|
||||
|
@ -18,19 +19,25 @@ class StreamerCommand : Extension() {
|
|||
override val name = "streaming"
|
||||
override suspend fun setup() {
|
||||
publicSlashCommand {
|
||||
name = "streamer"
|
||||
description = "Streamer commands"
|
||||
name = Translations.Streamer.Command.name
|
||||
description = Translations.Streamer.Command.description
|
||||
|
||||
publicSubCommand(::AddStreamerArgs) {
|
||||
name = "add"
|
||||
description = "Add a streamer to the listener of this server"
|
||||
name = Translations.Streamer.Command.Add.name
|
||||
description = Translations.Streamer.Command.Add.description
|
||||
check {
|
||||
anyGuild()
|
||||
hasPermission(Permission.ManageGuild)
|
||||
}
|
||||
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"
|
||||
|
@ -39,8 +46,8 @@ class StreamerCommand : Extension() {
|
|||
}
|
||||
|
||||
publicSubCommand(::RemoveStreamerArgs) {
|
||||
name = "remove"
|
||||
description = "Remove a streamer from the listener of this server"
|
||||
name = Translations.Streamer.Command.Remove.name
|
||||
description = Translations.Streamer.Command.Remove.description
|
||||
check {
|
||||
anyGuild()
|
||||
hasPermission(Permission.ManageGuild)
|
||||
|
@ -58,29 +65,29 @@ class StreamerCommand : Extension() {
|
|||
|
||||
inner class AddStreamerArgs : Arguments() {
|
||||
val streamer by string {
|
||||
name = "streamer"
|
||||
description = "The streamer to add"
|
||||
name = Translations.Streamer.Command.Arguments.Add.Streamer.name
|
||||
description = Translations.Streamer.Command.Arguments.Add.Streamer.description
|
||||
require(true)
|
||||
}
|
||||
val channel by channel {
|
||||
name = "announcechannel"
|
||||
description = "Channel where the bot will send a message when the streamer goes live"
|
||||
name = Translations.Streamer.Command.Arguments.Add.Channel.name
|
||||
description = Translations.Streamer.Command.Arguments.Add.Channel.description
|
||||
require(true)
|
||||
}
|
||||
val role by optionalRole {
|
||||
name = "role"
|
||||
description = "Role to ping when the streamer goes live"
|
||||
name = Translations.Streamer.Command.Arguments.Add.Role.name
|
||||
description = Translations.Streamer.Command.Arguments.Add.Role.description
|
||||
}
|
||||
val message by optionalString {
|
||||
name = "message"
|
||||
description = "Possible placeholders (put in curly braces!!): url, name, title, category, role (if set)"
|
||||
name = Translations.Streamer.Command.Arguments.Add.Message.name
|
||||
description = Translations.Streamer.Command.Arguments.Add.Message.description
|
||||
}
|
||||
}
|
||||
|
||||
inner class RemoveStreamerArgs : Arguments() {
|
||||
val streamer by string {
|
||||
name = "streamer"
|
||||
description = "The streamer to remove"
|
||||
name = Translations.Streamer.Command.Arguments.Remove.name
|
||||
description = Translations.Streamer.Command.Arguments.Remove.description
|
||||
require(true)
|
||||
}
|
||||
}
|
||||
|
|
20
src/main/resources/translations/feixiao/strings.properties
Normal file
20
src/main/resources/translations/feixiao/strings.properties
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Streamer Command
|
||||
|
||||
streamer.command.name=streamer
|
||||
streamer.command.description=A bundle of Streamer commands
|
||||
streamer.command.add.name=add
|
||||
streamer.command.add.description=Add a new streamer to the listener
|
||||
streamer.command.remove.name=remove
|
||||
streamer.command.remove.description=Remove a streamer from the listener
|
||||
streamer.command.arguments.add.streamer.name=streamer
|
||||
streamer.command.arguments.add.streamer.description=The streamer to add
|
||||
streamer.command.arguments.add.channel.name=channel
|
||||
streamer.command.arguments.add.channel.description=The channel to add the streamer to
|
||||
streamer.command.arguments.add.role.name=role
|
||||
streamer.command.arguments.add.role.description=The role to assign to the streamer
|
||||
streamer.command.arguments.add.message.name=message
|
||||
streamer.command.arguments.add.message.description=Custom Announce message. Placeholders (in curly braces): url, name, title, category, role (if set)
|
||||
streamer.command.arguments.remove.name=streamer
|
||||
streamer.command.arguments.remove.description=The streamer to remove
|
||||
|
||||
# more to come...
|
Loading…
Add table
Add a link
Reference in a new issue