From fffb7d890c6fb22d5017b74f8de9185dfbc1cfcb Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 18:58:37 -0300 Subject: [PATCH 1/8] =?UTF-8?q?=F0=9F=9A=80=20defer=20interaction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elements/effects/EffDeferInteraction.java | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java diff --git a/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java b/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java new file mode 100644 index 00000000..829612ac --- /dev/null +++ b/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java @@ -0,0 +1,78 @@ +package info.itsthesky.disky.elements.effects; + +import ch.njol.skript.Skript; +import ch.njol.skript.doc.Description; +import ch.njol.skript.doc.Name; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import info.itsthesky.disky.DiSky; +import info.itsthesky.disky.api.events.specific.InteractionEvent; +import info.itsthesky.disky.api.skript.WaiterEffect; +import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; +import org.bukkit.event.Event; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; + +@Name(" ") +@Description({""}) + +public class EffDeferInteraction extends WaiterEffect { + + static { + Skript.registerEffect( + EffDeferIntreaction.class, + "defer the interaction [and wait [(1¦silently)]]" + ); + } + + private boolean isInInteraction; + private boolean shouldwait; + private boolean isEphemeral; + + + @Override + public boolean initEffect(Expression[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { + if ((!(Arrays.asList(info.itsthesky.disky3.api.skript.adapter.SkriptAdapter.getInstance().getCurrentEvents()[0].getInterfaces()).contains(InteractionEvent.class)))) { + Skript.error("The defer interaction effect can only be used in interaction events."); + return false; + } + isInInteraction = containsInterfaces(InteractionEvent.class); + shouldwait = parseResult.expr.contains("and wait"); + boolean isEphemeral = parseResult.mark == 1; + + } + + @Override + public void runEffect(Event e) { + if (isInInteraction) { + + final IReplyCallback event = (IReplyCallback) ((InteractionEvent) e).getInteractionEvent(); + if (anyNull(event)) { + restart(); + return; + } + + if (shouldwait) { + event.deferReply(isEphemeral).queue((v -> restart()), ex -> { + DiSky.getErrorHandler().exception(event, ex); + restart()) + else { + event.deferEdit().queue((v -> restart(), ex -> { + DiSky.getErrorHandler().exception(event, ex); + restart();); + }); + } + }); + + + } + } + + @Override + public @NotNull String toString(@Nullable Event e, boolean debug) { + return "defer the interaction"; + } +} From a09b088cd5b73f089164bc8d2761d30f48961770 Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 19:04:09 -0300 Subject: [PATCH 2/8] =?UTF-8?q?=F0=9F=9A=80=20hook=20of=20the=20interactio?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../itsthesky/disky/elements/effects/EffDeferInteraction.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java b/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java index 829612ac..087b5a9e 100644 --- a/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java +++ b/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java @@ -9,6 +9,7 @@ import info.itsthesky.disky.DiSky; import info.itsthesky.disky.api.events.specific.InteractionEvent; import info.itsthesky.disky.api.skript.WaiterEffect; +import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; import org.bukkit.event.Event; import org.jetbrains.annotations.NotNull; @@ -50,7 +51,8 @@ public void runEffect(Event e) { if (isInInteraction) { final IReplyCallback event = (IReplyCallback) ((InteractionEvent) e).getInteractionEvent(); - if (anyNull(event)) { + final InteractionHook hook = event.getHook(); //need to store that in a variable that will be used in another class + if (anyNull(event, hook)) { restart(); return; } From 9e1698536d022716c3e65288da790c5f956b9a26 Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 21:04:45 -0300 Subject: [PATCH 3/8] =?UTF-8?q?=F0=9F=9A=80=20delete=20duplicated=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elements/effects/EffDeferInteraction.java | 80 ------------------- 1 file changed, 80 deletions(-) delete mode 100644 src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java diff --git a/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java b/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java deleted file mode 100644 index 087b5a9e..00000000 --- a/src/main/java/info/itsthesky/disky/elements/effects/EffDeferInteraction.java +++ /dev/null @@ -1,80 +0,0 @@ -package info.itsthesky.disky.elements.effects; - -import ch.njol.skript.Skript; -import ch.njol.skript.doc.Description; -import ch.njol.skript.doc.Name; -import ch.njol.skript.lang.Expression; -import ch.njol.skript.lang.SkriptParser; -import ch.njol.util.Kleenean; -import info.itsthesky.disky.DiSky; -import info.itsthesky.disky.api.events.specific.InteractionEvent; -import info.itsthesky.disky.api.skript.WaiterEffect; -import net.dv8tion.jda.api.interactions.InteractionHook; -import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; -import org.bukkit.event.Event; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; - -@Name(" ") -@Description({""}) - -public class EffDeferInteraction extends WaiterEffect { - - static { - Skript.registerEffect( - EffDeferIntreaction.class, - "defer the interaction [and wait [(1¦silently)]]" - ); - } - - private boolean isInInteraction; - private boolean shouldwait; - private boolean isEphemeral; - - - @Override - public boolean initEffect(Expression[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) { - if ((!(Arrays.asList(info.itsthesky.disky3.api.skript.adapter.SkriptAdapter.getInstance().getCurrentEvents()[0].getInterfaces()).contains(InteractionEvent.class)))) { - Skript.error("The defer interaction effect can only be used in interaction events."); - return false; - } - isInInteraction = containsInterfaces(InteractionEvent.class); - shouldwait = parseResult.expr.contains("and wait"); - boolean isEphemeral = parseResult.mark == 1; - - } - - @Override - public void runEffect(Event e) { - if (isInInteraction) { - - final IReplyCallback event = (IReplyCallback) ((InteractionEvent) e).getInteractionEvent(); - final InteractionHook hook = event.getHook(); //need to store that in a variable that will be used in another class - if (anyNull(event, hook)) { - restart(); - return; - } - - if (shouldwait) { - event.deferReply(isEphemeral).queue((v -> restart()), ex -> { - DiSky.getErrorHandler().exception(event, ex); - restart()) - else { - event.deferEdit().queue((v -> restart(), ex -> { - DiSky.getErrorHandler().exception(event, ex); - restart();); - }); - } - }); - - - } - } - - @Override - public @NotNull String toString(@Nullable Event e, boolean debug) { - return "defer the interaction"; - } -} From 8dca86b0e92d8e4cea5a39ef4f9ad95fd26ab0dc Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 21:05:33 -0300 Subject: [PATCH 4/8] =?UTF-8?q?=F0=9F=9A=80=20finish=20interaction=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/EffDeferInteraction.java | 49 ++++++++++++------- .../disky/elements/effects/ReplyWith.java | 10 +++- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java b/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java index c64c306c..cc00e5f1 100644 --- a/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java +++ b/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java @@ -20,20 +20,41 @@ import org.jetbrains.annotations.Nullable; @Name("Defer Interaction") -@Description({"Only usable in interaction event, currently button click & dropdown update event!", -"\nThis will force the interaction to be acknowledge, sending a success message to Discord.", +@Description({"Only usable in interaction event, currently button click/dropdown update/modal event!", +"\nThis will force the interaction to be acknowledge, you have 3 seconds to do so, the effect will send a success message to Discord or hold the interaction to send a message later.", "\nKeep in mind that replying in an interaction event will automatically defer the interaction, and therefore you don't need to defer it.", +"\nIf you need to wait more than 3 seconds use the and wait pattern", "\nAn interaction can only be deferred once!"}) -@Examples("defer the interaction") +@Examples("defer the interaction [and wait]") public class EffDeferInteraction extends Effect { static { Skript.registerEffect( EffDeferInteraction.class, - "(acknowledge|defer) [the] interaction" + "(acknowledge|defer) [the] interaction [and wait (1¦silently)]" ); } + private NodeInformation node; + + @Override + public boolean init(Expression @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { + + if (!EasyElement.containsInterfaces(InteractionEvent.class)) { + Skript.error("The defer interaction effect can only be used in interaction events!"); + return false; + } + + node = new NodeInformation(); + + isEphemeral = parseResult.mark == 1; + shouldwait = parseResult.expr.contains("and wait"); + + return true; + } + + private boolean isEphemeral; + private boolean shouldwait; @Override protected void execute(@NotNull Event e) { @@ -42,11 +63,15 @@ protected void execute(@NotNull Event e) { if (event instanceof GenericComponentInteractionCreateEvent) { GenericComponentInteractionCreateEvent clickEvent = (GenericComponentInteractionCreateEvent) event; - clickEvent.deferEdit().queue(null, ex -> DiSky.getErrorHandler().exception(e, ex)); } else if (event instanceof ModalInteractionEvent) { ModalInteractionEvent clickEvent = (ModalInteractionEvent) event; + + if (shouldwait) { + clickEvent.deferReply(isEphemeral).queue(null, ex -> DiSky.getErrorHandler().exception(e, ex)); + return; + } clickEvent.deferEdit().queue(null, ex -> DiSky.getErrorHandler().exception(e, ex)); } @@ -58,18 +83,4 @@ protected void execute(@NotNull Event e) { return "defer the interaction"; } - private NodeInformation node; - - @Override - public boolean init(Expression @NotNull [] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { - - if (!EasyElement.containsInterfaces(InteractionEvent.class)) { - Skript.error("The defer interaction effect can only be used in interaction events!"); - return false; - } - - node = new NodeInformation(); - - return true; - } } diff --git a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java index 85871476..27bb7175 100644 --- a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java +++ b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java @@ -18,6 +18,7 @@ import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.requests.restaction.MessageAction; @@ -74,6 +75,7 @@ public void runEffect(Event e, Bot bot) { if (isInInteraction) { final IReplyCallback event = (IReplyCallback) ((InteractionEvent) e).getInteractionEvent(); + final InteractionHook hook = event.getHook(); final Object rawMessage = parseSingle(exprMessage, e, null); final MessageBuilder message = JDAUtils.constructMessage(rawMessage); final List rows = Arrays.asList(parseList(exprComponents, e, new ComponentRow[0])); @@ -86,7 +88,13 @@ public void runEffect(Event e, Bot bot) { .stream() .map(ComponentRow::asActionRow) .collect(Collectors.toList()); - + if (!hook.isExpired()) { + hook.editOriginal(message.build()) + .queue(v -> restart(), ex -> { + DiSky.getErrorHandler().exception(e, ex); + restart(); + }); + } event.reply(message.build()) .addActionRows(formatted) .setEphemeral(hidden) From 5bea13a7ed9c1a96bef88371d884d785315b4616 Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 21:16:01 -0300 Subject: [PATCH 5/8] =?UTF-8?q?=F0=9F=9A=80=20minor=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disky/elements/components/EffDeferInteraction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java b/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java index cc00e5f1..a759afde 100644 --- a/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java +++ b/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java @@ -25,7 +25,8 @@ "\nKeep in mind that replying in an interaction event will automatically defer the interaction, and therefore you don't need to defer it.", "\nIf you need to wait more than 3 seconds use the and wait pattern", "\nAn interaction can only be deferred once!"}) -@Examples("defer the interaction [and wait]") +@Examples({"defer the interaction", +"\n defer the interaction and wait"}) public class EffDeferInteraction extends Effect { static { From a9d86e1962affe849a948cd157df7425c12d9bab Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 21:16:38 -0300 Subject: [PATCH 6/8] =?UTF-8?q?=F0=9F=9A=80=20minor=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disky/elements/components/EffDeferInteraction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java b/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java index a759afde..f90bc581 100644 --- a/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java +++ b/src/main/java/info/itsthesky/disky/elements/components/EffDeferInteraction.java @@ -26,7 +26,8 @@ "\nIf you need to wait more than 3 seconds use the and wait pattern", "\nAn interaction can only be deferred once!"}) @Examples({"defer the interaction", -"\n defer the interaction and wait"}) +"\n defer the interaction and wait", +"\n defer the interaction and wait silently"}) public class EffDeferInteraction extends Effect { static { From adc28c6d9e3e64454cd5ed0de606d9c5d0863a99 Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Fri, 25 Mar 2022 22:16:21 -0300 Subject: [PATCH 7/8] =?UTF-8?q?=F0=9F=9A=80=20update=20'reply=20with'=20wi?= =?UTF-8?q?th=20master=20+=20my=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disky/elements/effects/ReplyWith.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java index 27bb7175..27b88478 100644 --- a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java +++ b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java @@ -67,34 +67,37 @@ public boolean initEffect(Expression[] expressions, int i, Kleenean kleenean, exprReference = (Expression) expressions[2]; mentioning = (parseResult.mark & 1) != 1; - return validateVariable(expressions[2], false, true); + return validateVariable(expressions[3], false, true); } @Override public void runEffect(Event e, Bot bot) { + + final List rows = Arrays.asList(parseList(exprComponents, e, new ComponentRow[0])); + final List formatted = rows + .stream() + .map(ComponentRow::asActionRow) + .collect(Collectors.toList()); + if (isInInteraction) { final IReplyCallback event = (IReplyCallback) ((InteractionEvent) e).getInteractionEvent(); final InteractionHook hook = event.getHook(); final Object rawMessage = parseSingle(exprMessage, e, null); final MessageBuilder message = JDAUtils.constructMessage(rawMessage); - final List rows = Arrays.asList(parseList(exprComponents, e, new ComponentRow[0])); if (anyNull(event, rawMessage, message)) { restart(); return; } - final List formatted = rows - .stream() - .map(ComponentRow::asActionRow) - .collect(Collectors.toList()); if (!hook.isExpired()) { hook.editOriginal(message.build()) - .queue(v -> restart(), ex -> { - DiSky.getErrorHandler().exception(e, ex); - restart(); - }); + .queue(v -> restart(), ex -> { + DiSky.getErrorHandler().exception(e, ex); + restart(); + }); } + event.reply(message.build()) .addActionRows(formatted) .setEphemeral(hidden) @@ -108,7 +111,6 @@ public void runEffect(Event e, Bot bot) { final MessageEvent event = (MessageEvent) e; final Object rawMessage = parseSingle(exprMessage, e, null); final MessageBuilder message = JDAUtils.constructMessage(rawMessage); - final List rows = Arrays.asList(parseList(exprComponents, e, new ComponentRow[0])); final @Nullable Message referenced = parseSingle(exprReference, e, null); final MessageChannel channel = bot.findMessageChannel(event.getMessageChannel()); if (anyNull(channel, event, rawMessage, message)) { @@ -116,16 +118,11 @@ public void runEffect(Event e, Bot bot) { return; } - final List formatted = rows - .stream() - .map(ComponentRow::asActionRow) - .collect(Collectors.toList()); - MessageAction action = channel.sendMessage(message.build()); action = action.setActionRows(formatted); if (referenced != null) - action = action.reference(referenced); + action = action.reference(referenced).mentionRepliedUser(mentioning); action.queue(this::restart, ex -> { DiSky.getErrorHandler().exception(e, ex); @@ -140,4 +137,4 @@ public void runEffect(Event e, Bot bot) { return "reply with " + exprMessage.toString(e, debug) + (getChangedVariable() == null ? "" : " and store the message in " + variableAsString(e, debug)); } -} +} \ No newline at end of file From fac65714785b6d42df97096c26aeaffdf1fc1c9a Mon Sep 17 00:00:00 2001 From: wallace4BR Date: Sat, 26 Mar 2022 06:53:02 -0300 Subject: [PATCH 8/8] =?UTF-8?q?=F0=9F=9A=80=20remove=20some=20unecessary?= =?UTF-8?q?=20spaces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../disky/elements/effects/ReplyWith.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java index 27b88478..ca40f9d7 100644 --- a/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java +++ b/src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java @@ -92,18 +92,18 @@ public void runEffect(Event e, Bot bot) { if (!hook.isExpired()) { hook.editOriginal(message.build()) - .queue(v -> restart(), ex -> { - DiSky.getErrorHandler().exception(e, ex); - restart(); + .queue(v -> restart(), ex -> { + DiSky.getErrorHandler().exception(e, ex); + restart(); }); } event.reply(message.build()) - .addActionRows(formatted) - .setEphemeral(hidden) - .queue(v -> restart(), ex -> { - DiSky.getErrorHandler().exception(e, ex); - restart(); + .addActionRows(formatted) + .setEphemeral(hidden) + .queue(v -> restart(), ex -> { + DiSky.getErrorHandler().exception(e, ex); + restart(); }); } else {