From 67f3764c4ba92c6b4d9a32c794d10ac9f7417eca Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Fri, 24 Feb 2023 22:55:33 +0800 Subject: [PATCH 01/12] refactor: removed todo --- .../slash_command/commands/joke/getJoke/GetJoke.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java index 4f15201..f7dee3e 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java @@ -36,18 +36,16 @@ import tech.araopj.springpitzzahhbot.config.HttpConfig; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.stereotype.Component; - -import static java.awt.Color.YELLOW; import static java.time.LocalDateTime.now; import static java.lang.String.format; - -import java.time.ZoneId; +import static java.awt.Color.YELLOW; import java.util.function.Consumer; import java.util.function.Supplier; import java.net.http.HttpResponse; import static java.awt.Color.CYAN; import lombok.extern.slf4j.Slf4j; import java.io.IOException; +import java.time.ZoneId; import java.net.URI; @Slf4j @@ -82,7 +80,7 @@ private void process(CommandContext context){ log.info("Language: {}", language); String url = jokesService.createJokeRequestUrl(category, language); log.info("Url: {}", url); - final var REQUEST = httpConfig.httpBuilder() // TODO: create a uri builder + final var REQUEST = httpConfig.httpBuilder() .uri(URI.create(url)) .GET() .build(); From 6229d3e8a5955e534c4445a736b740232a994ded Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Fri, 24 Feb 2023 22:56:00 +0800 Subject: [PATCH 02/12] add: empty SubmitJoke Java record --- .../commands/joke/submitJoke/SubmitJoke.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java new file mode 100644 index 0000000..4fca4d6 --- /dev/null +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java @@ -0,0 +1,28 @@ +/* + * MIT License + * + * Copyright (c) 2022 pitzzahh + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.submitJoke; + +public record SubmitJoke() { +} From e1b2748860f8471c4f5ad2315a8b78ac375020a0 Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:02:57 +0800 Subject: [PATCH 03/12] add: JokesService import --- .../java/tech/araopj/springpitzzahhbot/service/BotService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/service/BotService.java b/src/main/java/tech/araopj/springpitzzahhbot/service/BotService.java index 7cd3555..fbad143 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/service/BotService.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/service/BotService.java @@ -1,7 +1,7 @@ package tech.araopj.springpitzzahhbot.service; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.confessions.service.ConfessionService; -import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.service.JokesService; +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.service.JokesService; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.game.service.GameService; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.confessions.Confession; import tech.araopj.springpitzzahhbot.config.moderation.service.MessageCheckerService; From 891f3183d2a28275da0df5cb6e544aa302499bba Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:03:42 +0800 Subject: [PATCH 04/12] add: JokesService import --- .../commands/slash_command/commands/joke/getJoke/GetJoke.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java index f7dee3e..bede862 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java @@ -24,7 +24,7 @@ package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke; -import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.service.JokesService; +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.service.JokesService; import tech.araopj.springpitzzahhbot.commands.slash_command.CommandContext; import tech.araopj.springpitzzahhbot.commands.slash_command.SlashCommand; import net.dv8tion.jda.api.interactions.commands.build.CommandData; From 79330c27b452fd2aa54c1aeafd4e50eb60cd49cc Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:38:36 +0800 Subject: [PATCH 05/12] add: joke java record --- .../commands/joke/entity/Joke.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/entity/Joke.java diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/entity/Joke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/entity/Joke.java new file mode 100644 index 0000000..e272732 --- /dev/null +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/entity/Joke.java @@ -0,0 +1,30 @@ +/* + * MIT License + * + * Copyright (c) 2022 pitzzahh + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.entity; + +import lombok.Builder; + +@Builder +public record Joke(String joke, String category, String language) { } From a076c50f890acd9573fd4122e3a71104f028f137 Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:39:10 +0800 Subject: [PATCH 06/12] add: method for creating json from objects --- .../joke/{getJoke => }/service/JokesService.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) rename src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/{getJoke => }/service/JokesService.java (88%) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/service/JokesService.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java similarity index 88% rename from src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/service/JokesService.java rename to src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java index e150d44..3961d48 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/service/JokesService.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java @@ -22,8 +22,9 @@ * SOFTWARE. */ -package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.service; +package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.service; +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.entity.Joke; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.entity.*; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import tech.araopj.springpitzzahhbot.config.HttpConfig; @@ -106,4 +107,15 @@ public String createJokeSubmitUrl() { return httpConfig.getJokeApiUrl().concat("submit"); } + public String createJokeSubmitBody(OptionMapping joke, OptionMapping category, OptionMapping language) { + var jokeObject = category != null ? Joke.builder() + .joke(joke.getAsString()) + .category(category.getAsString()) + .language(language.getAsString()) + .build() : Joke.builder() + .joke(joke.getAsString()) + .language(language.getAsString()) + .build(); + return new Gson().toJson(jokeObject); + } } From b7b3333b55172224126f047ef0a376dd8748468d Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:39:51 +0800 Subject: [PATCH 07/12] refactor: removed throws declaration for execute abstract method --- .../commands/slash_command/SlashCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommand.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommand.java index c5ed91b..e34b0c3 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommand.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommand.java @@ -26,8 +26,6 @@ import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.internal.interactions.CommandDataImpl; - -import java.io.IOException; import java.util.function.Consumer; import java.util.function.Supplier; @@ -38,7 +36,7 @@ public interface SlashCommand { * @return nothing. * @see Consumer */ - Consumer execute() throws InterruptedException, IOException; + Consumer execute(); /** * Supplies the name of the slash command. From 2d5232c19cbf14333d65fde96153dbca36d0672a Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:40:20 +0800 Subject: [PATCH 08/12] add: SubmitJoke command to map --- .../commands/slash_command/SlashCommandManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommandManager.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommandManager.java index 9bccdcc..7dcb1c3 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommandManager.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/SlashCommandManager.java @@ -25,7 +25,8 @@ package tech.araopj.springpitzzahhbot.commands.slash_command; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.confessions.service.ConfessionService; -import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.service.JokesService; +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.submitJoke.SubmitJoke; +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.service.JokesService; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.game.service.GameService; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.confessions.Confession; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.GetJoke; @@ -63,7 +64,8 @@ public SlashCommandManager( addCommands( new Confession(confessionService, commandsService, channelService, messageUtil), new Game(gameService, messageUtil), - new GetJoke(messageUtil, jokesService, httpConfig) + new GetJoke(messageUtil, jokesService, httpConfig), + new SubmitJoke(messageUtil, jokesService, httpConfig) ); } From dbdeb62c294c5ce13f7a06f4b7456a60ebfa8ac2 Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 12:42:46 +0800 Subject: [PATCH 09/12] add: business logic for submitting jokes --- .../commands/joke/submitJoke/SubmitJoke.java | 159 +++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java index 4fca4d6..7004b28 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java @@ -24,5 +24,162 @@ package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.submitJoke; -public record SubmitJoke() { +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.service.JokesService; +import tech.araopj.springpitzzahhbot.commands.slash_command.CommandContext; +import tech.araopj.springpitzzahhbot.commands.slash_command.SlashCommand; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.internal.interactions.CommandDataImpl; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import tech.araopj.springpitzzahhbot.utilities.MessageUtil; +import tech.araopj.springpitzzahhbot.config.HttpConfig; +import org.springframework.stereotype.Component; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; +import java.time.ZoneId; +import java.util.function.Consumer; +import java.util.function.Supplier; +import lombok.extern.slf4j.Slf4j; +import static java.awt.Color.CYAN; +import static java.awt.Color.YELLOW; +import static java.lang.String.format; +import static java.time.LocalDateTime.now; + +@Slf4j +@Component +public record SubmitJoke( + MessageUtil messageUtil, + JokesService jokesService, + HttpConfig httpConfig +) implements SlashCommand { + + /** + * Executes a {@code SlashCommand} + * + * @return nothing. + * @see Consumer + */ + @Override + public Consumer execute() { + return this::process; + } + + /** + * Contains the process to be executed. + * + * @param context the command context containing the information about the command. + */ + private void process(CommandContext context) { + final var category = context.getEvent().getOption("category"); + log.info("Category: {}", category); + + final var language = context.getEvent().getOption("language"); + log.info("Language: {}", language); + + final var joke = context.getEvent().getOption("joke"); + log.info("Joke: {}", joke); + + String url = jokesService.createJokeSubmitUrl(); + + log.info("Url: {}", url); + String jokeSubmitBody = jokesService.createJokeSubmitBody(category, language, joke); + log.info("Joke submit body: {}", jokeSubmitBody); + final var REQUEST = httpConfig.httpBuilder() + .uri(URI.create(url)) + .POST(HttpRequest.BodyPublishers.ofString(jokeSubmitBody)) + .build(); + + final HttpResponse RESPONSE; + + try { + RESPONSE = httpConfig.httpClient().send(REQUEST, HttpResponse.BodyHandlers.ofString()); + + log.info("Response from joke api: {}", RESPONSE.body()); + } catch (IOException | InterruptedException e) { + log.error("Error while sending request to joke api", e); + throw new RuntimeException(e); + } + + if (RESPONSE.statusCode() == 200) { + messageUtil.getEmbedBuilder() + .clear() + .clearFields() + .setColor(CYAN) + .setTitle(RESPONSE.body()) + .setDescription("Your joke has been sent to the joke api. It will be reviewed and added to the joke api if it is good enough.") + .setTimestamp(now(ZoneId.systemDefault())) + .setFooter( + format("Created by %s", context.getGuild().getJDA().getSelfUser().getAsTag()), + context.getGuild().getJDA().getSelfUser().getAvatarUrl() + ); + context.getEvent() + .getInteraction() + .replyEmbeds(messageUtil.getEmbedBuilder().build()) + .queue(); + } else { + messageUtil.getEmbedBuilder() + .clear() + .clearFields() + .setColor(YELLOW) + .setTitle("Failed to send joke to joke api") + .setDescription("I couldn't send your request at the momentšŸ˜¢.") + .setTimestamp(now(ZoneId.systemDefault())) + .setFooter( + format("Created by %s", context.getGuild().getJDA().getSelfUser().getAsTag()), + context.getGuild().getJDA().getSelfUser().getAvatarUrl() + ); + context.getEvent() + .getInteraction() + .replyEmbeds(messageUtil.getEmbedBuilder().build()) + .queue(); + } + } + + /** + * Supplies the name of the slash command. + * + * @return a {@code Supplier}. + * @see Supplier + */ + @Override + public Supplier name() { + return () -> "submit-joke"; + } + + /** + * Supplies the command data of a slash command. + * + * @return a {@code Supplier}. + * @see Supplier + * @see CommandData + */ + @Override + public Supplier getCommandData() { + return () -> new CommandDataImpl( + name().get(), + description().get()) + .addOptions( + new OptionData(OptionType.STRING, "category", "Category of the joke", false) + .setDescription("Select your desired joke category") + .addChoices(jokesService.getCategories()), + new OptionData(OptionType.STRING, "language", "Language of the joke", false) + .setDescription("Select your desired joke language") + .addChoices(jokesService.getLanguages()), + new OptionData(OptionType.STRING, "joke", "The joke you want to submit", false) + .setDescription("Enter your joke") + ); + } + + /** + * Supplies the description of a slash command. + * + * @return a {code Supplier} containing the description of the command. + * @see Supplier + */ + @Override + public Supplier description() { + return () -> "Submit a joke to the bot"; + } } From d62755327b7275d855b01b64b6187dd9e14005fd Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 13:08:16 +0800 Subject: [PATCH 10/12] refactor: removed explicit logging and declared variables --- .../commands/joke/getJoke/GetJoke.java | 13 +++----- .../commands/joke/submitJoke/SubmitJoke.java | 32 ++++++++----------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java index bede862..1a4ea24 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/getJoke/GetJoke.java @@ -72,14 +72,11 @@ public Consumer execute() { * @param context the command context containing the information about the command. */ private void process(CommandContext context){ - - final var category = context.getEvent().getOption("category"); - log.info("Category: {}", category); - - final var language = context.getEvent().getOption("language"); - log.info("Language: {}", language); - String url = jokesService.createJokeRequestUrl(category, language); - log.info("Url: {}", url); + var url = jokesService.createJokeRequestUrl( + context.getEvent().getOption("category"), + context.getEvent().getOption("language") + ); + log.info("Get Joke url: {}", url); final var REQUEST = httpConfig.httpBuilder() .uri(URI.create(url)) .GET() diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java index 7004b28..600afea 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/submitJoke/SubmitJoke.java @@ -72,22 +72,19 @@ public Consumer execute() { * @param context the command context containing the information about the command. */ private void process(CommandContext context) { - final var category = context.getEvent().getOption("category"); - log.info("Category: {}", category); - final var language = context.getEvent().getOption("language"); - log.info("Language: {}", language); + var url = jokesService.createJokeSubmitUrl(); - final var joke = context.getEvent().getOption("joke"); - log.info("Joke: {}", joke); - - String url = jokesService.createJokeSubmitUrl(); - - log.info("Url: {}", url); - String jokeSubmitBody = jokesService.createJokeSubmitBody(category, language, joke); - log.info("Joke submit body: {}", jokeSubmitBody); + log.info("Submit Joke url: {}", url); + var jokeSubmitBody = jokesService.createJokeSubmitBody( + context.getEvent().getOption("joke"), + context.getEvent().getOption("category"), + context.getEvent().getOption("language") + ); + log.info("Submit Joke body: {}", jokeSubmitBody); final var REQUEST = httpConfig.httpBuilder() .uri(URI.create(url)) + .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jokeSubmitBody)) .build(); @@ -95,7 +92,6 @@ private void process(CommandContext context) { try { RESPONSE = httpConfig.httpClient().send(REQUEST, HttpResponse.BodyHandlers.ofString()); - log.info("Response from joke api: {}", RESPONSE.body()); } catch (IOException | InterruptedException e) { log.error("Error while sending request to joke api", e); @@ -161,13 +157,13 @@ public Supplier getCommandData() { name().get(), description().get()) .addOptions( - new OptionData(OptionType.STRING, "category", "Category of the joke", false) - .setDescription("Select your desired joke category") + new OptionData(OptionType.STRING, "category", "Category of the joke", true) + .setDescription("Select the category of your joke") .addChoices(jokesService.getCategories()), - new OptionData(OptionType.STRING, "language", "Language of the joke", false) - .setDescription("Select your desired joke language") + new OptionData(OptionType.STRING, "language", "Language of the joke", true) + .setDescription("Select the language of your joke") .addChoices(jokesService.getLanguages()), - new OptionData(OptionType.STRING, "joke", "The joke you want to submit", false) + new OptionData(OptionType.STRING, "joke", "The joke you to submit", true) .setDescription("Enter your joke") ); } From 0aa2254e1c1c2c384da1ea5221b82828a2a21a7a Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 13:27:39 +0800 Subject: [PATCH 11/12] update: badges --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a8eebeb..d4f0a24 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,19 @@ ___ My Discord bot is built using Java Discord API with Spring framework integration. It contains several features, including: ___ -![GitHub Issues](https://img.shields.io/github/issues/pitzzahh/spring-pitzzahh-bot) -![Forks](https://img.shields.io/github/forks/pitzzahh/spring-pitzzahh-bot) -![Stars](https://img.shields.io/github/stars/pitzzahh/spring-pitzzahh-bot) -![License](https://img.shields.io/github/license/pitzzahh/spring-pitzzahh-bot) -![Forks](https://img.shields.io/github/forks/pitzzahh/spring-pitzzahh-bot) -![Stars](https://img.shields.io/github/stars/pitzzahh/spring-pitzzahh-bot) -![Contributors](https://img.shields.io/github/contributors/pitzzahh/spring-pitzzahh-bot) -![Last Commit](https://img.shields.io/github/last-commit/pitzzahh/spring-pitzzahh-bot) -![Code size](https://img.shields.io/github/languages/code-size/pitzzahh/spring-pitzzahh-bot) -![Top language](https://img.shields.io/github/languages/top/pitzzahh/spring-pitzzahh-bot) -![Languages count](https://img.shields.io/github/languages/count/pitzzahh/spring-pitzzahh-bot) -![Repo size](https://img.shields.io/github/repo-size/pitzzahh/spring-pitzzahh-bot) -![Lines of code](https://img.shields.io/tokei/lines/github/pitzzahh/spring-pitzzahh-bot?label=lines%20of%20code) +![GitHub Issues](https://img.shields.io/github/issues/pitzzahh/pitzzahh-bot) +![Forks](https://img.shields.io/github/forks/pitzzahh/pitzzahh-bot) +![Stars](https://img.shields.io/github/stars/pitzzahh/pitzzahh-bot) +![License](https://img.shields.io/github/license/pitzzahh/pitzzahh-bot) +![Forks](https://img.shields.io/github/forks/pitzzahh/pitzzahh-bot) +![Stars](https://img.shields.io/github/stars/pitzzahh/pitzzahh-bot) +![Contributors](https://img.shields.io/github/contributors/pitzzahh/pitzzahh-bot) +![Last Commit](https://img.shields.io/github/last-commit/pitzzahh/pitzzahh-bot) +![Code size](https://img.shields.io/github/languages/code-size/pitzzahh/pitzzahh-bot) +![Top language](https://img.shields.io/github/languages/top/pitzzahh/pitzzahh-bot) +![Languages count](https://img.shields.io/github/languages/count/pitzzahh/pitzzahh-bot) +![Repo size](https://img.shields.io/github/repo-size/pitzzahh/pitzzahh-bot) +![Lines of code](https://img.shields.io/tokei/lines/github/pitzzahh/pitzzahh-bot?label=lines%20of%20code) ___ - User Verification: This feature allows users to verify their account before joining the server, ensuring that only authorized users can access the server. From f683a1a74ad76577bcb540246b4d6594b12a3c56 Mon Sep 17 00:00:00 2001 From: pitzzahh Date: Sat, 25 Feb 2023 13:29:37 +0800 Subject: [PATCH 12/12] refactor: re-ordered import statement --- .../slash_command/commands/joke/service/JokesService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java index 3961d48..c5b1238 100644 --- a/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java +++ b/src/main/java/tech/araopj/springpitzzahhbot/commands/slash_command/commands/joke/service/JokesService.java @@ -24,8 +24,8 @@ package tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.service; -import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.entity.Joke; import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.getJoke.entity.*; +import tech.araopj.springpitzzahhbot.commands.slash_command.commands.joke.entity.Joke; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import tech.araopj.springpitzzahhbot.config.HttpConfig; import java.util.concurrent.ExecutionException;