From 6abf50e413729612570cc8efbedd90be1a90585a Mon Sep 17 00:00:00 2001 From: RealMangoRage <64402114+RealMangorage@users.noreply.github.com> Date: Wed, 22 May 2024 14:31:18 -0700 Subject: [PATCH] Fixed up a minor few things... --- build.gradle | 2 +- .../mangorage/mangobot/MangoBotPlugin.java | 6 +- .../modules/actions/TrashButtonAction.java | 59 +++++++++++++++++++ .../mangobot/modules/tricks/TrickCommand.java | 17 +----- 4 files changed, 62 insertions(+), 22 deletions(-) create mode 100644 src/main/java/org/mangorage/mangobot/modules/actions/TrashButtonAction.java diff --git a/build.gradle b/build.gradle index 0cd9015..3bb8af9 100644 --- a/build.gradle +++ b/build.gradle @@ -67,7 +67,7 @@ dependencies { testImplementation 'org.junit.jupiter:junit-jupiter' installer('org.mangorage:installer:3.0.22') - bot('org.mangorage:mangobot:10.0.399') + bot('org.mangorage:mangobot:+') library('org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5') library('org.kohsuke:github-api:1.321') diff --git a/src/main/java/org/mangorage/mangobot/MangoBotPlugin.java b/src/main/java/org/mangorage/mangobot/MangoBotPlugin.java index 29a8439..7652414 100644 --- a/src/main/java/org/mangorage/mangobot/MangoBotPlugin.java +++ b/src/main/java/org/mangorage/mangobot/MangoBotPlugin.java @@ -29,15 +29,11 @@ import static org.mangorage.mangobot.core.BotPermissions.PREFIX_ADMIN; import static org.mangorage.mangobot.core.BotPermissions.TRICK_ADMIN; -import java.awt.*; import java.nio.file.Path; import java.util.Date; import java.util.EnumSet; import java.util.List; import java.util.Scanner; -import java.util.function.Consumer; - -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.channel.ChannelType; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.mangorage.basicutils.config.Config; @@ -48,6 +44,7 @@ import org.mangorage.mangobot.core.BotEventListener; import org.mangorage.mangobot.core.BotPermissions; import org.mangorage.mangobot.core.Listeners; +import org.mangorage.mangobot.modules.actions.TrashButtonAction; import org.mangorage.mangobot.modules.basic.commands.GetEmbedsCommand; import org.mangorage.mangobot.modules.basic.commands.HelpCommand; import org.mangorage.mangobot.modules.basic.commands.InfoCommand; @@ -90,7 +87,6 @@ import org.mangorage.mangobotapi.core.events.LoadEvent; import org.mangorage.mangobotapi.core.events.SaveEvent; import org.mangorage.mangobotapi.core.modules.action.ButtonActionRegistry; -import org.mangorage.mangobotapi.core.modules.action.TrashButtonAction; import org.mangorage.mangobotapi.core.plugin.api.CorePlugin; import org.mangorage.mangobotapi.core.plugin.api.PluginMessageEvent; import org.mangorage.mangobotapi.core.plugin.impl.Plugin; diff --git a/src/main/java/org/mangorage/mangobot/modules/actions/TrashButtonAction.java b/src/main/java/org/mangorage/mangobot/modules/actions/TrashButtonAction.java new file mode 100644 index 0000000..0e91d54 --- /dev/null +++ b/src/main/java/org/mangorage/mangobot/modules/actions/TrashButtonAction.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024. MangoRage + * + * 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 NONINFRINGEMENT. + * 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 org.mangorage.mangobot.modules.actions; + +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; +import net.dv8tion.jda.api.interactions.components.buttons.Button; +import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; +import org.mangorage.mangobotapi.core.modules.action.ButtonAction; + +public class TrashButtonAction extends ButtonAction { + + public TrashButtonAction() { + super("trash", "Delete"); + } + + public Button createForUser(User user) { + return create(ButtonStyle.DANGER, user.getId()); + } + + @Override + public boolean onClick(ButtonInteractionEvent event) { + if (event.getComponent().getId() == null) return false; + + if (event.getComponent().getId().startsWith(getId() + ":")) { + var list = event.getComponent().getId().split(":"); + var clicked = event.getUser().getId(); + var msg = event.getMessage(); + + if (list[1].equals(clicked)) { + msg.delete().queue(); + event.deferReply(true).setContent("Deleted Message!").queue(); + } else { + event.deferReply(true).setContent("No permission to delete message!").queue(); + } + } + return false; + } +} diff --git a/src/main/java/org/mangorage/mangobot/modules/tricks/TrickCommand.java b/src/main/java/org/mangorage/mangobot/modules/tricks/TrickCommand.java index e8b5001..a611ecb 100644 --- a/src/main/java/org/mangorage/mangobot/modules/tricks/TrickCommand.java +++ b/src/main/java/org/mangorage/mangobot/modules/tricks/TrickCommand.java @@ -8,17 +8,11 @@ import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.components.ActionRow; -import net.dv8tion.jda.api.interactions.components.Component; import net.dv8tion.jda.api.interactions.components.buttons.Button; -import net.dv8tion.jda.api.interactions.components.buttons.ButtonStyle; -import net.dv8tion.jda.api.interactions.components.selections.StringSelectMenu; import net.dv8tion.jda.api.interactions.components.text.TextInput; import net.dv8tion.jda.api.interactions.components.text.TextInputStyle; import net.dv8tion.jda.api.interactions.modals.Modal; -import net.dv8tion.jda.api.utils.FileUpload; import net.dv8tion.jda.api.utils.MarkdownSanitizer; -import net.dv8tion.jda.api.utils.MarkdownUtil; -import net.dv8tion.jda.internal.interactions.component.ButtonImpl; import org.jetbrains.annotations.NotNull; import org.mangorage.basicutils.LogHelper; import org.mangorage.basicutils.TaskScheduler; @@ -27,6 +21,7 @@ import org.mangorage.jdautils.command.Command; import org.mangorage.jdautils.command.CommandOption; import org.mangorage.mangobot.MangoBotPlugin; +import org.mangorage.mangobot.modules.actions.TrashButtonAction; import org.mangorage.mangobotapi.core.commands.Arguments; import org.mangorage.mangobotapi.core.commands.CommandAlias; import org.mangorage.mangobotapi.core.commands.CommandResult; @@ -36,24 +31,14 @@ import org.mangorage.mangobotapi.core.events.DiscordEvent; import org.mangorage.mangobotapi.core.events.LoadEvent; import org.mangorage.mangobotapi.core.events.SaveEvent; -import org.mangorage.mangobotapi.core.events.discord.DButtonInteractionEvent; -import org.mangorage.mangobotapi.core.events.discord.DModalInteractionEvent; -import org.mangorage.mangobotapi.core.modules.action.TrashButtonAction; import org.mangorage.mangobotapi.core.plugin.api.CorePlugin; import org.mangorage.mangobotapi.core.util.MessageSettings; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.lang.runtime.SwitchBootstraps; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; -import java.util.stream.Stream; - public class TrickCommand implements IBasicCommand { private static final boolean ALLOW_SCRIPT_TRICKS = true; private final CorePlugin plugin;