feat: added buttons for TimePlanner v2
Signed-off-by: limited_dev <loginakkisativ@gmail.com>
This commit is contained in:
parent
ec9d8b195c
commit
af79090ca0
5 changed files with 328 additions and 1 deletions
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* Copyright (C) 2023 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.buttons.timeplanner
|
||||
|
||||
import dev.kord.core.behavior.edit
|
||||
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
|
||||
import dev.kord.core.entity.Guild
|
||||
import dev.kord.core.entity.User
|
||||
import dev.kord.core.entity.channel.MessageChannel
|
||||
import dev.kord.core.entity.interaction.ButtonInteraction
|
||||
import dev.kord.rest.builder.message.modify.embed
|
||||
import net.moonleay.lilJudd.Bot
|
||||
import net.moonleay.lilJudd.buttons.component.EditButton
|
||||
import net.moonleay.lilJudd.util.ButtonUtil
|
||||
|
||||
class IsAvailableEditButton : EditButton("public.edit.btn.timemanagement.available") {
|
||||
override suspend fun onInteraction(
|
||||
interaction: ButtonInteraction,
|
||||
response: PublicMessageInteractionResponseBehavior,
|
||||
guild: Guild,
|
||||
user: User
|
||||
) {
|
||||
val m = interaction.message
|
||||
if (m.embeds[0].fields[0].value.contains(user.id.value.toString())) {
|
||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
|
||||
this.embed {
|
||||
val temp = ButtonUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", m.embeds[0], 1)
|
||||
this.color = temp.color
|
||||
this.title = temp.title
|
||||
this.description = temp.description
|
||||
this.fields = temp.fields
|
||||
this.footer = temp.footer
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
|
||||
this.embed {
|
||||
val temp = ButtonUtil.addXToValuesAtTable(user.id.value.toString(), m.embeds[0], 1)
|
||||
this.color = temp.color
|
||||
this.title = temp.title
|
||||
this.description = temp.description
|
||||
this.fields = temp.fields
|
||||
this.footer = temp.footer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* Copyright (C) 2023 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.buttons.timeplanner
|
||||
|
||||
import dev.kord.core.behavior.edit
|
||||
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
|
||||
import dev.kord.core.entity.Guild
|
||||
import dev.kord.core.entity.User
|
||||
import dev.kord.core.entity.channel.MessageChannel
|
||||
import dev.kord.core.entity.interaction.ButtonInteraction
|
||||
import dev.kord.rest.builder.message.modify.embed
|
||||
import net.moonleay.lilJudd.Bot
|
||||
import net.moonleay.lilJudd.buttons.component.EditButton
|
||||
import net.moonleay.lilJudd.util.ButtonUtil
|
||||
|
||||
class MaybeAvailableEditButton : EditButton("public.edit.btn.timemanagement.maybeavailable") {
|
||||
override suspend fun onInteraction(
|
||||
interaction: ButtonInteraction,
|
||||
response: PublicMessageInteractionResponseBehavior,
|
||||
guild: Guild,
|
||||
user: User
|
||||
) {
|
||||
val m = interaction.message
|
||||
if (m.embeds[0].fields[1].value.contains(user.id.value.toString())) {
|
||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
|
||||
this.embed {
|
||||
val temp = ButtonUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", m.embeds[0], 2)
|
||||
this.color = temp.color
|
||||
this.title = temp.title
|
||||
this.description = temp.description
|
||||
this.fields = temp.fields
|
||||
this.footer = temp.footer
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
|
||||
this.embed {
|
||||
val temp = ButtonUtil.addXToValuesAtTable(user.id.value.toString(), m.embeds[0], 2)
|
||||
this.color = temp.color
|
||||
this.title = temp.title
|
||||
this.description = temp.description
|
||||
this.fields = temp.fields
|
||||
this.footer = temp.footer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* Copyright (C) 2023 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.buttons.timeplanner
|
||||
|
||||
import dev.kord.core.behavior.edit
|
||||
import dev.kord.core.behavior.interaction.response.PublicMessageInteractionResponseBehavior
|
||||
import dev.kord.core.entity.Guild
|
||||
import dev.kord.core.entity.User
|
||||
import dev.kord.core.entity.channel.MessageChannel
|
||||
import dev.kord.core.entity.interaction.ButtonInteraction
|
||||
import dev.kord.rest.builder.message.modify.embed
|
||||
import net.moonleay.lilJudd.Bot
|
||||
import net.moonleay.lilJudd.buttons.component.EditButton
|
||||
import net.moonleay.lilJudd.util.ButtonUtil
|
||||
|
||||
class NotAvailableEditButton : EditButton("public.edit.btn.timemanagement.notavailable") {
|
||||
|
||||
override suspend fun onInteraction(
|
||||
interaction: ButtonInteraction,
|
||||
response: PublicMessageInteractionResponseBehavior,
|
||||
guild: Guild,
|
||||
user: User
|
||||
) {
|
||||
val m = interaction.message
|
||||
if (m.embeds[0].fields[2].value.contains(user.id.value.toString())) {
|
||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
|
||||
this.embed {
|
||||
val temp = ButtonUtil.replaceXWithYinValuesAtTable(user.id.value.toString(), "", m.embeds[0], 3)
|
||||
this.color = temp.color
|
||||
this.title = temp.title
|
||||
this.description = temp.description
|
||||
this.fields = temp.fields
|
||||
this.footer = temp.footer
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Bot.bot.kordRef.getChannelOf<MessageChannel>(interaction.channelId)!!.getMessage(m.id).edit {
|
||||
this.embed {
|
||||
val temp = ButtonUtil.addXToValuesAtTable(user.id.value.toString(), m.embeds[0], 3)
|
||||
this.color = temp.color
|
||||
this.title = temp.title
|
||||
this.description = temp.description
|
||||
this.fields = temp.fields
|
||||
this.footer = temp.footer
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
96
src/main/kotlin/net/moonleay/lilJudd/util/ButtonUtil.kt
Normal file
96
src/main/kotlin/net/moonleay/lilJudd/util/ButtonUtil.kt
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* lilJudd
|
||||
* Copyright (C) 2023 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 ButtonUtil {
|
||||
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 = "Maybe available"
|
||||
}
|
||||
ar.interactionButton(ButtonStyle.Danger, "public.edit.btn.timemanagement.notavailable") {
|
||||
this.label = "Not available"
|
||||
}
|
||||
return ar
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x The string to replace
|
||||
* @param y The string to replace with
|
||||
* @param e The embed to replace the string in
|
||||
* @param table The table to replace the string in
|
||||
* @param maxTableSize The max table size
|
||||
* @return The embed with the replaced string
|
||||
*/
|
||||
fun replaceXWithYinValuesAtTable(x: String, y: String, e: Embed, table: Int): EmbedBuilder {
|
||||
val ebb = MessageUtil.getAClonedEmbedd(e)
|
||||
for ((i, f) in e.fields.withIndex()) {
|
||||
val fb = EmbedBuilder.Field()
|
||||
fb.name = f.name
|
||||
if (i == table - 1) {
|
||||
val v = f.value.split("\n").toMutableList()
|
||||
for ((i, l) in v.withIndex())
|
||||
if (l.contains(x))
|
||||
v[i] = "\n${y}"
|
||||
fb.value = v.joinToString("\n")
|
||||
} else
|
||||
fb.value = f.value
|
||||
fb.inline = true
|
||||
ebb.fields.add(fb)
|
||||
}
|
||||
return ebb
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x The string to add
|
||||
* @param e The embed to add the string to
|
||||
* @param table The table to add the string to
|
||||
* @param maxTableSize The max table size
|
||||
* @return The embed with the added string
|
||||
*/
|
||||
fun addXToValuesAtTable(x: String, e: Embed, table: Int): EmbedBuilder {
|
||||
val ebb = MessageUtil.getAClonedEmbedd(e)
|
||||
for ((i, f) in e.fields.withIndex()) {
|
||||
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] = "\n"
|
||||
fb.value = v.joinToString("\n")
|
||||
}
|
||||
|
||||
fb.inline = true
|
||||
ebb.fields.add(fb)
|
||||
}
|
||||
return ebb
|
||||
}
|
||||
|
||||
}
|
|
@ -23,6 +23,7 @@ import com.kotlindiscord.kord.extensions.commands.application.slash.PublicSlashC
|
|||
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
|
||||
import com.kotlindiscord.kord.extensions.types.respond
|
||||
import dev.kord.common.Color
|
||||
import dev.kord.core.entity.Embed
|
||||
import dev.kord.rest.builder.message.EmbedBuilder
|
||||
import java.time.LocalDateTime
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
@ -70,6 +71,43 @@ object MessageUtil {
|
|||
}
|
||||
}
|
||||
|
||||
///Get a cloned embedded message, missing only the fields
|
||||
fun getAClonedEmbedd(e: Embed): EmbedBuilder {
|
||||
val ebb = EmbedBuilder()
|
||||
ebb.color = e.color
|
||||
ebb.title = e.title
|
||||
ebb.description = e.description
|
||||
ebb.footer {
|
||||
icon = e.footer!!.iconUrl
|
||||
text = e.footer!!.text
|
||||
}
|
||||
return ebb
|
||||
}
|
||||
|
||||
///Get an embedded msg with image, title and description
|
||||
fun getEmbedWithTable(
|
||||
color: Color,
|
||||
title: String,
|
||||
description: String,
|
||||
source: String,
|
||||
values: Map<String, List<String>>?
|
||||
): EmbedBuilder {
|
||||
val ebb = getEmbed(color, title, description, source)
|
||||
if (values != null)
|
||||
for (key in values.keys) {
|
||||
val fb = EmbedBuilder.Field()
|
||||
fb.name = key
|
||||
var s = ""
|
||||
for (value in values[key]!!)
|
||||
s += "$value\n"
|
||||
fb.value = s
|
||||
fb.inline = true
|
||||
ebb.fields.add(fb)
|
||||
}
|
||||
return ebb
|
||||
}
|
||||
|
||||
|
||||
///Get an embedded msg with title and description
|
||||
fun getEmbedSmall(
|
||||
color: Color,
|
||||
|
@ -79,6 +117,7 @@ object MessageUtil {
|
|||
val ebb = EmbedBuilder()
|
||||
ebb.title = title
|
||||
ebb.description = description
|
||||
ebb.color = color
|
||||
return ebb
|
||||
}
|
||||
|
||||
|
@ -93,7 +132,6 @@ object MessageUtil {
|
|||
val now: LocalDateTime = LocalDateTime.now()
|
||||
ebb.footer = EmbedBuilder.Footer()
|
||||
ebb.footer!!.text = ">" + dtf.format(now) + " - $source"
|
||||
ebb.color = color
|
||||
return ebb
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue