forked from DiscordBots/lilJudd
127 lines
4.5 KiB
Kotlin
127 lines
4.5 KiB
Kotlin
/*
|
|
* lilJudd
|
|
* Copyright (C) 2024 moonleay
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package net.moonleay.liljudd.util
|
|
|
|
import dev.kord.common.entity.ButtonStyle
|
|
import dev.kord.core.entity.Embed
|
|
import dev.kord.rest.builder.component.ActionRowBuilder
|
|
import dev.kord.rest.builder.message.EmbedBuilder
|
|
|
|
object EmbedUtil {
|
|
fun getTimePlannerButtons(): ActionRowBuilder {
|
|
val ar = ActionRowBuilder()
|
|
ar.interactionButton(ButtonStyle.Success, "public.edit.btn.timemanagement.available") {
|
|
this.label = "Available"
|
|
}
|
|
ar.interactionButton(ButtonStyle.Primary, "public.edit.btn.timemanagement.maybeavailable") {
|
|
this.label = "May be available"
|
|
}
|
|
ar.interactionButton(ButtonStyle.Danger, "public.edit.btn.timemanagement.notavailable") {
|
|
this.label = "Not available"
|
|
}
|
|
return ar
|
|
}
|
|
|
|
fun getMatchButtons(): ActionRowBuilder {
|
|
val ar = ActionRowBuilder()
|
|
ar.interactionButton(ButtonStyle.Success, "public.edit.btn.matchmanagement.accept") {
|
|
this.label = "I'm in!"
|
|
}
|
|
ar.interactionButton(ButtonStyle.Danger, "public.edit.btn.matchmanagement.decline") {
|
|
this.label = "I'm out!"
|
|
}
|
|
/*
|
|
ar.interactionButton(ButtonStyle.Secondary, "public.edit.btn.matchmanagement.cancel") {
|
|
this.label = "Cancel this match..."
|
|
} */
|
|
return ar
|
|
}
|
|
|
|
fun replaceXWithYinValuesAtTable(x: String, y: String, e: Embed, table: Int): EmbedBuilder {
|
|
return replaceXWithYinValuesAtTable(x, y, MessageUtil.getAClonedEmbed(e), table)
|
|
}
|
|
|
|
fun replaceXWithYinValuesAtTable(x: String, y: String, ebb: EmbedBuilder, table: Int): EmbedBuilder {
|
|
val ebbb = MessageUtil.getAClonedEmbed(ebb)
|
|
ebbb.fields = mutableListOf()
|
|
for ((i, f) in ebb.fields.withIndex()) {
|
|
val fb = EmbedBuilder.Field()
|
|
fb.name = f.name
|
|
if (i == table - 1) {
|
|
val v = f.value.split("\n").toMutableList()
|
|
for ((j, l) in v.withIndex())
|
|
if (l.contains(x))
|
|
v[j] = y
|
|
v.removeIf {
|
|
!it.contains("@")
|
|
}
|
|
fb.value = v.joinToString("\n")
|
|
} else
|
|
fb.value = f.value
|
|
fb.inline = true
|
|
ebbb.fields.add(fb)
|
|
}
|
|
return ebbb
|
|
}
|
|
|
|
fun getAllUsersInTheFirstXTables(amountOfTables: Int, e: Embed): List<String> {
|
|
val users = mutableListOf<String>()
|
|
for (i in 0 until amountOfTables) {
|
|
val f = e.fields[i]
|
|
if (!f.value.contains("@"))
|
|
continue // check next one. this one does not have any entries
|
|
val v = f.value.split("\n").toMutableList()
|
|
for (l in v) {
|
|
Logger.out(l)
|
|
users.add(l.subSequence(2, l.indexOf(">")).toString())
|
|
}
|
|
}
|
|
return users
|
|
}
|
|
|
|
fun addXToValuesAtTable(x: String, e: Embed, table: Int): EmbedBuilder {
|
|
return addXToValuesAtTable(x, MessageUtil.getAClonedEmbed(e), table)
|
|
}
|
|
|
|
fun addXToValuesAtTable(x: String, ebb: EmbedBuilder, table: Int): EmbedBuilder {
|
|
val ebbb = MessageUtil.getAClonedEmbed(ebb)
|
|
ebbb.fields = mutableListOf()
|
|
ebb.fields.forEachIndexed { i, f ->
|
|
val fb = EmbedBuilder.Field()
|
|
fb.name = f.name
|
|
if (i == table - 1)
|
|
fb.value = f.value + "\n<@$x>"
|
|
else {
|
|
val v = f.value.split("\n").toMutableList()
|
|
for ((j, l) in v.withIndex())
|
|
if (l.contains(x))
|
|
v[j] = ""
|
|
v.removeIf {
|
|
!it.contains("@")
|
|
}
|
|
fb.value = v.joinToString("\n")
|
|
}
|
|
|
|
fb.inline = true
|
|
ebbb.fields.add(fb)
|
|
}
|
|
return ebbb
|
|
}
|
|
|
|
}
|