From 843bb34fb4dc027567c4a29f1dd1ba046fa11901 Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 7 Jul 2024 01:23:20 +0100 Subject: [PATCH] add paste command --- .../bat/features/base/BaseFeature.java | 2 + .../commands/utility/PastebinCommand.java | 49 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/main/java/cc/fascinated/bat/features/base/commands/utility/PastebinCommand.java diff --git a/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java b/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java index 8e79f62..e11e9dc 100644 --- a/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java +++ b/src/main/java/cc/fascinated/bat/features/base/BaseFeature.java @@ -13,6 +13,7 @@ import cc.fascinated.bat.features.base.commands.server.MemberCountCommand; import cc.fascinated.bat.features.base.commands.server.PremiumCommand; import cc.fascinated.bat.features.base.commands.server.channel.ChannelCommand; import cc.fascinated.bat.features.base.commands.server.feature.FeatureCommand; +import cc.fascinated.bat.features.base.commands.utility.PastebinCommand; import cc.fascinated.bat.service.CommandService; import lombok.NonNull; import org.springframework.beans.factory.annotation.Autowired; @@ -44,5 +45,6 @@ public class BaseFeature extends Feature { super.registerCommand(commandService, context.getBean(EightBallCommand.class)); super.registerCommand(commandService, context.getBean(LookupUserCommand.class)); super.registerCommand(commandService, context.getBean(PPSizeCommand.class)); + super.registerCommand(commandService, context.getBean(PastebinCommand.class)); } } diff --git a/src/main/java/cc/fascinated/bat/features/base/commands/utility/PastebinCommand.java b/src/main/java/cc/fascinated/bat/features/base/commands/utility/PastebinCommand.java new file mode 100644 index 0000000..828ff33 --- /dev/null +++ b/src/main/java/cc/fascinated/bat/features/base/commands/utility/PastebinCommand.java @@ -0,0 +1,49 @@ +package cc.fascinated.bat.features.base.commands.utility; + +import cc.fascinated.bat.command.BatCommand; +import cc.fascinated.bat.command.CommandInfo; +import cc.fascinated.bat.common.EmbedDescriptionBuilder; +import cc.fascinated.bat.common.EmbedUtils; +import cc.fascinated.bat.common.PasteUtils; +import cc.fascinated.bat.model.BatGuild; +import cc.fascinated.bat.model.BatUser; +import lombok.NonNull; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import org.springframework.stereotype.Component; + +/** + * @author Fascinated (fascinated7) + */ +@Component +@CommandInfo( + name = "pastebin", + description = "Uploads the given text to Paste", + userInstall = true +) +public class PastebinCommand extends BatCommand { + public PastebinCommand() { + super.addOptions( + new OptionData(OptionType.STRING, "text", "The text to upload to Paste", true) + ); + } + + @Override + public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { + OptionMapping textOption = event.getOption("text"); + assert textOption != null; + String text = textOption.getAsString(); + + // Upload the text to pastebin + String url = PasteUtils.uploadPaste(text).getUrl(); + event.replyEmbeds(EmbedUtils.successEmbed() + .setDescription(new EmbedDescriptionBuilder("The text has been uploaded to Paste!") + .appendLine("URL: %s".formatted(url), true) + .build()) + .build()).queue(); + } +}