done a lot of shit that will be too much to explain, especially because for once I had to comment my code which I don't like.
This commit is contained in:
parent
6fb1e794bd
commit
5728ac716c
@ -6,6 +6,7 @@ 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
|
||||
|
||||
@ -20,7 +21,7 @@ class StreamerCollection : KordExKoinComponent {
|
||||
suspend fun getData(channelName: String): StreamerData? =
|
||||
collection.findOne(StreamerData::name eq channelName)
|
||||
|
||||
suspend fun updateData(
|
||||
suspend fun addData(
|
||||
guildId: Snowflake,
|
||||
channelId: Snowflake,
|
||||
streamerName: String,
|
||||
@ -40,6 +41,84 @@ class StreamerCollection : KordExKoinComponent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the roleId
|
||||
* @param streamerName: The name of the streamer
|
||||
* @param roleId: The roleId to update
|
||||
* @param guildId: The guildId to update
|
||||
* @param noOverload: This is needed to avoid a conflict with the other updateData function, set to true or false, doesn't matter
|
||||
* @return 0 = success, 1 = no Server associated with the guildId, 2 = no StreamerData associated with the streamerName
|
||||
*/
|
||||
|
||||
suspend fun updateData(
|
||||
streamerName: String,
|
||||
roleId: Snowflake,
|
||||
guildId: Snowflake,
|
||||
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))
|
||||
)
|
||||
return 0
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the liveMessage
|
||||
* @param streamerName: The name of the streamer
|
||||
* @param liveMessage: The liveMessage to update
|
||||
* @param guildId: The guildId to update
|
||||
* @return 0 = success, 1 = no Server associated with the guildId, 2 = no StreamerData associated with the streamerName
|
||||
*/
|
||||
suspend fun updateData(
|
||||
streamerName: String,
|
||||
liveMessage: String?,
|
||||
guildId: Snowflake
|
||||
): 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, temp.roleId, liveMessage))
|
||||
)
|
||||
return 0
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the channelId
|
||||
* @param streamerName: The name of the streamer
|
||||
* @param channelId: The channelId to update
|
||||
* @param guildId: The guildId to update
|
||||
* @return 0 = success, 1 = no Server associated with the guildId, 2 = no StreamerData associated with the streamerName
|
||||
*/
|
||||
suspend fun updateData(
|
||||
streamerName: String,
|
||||
channelId: Snowflake,
|
||||
guildId: Snowflake
|
||||
): 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, channelId, temp.roleId, temp.liveMessage))
|
||||
)
|
||||
return 0
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
suspend fun removeData(
|
||||
guildId: Snowflake,
|
||||
channelId: Snowflake,
|
||||
|
@ -2,6 +2,7 @@ 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
|
||||
@ -10,6 +11,7 @@ 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
|
||||
@ -33,7 +35,15 @@ class StreamerCommand : Extension() {
|
||||
}
|
||||
action {
|
||||
val streamer = arguments.streamer
|
||||
StreamerCollection().updateData(
|
||||
StreamerCollection().getData(streamer)?.servers?.forEach {
|
||||
if (it.guildId == guild!!.id) {
|
||||
respond {
|
||||
content = "Streamer already exists in this server"
|
||||
}
|
||||
return@action
|
||||
}
|
||||
}
|
||||
StreamerCollection().addData(
|
||||
guild!!.id,
|
||||
arguments.channel.id,
|
||||
streamer,
|
||||
@ -64,6 +74,49 @@ class StreamerCommand : Extension() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publicSubCommand(::UpdateStreamerArgs) {
|
||||
name = Translations.Streamer.Command.Update.name
|
||||
description = Translations.Streamer.Command.Update.description
|
||||
check {
|
||||
anyGuild()
|
||||
hasPermission(Permission.ManageGuild)
|
||||
}
|
||||
action {
|
||||
val streamer = arguments.streamer
|
||||
val data = StreamerCollection().collection.findOne(StreamerData::name eq streamer)
|
||||
if (data != null) {
|
||||
val servers = data.servers
|
||||
val guildId = guild!!.id
|
||||
val roleId = arguments.role
|
||||
val channelId = arguments.channel
|
||||
val message = arguments.message
|
||||
val temp = servers.find { it.guildId == guildId }
|
||||
if (temp != null) {
|
||||
if (channelId != null) {
|
||||
StreamerCollection().updateData(streamer, channelId.id, guildId)
|
||||
}
|
||||
if (roleId != null) {
|
||||
StreamerCollection().updateData(streamer, roleId.id, guildId, false)
|
||||
}
|
||||
if (message != null) {
|
||||
StreamerCollection().updateData(streamer, message, guildId)
|
||||
}
|
||||
respond {
|
||||
content = "Updated streamer $streamer"
|
||||
}
|
||||
} else {
|
||||
respond {
|
||||
content = "No server associated with the guildId"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
respond {
|
||||
content = "No StreamerData associated with the streamerName"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,4 +148,23 @@ class StreamerCommand : Extension() {
|
||||
require(true)
|
||||
}
|
||||
}
|
||||
|
||||
inner class UpdateStreamerArgs : Arguments() {
|
||||
val streamer by string {
|
||||
name = Translations.Streamer.Command.Arguments.Update.Streamer.name
|
||||
description = Translations.Streamer.Command.Arguments.Update.Streamer.description
|
||||
}
|
||||
val channel by optionalChannel {
|
||||
name = Translations.Streamer.Command.Arguments.Update.Channel.name
|
||||
description = Translations.Streamer.Command.Arguments.Update.Channel.description
|
||||
}
|
||||
val role by optionalRole {
|
||||
name = Translations.Streamer.Command.Arguments.Update.Role.name
|
||||
description = Translations.Streamer.Command.Arguments.Update.Role.description
|
||||
}
|
||||
val message by optionalString {
|
||||
name = Translations.Streamer.Command.Arguments.Update.Message.name
|
||||
description = Translations.Streamer.Command.Arguments.Update.Message.description
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,16 @@
|
||||
|
||||
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.update.name=update
|
||||
streamer.command.update.description=Update a streamer listener's settings for this guild
|
||||
|
||||
streamer.command.arguments.add.streamer.name=streamer
|
||||
streamer.command.arguments.add.streamer.description=The streamer to add
|
||||
streamer.command.arguments.add.channel.name=channel
|
||||
@ -14,7 +20,19 @@ 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
|
||||
|
||||
streamer.command.arguments.update.streamer.name=streamer
|
||||
streamer.command.arguments.update.streamer.description=The streamer to edit
|
||||
streamer.command.arguments.update.channel.name=channel
|
||||
streamer.command.arguments.update.channel.description=The channel to add the streamer to
|
||||
streamer.command.arguments.update.role.name=role
|
||||
streamer.command.arguments.update.role.description=The role to assign to the streamer
|
||||
streamer.command.arguments.update.message.name=message
|
||||
streamer.command.arguments.update.message.description=Custom Announce message. Placeholders (in curly braces): url, name, title, category, role (if set)
|
||||
|
||||
|
||||
|
||||
# more to come...
|
||||
|
Loading…
x
Reference in New Issue
Block a user