From e0c769347197c42cb444ffe9f91d2c10e28c7ec9 Mon Sep 17 00:00:00 2001 From: niggelgame Date: Sun, 6 Jun 2021 22:25:57 +0200 Subject: [PATCH 1/5] feat: add embed builder and migrate current commands to embeds fix: change code style to pass style test fix: remove comments and use global embed function feat: add new branding colors --- .gitignore | 3 + .idea/codeStyles/Project.xml | 10 ++ .idea/codeStyles/codeStyleConfig.xml | 5 + .idea/modules.xml | 8 + .idea/votebot.iml | 12 ++ .../commands/ClaimPermissionsCommand.kt | 5 +- .../schlaubi/votebot/commands/InfoCommand.kt | 3 +- .../votebot/commands/PermissionCommand.kt | 5 +- .../dev/schlaubi/votebot/util/Colors.kt | 49 ++++++ .../dev/schlaubi/votebot/util/Embeds.kt | 145 ++++++++++++++++++ .../dev/schlaubi/votebot/util/Emotes.kt | 36 +++++ 11 files changed, 276 insertions(+), 5 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/votebot.iml create mode 100644 src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt create mode 100644 src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt create mode 100644 src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt diff --git a/.gitignore b/.gitignore index a01c2fd..0f43b23 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ gradle-app.setting **/build/ # End of https://www.toptal.com/developers/gitignore/api/kotlin,gradle + + +.env \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a2e2410 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/votebot.iml b/.idea/votebot.iml new file mode 100644 index 0000000..f100729 --- /dev/null +++ b/.idea/votebot.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt index 10c248e..4aae022 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt @@ -23,6 +23,7 @@ import dev.kord.common.entity.Permission import dev.schlaubi.votebot.command.SingleCommand import dev.schlaubi.votebot.command.context.Context import dev.schlaubi.votebot.command.context.response.respond +import dev.schlaubi.votebot.util.Embeds import dev.schlaubi.votebot.util.appendPermission import dev.schlaubi.votebot.util.getCommands import kotlinx.coroutines.flow.first @@ -35,7 +36,7 @@ object ClaimPermissionsCommand : SingleCommand() { override suspend fun execute(context: Context) { if (Permission.Administrator !in context.executor.asMember().getPermissions()) { - context.respond("You need the `ADMINISTRATOR` permission to execute this command") + context.respond(Embeds.error("You need the `ADMINISTRATOR` permission to execute this command")) return } @@ -49,6 +50,6 @@ object ClaimPermissionsCommand : SingleCommand() { user(context.executor.id, true) } - context.respond("You now have access to /permissions") + context.respond(Embeds.info("You now have access to /permissions")) } } diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt index 1f38e48..434204e 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt @@ -22,6 +22,7 @@ package dev.schlaubi.votebot.commands import dev.schlaubi.votebot.command.SingleCommand import dev.schlaubi.votebot.command.context.Context import dev.schlaubi.votebot.command.context.response.respond +import dev.schlaubi.votebot.util.Embeds object InfoCommand : SingleCommand() { override val description: String = "Displays basic information about the bot" @@ -29,6 +30,6 @@ object InfoCommand : SingleCommand() { override val useEphemeral: Boolean = true override suspend fun execute(context: Context) { - context.respond("Coming soon :tm:") + context.respond(Embeds.info("Coming soon :tm:")) } } diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt index 7537702..25f0a58 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt @@ -26,6 +26,7 @@ import dev.schlaubi.votebot.command.SubCommand import dev.schlaubi.votebot.command.context.Context import dev.schlaubi.votebot.command.context.response.respond import dev.schlaubi.votebot.config.Config +import dev.schlaubi.votebot.util.Embeds import dev.schlaubi.votebot.util.addCommand import dev.schlaubi.votebot.util.appendPermission import dev.schlaubi.votebot.util.buildCommands @@ -107,7 +108,7 @@ suspend fun doPermissions( val command = commands.firstOrNull { it.name == commandName } if (command == null) { - context.respond("Unknown command") + context.respond(Embeds.error("Unknown command")) return } @@ -119,5 +120,5 @@ suspend fun doPermissions( addPermission(context.boolean("permission")) } - context.respond("Permission was updated!") + context.respond(Embeds.success("Permission was updated!")) } diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt new file mode 100644 index 0000000..3c7f8eb --- /dev/null +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt @@ -0,0 +1,49 @@ +/* + * Votebot - A feature-rich bot to create votes on Discord guilds. + * + * Copyright (C) 2019-2021 Michael Rittmeister & Yannick Seeger + * + * 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 dev.schlaubi.votebot.util + +import dev.kord.common.Color + +/** + * Wrapper for [Discordapp.com/branding][https://discordapp.com/branding] colors and some other colors: + */ +@Suppress("KDocMissingDocumentation", "unused", "MagicNumber") +object Colors { + // Discord + val BLURLPLE: Color = Color(88, 101, 242) + val GREEN: Color = Color(87, 242, 135) + val YELLOW: Color = Color(254, 231, 92) + val FUCHSIA: Color = Color(235, 69, 158) + val RED: Color = Color(237, 66, 69) + val WHITE: Color = Color(255, 255, 255) + val BLACK: Color = Color(0, 0, 0) + + // Old Discord Branding Colors + val GREYPLE: Color = Color(153, 170, 181) + val DARK_BUT_NOT_BLACK: Color = Color(44, 47, 51) + val NOT_QUITE_BLACK: Color = Color(33, 39, 42) + + // Other colors + val LIGHT_RED: Color = Color(231, 76, 60) + val DARK_RED: Color = Color(192, 57, 43) + val LIGHT_GREEN: Color = Color(46, 204, 113) + val DARK_GREEN: Color = Color(39, 174, 96) + val BLUE: Color = Color(52, 152, 219) +} diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt new file mode 100644 index 0000000..30b5242 --- /dev/null +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt @@ -0,0 +1,145 @@ +/* + * Votebot - A feature-rich bot to create votes on Discord guilds. + * + * Copyright (C) 2019-2021 Michael Rittmeister & Yannick Seeger + * + * 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 dev.schlaubi.votebot.util + +import dev.kord.core.behavior.MessageBehavior +import dev.kord.core.behavior.channel.MessageChannelBehavior +import dev.kord.core.behavior.channel.createMessage +import dev.kord.core.behavior.edit +import dev.kord.core.entity.Message +import dev.kord.rest.builder.message.EmbedBuilder + +/** + * Defines a creator of an embed. + */ +typealias EmbedCreator = EmbedBuilder.() -> Unit + +/** + * Some presets for frequently used embeds. + */ +@Suppress("unused", "TooManyFunctions") +object Embeds { + + /** + * Creates a info embed with the given [title] and [description] and applies the [builder] to it. + * @see EmbedCreator + * @see EmbedBuilder + */ + fun info(title: String, description: String? = null, builder: EmbedCreator = {}): EmbedBuilder = + embed { + title(Emotes.INFO, title) + this.description = description + color = Colors.BLUE + }.apply(builder) + + /** + * Creates a success embed with the given [title] and [description] and applies the [builder] to it. + * @see EmbedCreator + * @see EmbedBuilder + */ + fun success( + title: String, + description: String? = null, + builder: EmbedCreator = {} + ): EmbedBuilder = + embed { + title(Emotes.SUCCESS, title) + this.description = description + color = Colors.GREEN + }.apply(builder) + + /** + * Creates a error embed with the given [title] and [description] and applies the [builder] to it. + * @see EmbedCreator + * @see EmbedBuilder + */ + fun error( + title: String, + description: String? = null, + builder: EmbedCreator = {} + ): EmbedBuilder = + embed { + title(Emotes.ERROR, title) + this.description = description + color = Colors.RED + }.apply(builder) + + /** + * Creates a warning embed with the given [title] and [description] and applies the [builder] to it. + * @see EmbedCreator + * @see EmbedBuilder + */ + fun warn( + title: String, + description: String? = null, + builder: EmbedCreator = {} + ): EmbedBuilder = + embed { + title(Emotes.WARN, title) + this.description = description + color = Colors.YELLOW + }.apply(builder) + + /** + * Creates a loading embed with the given [title] and [description] and applies the [builder] to it. + * @see EmbedCreator + * @see EmbedBuilder + */ + fun loading( + title: String, + description: String?, + builder: EmbedCreator = {} + ): EmbedBuilder = + embed { + title(Emotes.LOADING, title) + this.description = description + color = Colors.DARK_BUT_NOT_BLACK + }.apply(builder) + + private fun EmbedBuilder.title(emote: String, title: String) { + this.title = "$emote $title" + } + + /** + * Sends a new message in this channel containing the embed provided by [base] and applies [creator] to it + */ + suspend fun MessageChannelBehavior.createEmbed( + base: EmbedBuilder, + creator: suspend EmbedBuilder.() -> Unit = {} + ): Message { + return createMessage { + creator(base) + embed = base + } + } + + /** + * Sends a new message in this channel containing the embed provided by [base] and applies [creator] to it + */ + suspend fun MessageBehavior.editEmbed( + base: EmbedBuilder, + creator: suspend EmbedBuilder.() -> Unit = {} + ): Message { + return edit { + creator(base) + embed = base + } + } +} diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt new file mode 100644 index 0000000..ae86d26 --- /dev/null +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt @@ -0,0 +1,36 @@ +/* + * Votebot - A feature-rich bot to create votes on Discord guilds. + * + * Copyright (C) 2019-2021 Michael Rittmeister & Yannick Seeger + * + * 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 dev.schlaubi.votebot.util + +/** + * Useful collection of Discord emotes. + * + * + * Designed by [Rxsto#1337](https://rxsto.me) + * Bot needs to be on [https://discord.gg/8phqcej](https://discord.gg/8phqcej) + */ +@Suppress("KDocMissingDocumentation") +object Emotes { + const val LOADING: String = "" + const val ERROR: String = "<:error:535827110489620500>" + const val WARN: String = "<:warn:535832532365737987>" + const val INFO: String = "<:info:535828529573789696>" + const val SUCCESS: String = "<:success:535827110552666112>" +} From a5b3a6c5978dc924480c2341cbe64f8b32ea37cb Mon Sep 17 00:00:00 2001 From: Nicolas Edelmann Date: Sun, 6 Jun 2021 22:01:16 +0200 Subject: [PATCH 2/5] feat: add embed builder and migrate current commands to embeds --- .../commands/ClaimPermissionsCommand.kt | 2 +- .../schlaubi/votebot/commands/InfoCommand.kt | 1 + .../votebot/commands/PermissionCommand.kt | 2 +- .../dev/schlaubi/votebot/core/VoteBotImpl.kt | 1 + .../dev/schlaubi/votebot/util/Colors.kt | 14 +-- .../dev/schlaubi/votebot/util/Embeds.kt | 86 +++++++++++++++++-- .../dev/schlaubi/votebot/util/Emotes.kt | 2 +- 7 files changed, 86 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt index 4aae022..53bc092 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt @@ -36,7 +36,7 @@ object ClaimPermissionsCommand : SingleCommand() { override suspend fun execute(context: Context) { if (Permission.Administrator !in context.executor.asMember().getPermissions()) { - context.respond(Embeds.error("You need the `ADMINISTRATOR` permission to execute this command")) + context.respond(Embeds.error("You need the `ADMINISTRATOR` permission to execute this command", description = null)) return } diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt index 434204e..e93dd4b 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt @@ -22,6 +22,7 @@ package dev.schlaubi.votebot.commands import dev.schlaubi.votebot.command.SingleCommand import dev.schlaubi.votebot.command.context.Context import dev.schlaubi.votebot.command.context.response.respond +import dev.schlaubi.votebot.command.context.response.respondEmbed import dev.schlaubi.votebot.util.Embeds object InfoCommand : SingleCommand() { diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt index 25f0a58..2e7365a 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt @@ -108,7 +108,7 @@ suspend fun doPermissions( val command = commands.firstOrNull { it.name == commandName } if (command == null) { - context.respond(Embeds.error("Unknown command")) + context.respond(Embeds.error("Unknown command", description = null)) return } diff --git a/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt b/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt index 15bbbc0..a047cae 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt @@ -19,6 +19,7 @@ package dev.schlaubi.votebot.core +import dev.kord.common.entity.PresenceStatus import dev.kord.core.Kord import dev.schlaubi.votebot.command.RegistrableCommand import dev.schlaubi.votebot.command.internal.CommandExecutor diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt index 3c7f8eb..b0b0642 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt @@ -27,15 +27,8 @@ import dev.kord.common.Color @Suppress("KDocMissingDocumentation", "unused", "MagicNumber") object Colors { // Discord - val BLURLPLE: Color = Color(88, 101, 242) - val GREEN: Color = Color(87, 242, 135) - val YELLOW: Color = Color(254, 231, 92) - val FUCHSIA: Color = Color(235, 69, 158) - val RED: Color = Color(237, 66, 69) - val WHITE: Color = Color(255, 255, 255) - val BLACK: Color = Color(0, 0, 0) - - // Old Discord Branding Colors + val BLURLPLE: Color = Color(114, 137, 218) + val FULL_WHITE: Color = Color(255, 255, 255) val GREYPLE: Color = Color(153, 170, 181) val DARK_BUT_NOT_BLACK: Color = Color(44, 47, 51) val NOT_QUITE_BLACK: Color = Color(33, 39, 42) @@ -46,4 +39,5 @@ object Colors { val LIGHT_GREEN: Color = Color(46, 204, 113) val DARK_GREEN: Color = Color(39, 174, 96) val BLUE: Color = Color(52, 152, 219) -} + val YELLOW: Color = Color(241, 196, 15) +} \ No newline at end of file diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt index 30b5242..727e78e 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt @@ -21,10 +21,11 @@ package dev.schlaubi.votebot.util import dev.kord.core.behavior.MessageBehavior import dev.kord.core.behavior.channel.MessageChannelBehavior -import dev.kord.core.behavior.channel.createMessage import dev.kord.core.behavior.edit import dev.kord.core.entity.Message import dev.kord.rest.builder.message.EmbedBuilder +import dev.kord.core.behavior.channel.createMessage + /** * Defines a creator of an embed. @@ -43,7 +44,7 @@ object Embeds { * @see EmbedBuilder */ fun info(title: String, description: String? = null, builder: EmbedCreator = {}): EmbedBuilder = - embed { + EmbedBuilder().apply { title(Emotes.INFO, title) this.description = description color = Colors.BLUE @@ -59,10 +60,10 @@ object Embeds { description: String? = null, builder: EmbedCreator = {} ): EmbedBuilder = - embed { + EmbedBuilder().apply { title(Emotes.SUCCESS, title) this.description = description - color = Colors.GREEN + color = Colors.LIGHT_GREEN }.apply(builder) /** @@ -75,10 +76,10 @@ object Embeds { description: String? = null, builder: EmbedCreator = {} ): EmbedBuilder = - embed { + EmbedBuilder().apply { title(Emotes.ERROR, title) this.description = description - color = Colors.RED + color = Colors.LIGHT_RED }.apply(builder) /** @@ -91,7 +92,7 @@ object Embeds { description: String? = null, builder: EmbedCreator = {} ): EmbedBuilder = - embed { + EmbedBuilder().apply { title(Emotes.WARN, title) this.description = description color = Colors.YELLOW @@ -107,12 +108,62 @@ object Embeds { description: String?, builder: EmbedCreator = {} ): EmbedBuilder = - embed { + EmbedBuilder().apply { title(Emotes.LOADING, title) this.description = description color = Colors.DARK_BUT_NOT_BLACK }.apply(builder) +/* + */ + /** + * Creates a help embed for [command]. + *//* + fun command(command: DescriptiveCommand, processor: CommandProcessor): EmbedBuilder { + val children = + processor.commands.filterValues { (it.aliasInfo as? AliasInfo.Child<*>)?.parent == command }.keys + return info("${command.name} - Hilfe", command.description) { + if (children.isNotEmpty()) { + field { + name = "Aliase" + value = children.joinToString("`, `", "`", "`") + } + } + field { + name = "Usage" + value = formatCommandUsage(command) + } + field { + name = "Permission" + value = command.permission.toString() + } +// addField("Permission", command.permission.name) +// val subCommands = command.registeredCommands.map(::formatSubCommandUsage) +// if (subCommands.isNotEmpty()) { +// addField("Sub commands", subCommands.joinToString("\n")) +// } + } + }*/ + + /*private fun formatCommandUsage(command: Command<*>): String { + val usage = command.arguments.joinToString(" ") { + if ("optional" in it.toString()) "[${it.name}]" else "<${it.name}>" + } + + return "!${command.name} $usage" + }*/ +// +// private fun formatSubCommandUsage(command: AbstractSubCommand): String { +// val builder = StringBuilder(Constants.firstPrefix) +// builder.append(' ').append(command.name).append(' ').append(command.usage.replace("\n", "\\n")) +// +// val prefix = " ${command.parent.name} " +// builder.insert(Constants.firstPrefix.length, prefix) +// builder.append(" - ").append(command.description) +// +// return builder.toString() +// } + private fun EmbedBuilder.title(emote: String, title: String) { this.title = "$emote $title" } @@ -142,4 +193,21 @@ object Embeds { embed = base } } -} + + +/* + */ + /** + * Responds to this command with an embed provided by [base] and applies [creator] to it + *//* + @Deprecated("Use sendResponse instead", ReplaceWith("sendResponse(base, creator)")) + suspend fun KordEvent.respondEmbed( + base: EmbedBuilder, + creator: suspend EmbedBuilder.() -> Unit = {} + ): Message { + return respond { + creator(base) + embed = base + } + }*/ +} \ No newline at end of file diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt index ae86d26..28e9f14 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt @@ -33,4 +33,4 @@ object Emotes { const val WARN: String = "<:warn:535832532365737987>" const val INFO: String = "<:info:535828529573789696>" const val SUCCESS: String = "<:success:535827110552666112>" -} +} \ No newline at end of file From 853e3c2d5100d5f7f6b3bf7979866e6b2bc3c097 Mon Sep 17 00:00:00 2001 From: Nicolas Edelmann Date: Sun, 6 Jun 2021 22:09:54 +0200 Subject: [PATCH 3/5] fix: change code style to pass style test --- .../kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt | 1 - src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt | 1 - src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt | 2 +- src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt | 6 ++---- src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt | 2 +- 5 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt index e93dd4b..434204e 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/InfoCommand.kt @@ -22,7 +22,6 @@ package dev.schlaubi.votebot.commands import dev.schlaubi.votebot.command.SingleCommand import dev.schlaubi.votebot.command.context.Context import dev.schlaubi.votebot.command.context.response.respond -import dev.schlaubi.votebot.command.context.response.respondEmbed import dev.schlaubi.votebot.util.Embeds object InfoCommand : SingleCommand() { diff --git a/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt b/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt index a047cae..15bbbc0 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/core/VoteBotImpl.kt @@ -19,7 +19,6 @@ package dev.schlaubi.votebot.core -import dev.kord.common.entity.PresenceStatus import dev.kord.core.Kord import dev.schlaubi.votebot.command.RegistrableCommand import dev.schlaubi.votebot.command.internal.CommandExecutor diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt index b0b0642..412928e 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt @@ -40,4 +40,4 @@ object Colors { val DARK_GREEN: Color = Color(39, 174, 96) val BLUE: Color = Color(52, 152, 219) val YELLOW: Color = Color(241, 196, 15) -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt index 727e78e..737ed03 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt @@ -21,11 +21,10 @@ package dev.schlaubi.votebot.util import dev.kord.core.behavior.MessageBehavior import dev.kord.core.behavior.channel.MessageChannelBehavior +import dev.kord.core.behavior.channel.createMessage import dev.kord.core.behavior.edit import dev.kord.core.entity.Message import dev.kord.rest.builder.message.EmbedBuilder -import dev.kord.core.behavior.channel.createMessage - /** * Defines a creator of an embed. @@ -194,7 +193,6 @@ object Embeds { } } - /* */ /** @@ -210,4 +208,4 @@ object Embeds { embed = base } }*/ -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt index 28e9f14..ae86d26 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Emotes.kt @@ -33,4 +33,4 @@ object Emotes { const val WARN: String = "<:warn:535832532365737987>" const val INFO: String = "<:info:535828529573789696>" const val SUCCESS: String = "<:success:535827110552666112>" -} \ No newline at end of file +} From 1cbbd8ae796cfe9cbbae0255b7ee589075235c80 Mon Sep 17 00:00:00 2001 From: Nicolas Edelmann Date: Sun, 6 Jun 2021 22:14:42 +0200 Subject: [PATCH 4/5] fix: remove comments and use global embed function --- .../commands/ClaimPermissionsCommand.kt | 2 +- .../votebot/commands/PermissionCommand.kt | 2 +- .../dev/schlaubi/votebot/util/Embeds.kt | 76 ++----------------- 3 files changed, 7 insertions(+), 73 deletions(-) diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt index 53bc092..4aae022 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/ClaimPermissionsCommand.kt @@ -36,7 +36,7 @@ object ClaimPermissionsCommand : SingleCommand() { override suspend fun execute(context: Context) { if (Permission.Administrator !in context.executor.asMember().getPermissions()) { - context.respond(Embeds.error("You need the `ADMINISTRATOR` permission to execute this command", description = null)) + context.respond(Embeds.error("You need the `ADMINISTRATOR` permission to execute this command")) return } diff --git a/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt b/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt index 2e7365a..25f0a58 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/commands/PermissionCommand.kt @@ -108,7 +108,7 @@ suspend fun doPermissions( val command = commands.firstOrNull { it.name == commandName } if (command == null) { - context.respond(Embeds.error("Unknown command", description = null)) + context.respond(Embeds.error("Unknown command")) return } diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt index 737ed03..a128d2b 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt @@ -43,7 +43,7 @@ object Embeds { * @see EmbedBuilder */ fun info(title: String, description: String? = null, builder: EmbedCreator = {}): EmbedBuilder = - EmbedBuilder().apply { + embed { title(Emotes.INFO, title) this.description = description color = Colors.BLUE @@ -59,7 +59,7 @@ object Embeds { description: String? = null, builder: EmbedCreator = {} ): EmbedBuilder = - EmbedBuilder().apply { + embed { title(Emotes.SUCCESS, title) this.description = description color = Colors.LIGHT_GREEN @@ -75,7 +75,7 @@ object Embeds { description: String? = null, builder: EmbedCreator = {} ): EmbedBuilder = - EmbedBuilder().apply { + embed { title(Emotes.ERROR, title) this.description = description color = Colors.LIGHT_RED @@ -91,7 +91,7 @@ object Embeds { description: String? = null, builder: EmbedCreator = {} ): EmbedBuilder = - EmbedBuilder().apply { + embed { title(Emotes.WARN, title) this.description = description color = Colors.YELLOW @@ -107,62 +107,12 @@ object Embeds { description: String?, builder: EmbedCreator = {} ): EmbedBuilder = - EmbedBuilder().apply { + embed { title(Emotes.LOADING, title) this.description = description color = Colors.DARK_BUT_NOT_BLACK }.apply(builder) -/* - */ - /** - * Creates a help embed for [command]. - *//* - fun command(command: DescriptiveCommand, processor: CommandProcessor): EmbedBuilder { - val children = - processor.commands.filterValues { (it.aliasInfo as? AliasInfo.Child<*>)?.parent == command }.keys - return info("${command.name} - Hilfe", command.description) { - if (children.isNotEmpty()) { - field { - name = "Aliase" - value = children.joinToString("`, `", "`", "`") - } - } - field { - name = "Usage" - value = formatCommandUsage(command) - } - field { - name = "Permission" - value = command.permission.toString() - } -// addField("Permission", command.permission.name) -// val subCommands = command.registeredCommands.map(::formatSubCommandUsage) -// if (subCommands.isNotEmpty()) { -// addField("Sub commands", subCommands.joinToString("\n")) -// } - } - }*/ - - /*private fun formatCommandUsage(command: Command<*>): String { - val usage = command.arguments.joinToString(" ") { - if ("optional" in it.toString()) "[${it.name}]" else "<${it.name}>" - } - - return "!${command.name} $usage" - }*/ -// -// private fun formatSubCommandUsage(command: AbstractSubCommand): String { -// val builder = StringBuilder(Constants.firstPrefix) -// builder.append(' ').append(command.name).append(' ').append(command.usage.replace("\n", "\\n")) -// -// val prefix = " ${command.parent.name} " -// builder.insert(Constants.firstPrefix.length, prefix) -// builder.append(" - ").append(command.description) -// -// return builder.toString() -// } - private fun EmbedBuilder.title(emote: String, title: String) { this.title = "$emote $title" } @@ -192,20 +142,4 @@ object Embeds { embed = base } } - -/* - */ - /** - * Responds to this command with an embed provided by [base] and applies [creator] to it - *//* - @Deprecated("Use sendResponse instead", ReplaceWith("sendResponse(base, creator)")) - suspend fun KordEvent.respondEmbed( - base: EmbedBuilder, - creator: suspend EmbedBuilder.() -> Unit = {} - ): Message { - return respond { - creator(base) - embed = base - } - }*/ } From 1887699621cff23273d3a124f01453513dc3e428 Mon Sep 17 00:00:00 2001 From: Nicolas Edelmann Date: Sun, 6 Jun 2021 22:20:07 +0200 Subject: [PATCH 5/5] feat: add new branding colors --- src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt | 12 +++++++++--- src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt index 412928e..3c7f8eb 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Colors.kt @@ -27,8 +27,15 @@ import dev.kord.common.Color @Suppress("KDocMissingDocumentation", "unused", "MagicNumber") object Colors { // Discord - val BLURLPLE: Color = Color(114, 137, 218) - val FULL_WHITE: Color = Color(255, 255, 255) + val BLURLPLE: Color = Color(88, 101, 242) + val GREEN: Color = Color(87, 242, 135) + val YELLOW: Color = Color(254, 231, 92) + val FUCHSIA: Color = Color(235, 69, 158) + val RED: Color = Color(237, 66, 69) + val WHITE: Color = Color(255, 255, 255) + val BLACK: Color = Color(0, 0, 0) + + // Old Discord Branding Colors val GREYPLE: Color = Color(153, 170, 181) val DARK_BUT_NOT_BLACK: Color = Color(44, 47, 51) val NOT_QUITE_BLACK: Color = Color(33, 39, 42) @@ -39,5 +46,4 @@ object Colors { val LIGHT_GREEN: Color = Color(46, 204, 113) val DARK_GREEN: Color = Color(39, 174, 96) val BLUE: Color = Color(52, 152, 219) - val YELLOW: Color = Color(241, 196, 15) } diff --git a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt index a128d2b..30b5242 100644 --- a/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt +++ b/src/main/kotlin/dev/schlaubi/votebot/util/Embeds.kt @@ -62,7 +62,7 @@ object Embeds { embed { title(Emotes.SUCCESS, title) this.description = description - color = Colors.LIGHT_GREEN + color = Colors.GREEN }.apply(builder) /** @@ -78,7 +78,7 @@ object Embeds { embed { title(Emotes.ERROR, title) this.description = description - color = Colors.LIGHT_RED + color = Colors.RED }.apply(builder) /**