fix: fixed sorting top lists not working

This commit is contained in:
moonleay 2023-12-08 11:36:01 +01:00
parent 338d00c990
commit e4102cc56b
Signed by: moonleay
GPG key ID: 82667543CCD715FB

View file

@ -25,11 +25,11 @@ import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
import com.kotlindiscord.kord.extensions.types.respond import com.kotlindiscord.kord.extensions.types.respond
import dev.kord.common.entity.Snowflake import dev.kord.common.entity.Snowflake
import dev.kord.core.entity.Guild import dev.kord.core.entity.Guild
import kotlinx.coroutines.flow.map
import net.moonleay.bedge.data.database.entry.UserData import net.moonleay.bedge.data.database.entry.UserData
import net.moonleay.bedge.data.database.repository.UserRepository import net.moonleay.bedge.data.database.repository.UserRepository
import net.moonleay.bedge.extensions.component.ListTypes import net.moonleay.bedge.extensions.component.ListTypes
import net.moonleay.bedge.util.EmbedColor import net.moonleay.bedge.util.EmbedColor
import net.moonleay.bedge.util.Logger
import net.moonleay.bedge.util.MessageUtil import net.moonleay.bedge.util.MessageUtil
class TopExtension : Extension() { class TopExtension : Extension() {
@ -49,22 +49,27 @@ class TopExtension : Extension() {
val g = this.guild!!.asGuild() val g = this.guild!!.asGuild()
val targetList = this.arguments.listType val targetList = this.arguments.listType
val all = UserRepository.getAllUsers() val all = UserRepository.getAllUsers()
val allInGuild = all.filter { g.getMemberOrNull(Snowflake(it.userid)) != null } var allInGuild = all.filter { g.getMemberOrNull(Snowflake(it.userid)) != null }
when(targetList) { when(targetList) {
ListTypes.TOPSTREAK -> { ListTypes.TOPSTREAK -> {
allInGuild.sortedByDescending { it.longestStreak } Logger.out("Sorting by topstreak")
allInGuild = allInGuild.sortedByDescending { it.longestStreak }
} }
ListTypes.STREAK -> { ListTypes.STREAK -> {
allInGuild.sortedByDescending { it.currentStreak } Logger.out("Sorting by streak")
allInGuild = allInGuild.sortedByDescending { it.currentStreak }
} }
ListTypes.TOPCOINS -> { ListTypes.TOPCOINS -> {
allInGuild.sortedByDescending { it.coinsCollected } Logger.out("Sorting by topcoins")
allInGuild = allInGuild.sortedByDescending { it.coinsCollected }
} }
ListTypes.COINS -> { ListTypes.COINS -> {
allInGuild.sortedByDescending { it.coins } Logger.out("Sorting by coins")
allInGuild = allInGuild.sortedByDescending { it.coins }
} }
ListTypes.FAILS -> { ListTypes.FAILS -> {
allInGuild.sortedByDescending { it.numberOfFails } Logger.out("Sorting by fails")
allInGuild = allInGuild.sortedByDescending { it.numberOfFails }
} }
} }
var msg = "" var msg = ""
@ -87,7 +92,6 @@ class TopExtension : Extension() {
} }
} }
private suspend fun getRow(user: UserData, g: Guild, type: ListTypes): Array<String> { private suspend fun getRow(user: UserData, g: Guild, type: ListTypes): Array<String> {
val typeResult: String = when(type) { val typeResult: String = when(type) {
ListTypes.TOPSTREAK -> user.longestStreak.toString() ListTypes.TOPSTREAK -> user.longestStreak.toString()