From ccdfa9abcff23a15ce1326a4b664eeeadaf0efff Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 18 Jan 2024 08:47:31 +0100 Subject: [PATCH] feat: started working on shop --- src/main/kotlin/net/moonleay/bedge/Bot.kt | 1 + .../bedge/extensions/ShopExtension.kt | 97 +++++++++++++++++++ .../bedge/extensions/component/ShopAction.kt | 26 +++++ .../bedge/extensions/component/ShopItem.kt | 28 ++++++ 4 files changed, 152 insertions(+) create mode 100644 src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt create mode 100644 src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt create mode 100644 src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt diff --git a/src/main/kotlin/net/moonleay/bedge/Bot.kt b/src/main/kotlin/net/moonleay/bedge/Bot.kt index da857c9..444f31a 100644 --- a/src/main/kotlin/net/moonleay/bedge/Bot.kt +++ b/src/main/kotlin/net/moonleay/bedge/Bot.kt @@ -79,6 +79,7 @@ object Bot { add(::AwakeExtension) add(::ProfileExtension) add(::TopExtension) +// add(::ShopExtension) } this.presence { diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt b/src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt new file mode 100644 index 0000000..7395c82 --- /dev/null +++ b/src/main/kotlin/net/moonleay/bedge/extensions/ShopExtension.kt @@ -0,0 +1,97 @@ +/* + * Bedge + * 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 . + */ + +package net.moonleay.bedge.extensions + +import com.kotlindiscord.kord.extensions.commands.Arguments +import com.kotlindiscord.kord.extensions.commands.application.slash.converters.impl.enumChoice +import com.kotlindiscord.kord.extensions.extensions.Extension +import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand +import com.kotlindiscord.kord.extensions.types.respond +import net.moonleay.bedge.data.database.repository.UserRepository +import net.moonleay.bedge.extensions.component.ShopAction +import net.moonleay.bedge.extensions.component.ShopItem +import net.moonleay.bedge.util.EmbedColor +import net.moonleay.bedge.util.MessageUtil + +class ShopExtension : Extension() { + + override val name = "shop" + override val allowApplicationCommandInDMs: Boolean + get() = false + + + override suspend fun setup() { + publicSlashCommand(::ShopArguments) { + name = "shop" + description = "Buy stuff with your items" + + this.action { + val user = this.user.asUser() + val ud = UserRepository.getUserByID(user.id.value) + + if (ud == null) { + this.respond { + this.embeds.add( + MessageUtil.getEmbed(EmbedColor.ERROR, + "You don't have an account here!", + "And therefore I cannot show you our shop.\n" + + "You can register by running `/time`.", + user.username) + ) + } + return@action + } + when(this.arguments.action){ + ShopAction.LIST_OFFERS -> { + var description = "Your Coins: ${ud.coins}\n" + + "Your lvl: ${ud.level}\n\n" + + "item :: price :: required level\n" + + ShopItem.entries.forEach { itm -> + description += "\"${itm.readableName}\" :: ${itm.cost} coins :: ${itm.requiredLevel}\n" + } + + this.respond { + this.embeds.add( + MessageUtil.getEmbed( + EmbedColor.INFO, + "The Shop", + description, + user.username + ) + ) + } + } + ShopAction.BUY -> { + var description = "" + + } + } + } + } + } + + inner class ShopArguments : Arguments() { + + val action by enumChoice { + this.name = "action" + this.description = "What you want to do" + } + } +} diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt new file mode 100644 index 0000000..8c1fee0 --- /dev/null +++ b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopAction.kt @@ -0,0 +1,26 @@ +/* + * Bedge + * 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 . + */ + +package net.moonleay.bedge.extensions.component + +import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum + +enum class ShopAction(override val readableName: String) : ChoiceEnum { + LIST_OFFERS("list offers"), + BUY("buy") +} diff --git a/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt new file mode 100644 index 0000000..f4f30c4 --- /dev/null +++ b/src/main/kotlin/net/moonleay/bedge/extensions/component/ShopItem.kt @@ -0,0 +1,28 @@ +/* + * Bedge + * 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 . + */ + +package net.moonleay.bedge.extensions.component + +import com.kotlindiscord.kord.extensions.commands.application.slash.converters.ChoiceEnum + +enum class ShopItem(override val readableName: String, val itemDescription: String, val cost: Int, val requiredLevel: Int) : ChoiceEnum { + ADD_CUSTOM_SERVER_MOTD("Add a custom MOTD", "Add a MOTD to my minecraft server", 2, 0), + REMOVE_DEATH_FROM_COUNTER("Remove Death", "Remove a death from the death counter on my minecraft server", 21, 4), + UPDATE_WAKEUP_MESSAGE("Update wakeup msg", "Update the message the bot sends, when you wake up", 4, 2), + UPDATE_REMINDER_MESSAGE("Update reminder msg","Update the message the bot sends you to remind you to go to bed", 4, 2) +}