Skip to content

Commit

Permalink
✨ Added way to reply with the new premium message thing
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Apr 22, 2024
1 parent 6cc4e6a commit 4b794fb
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/main/java/info/itsthesky/disky/elements/effects/ReplyWith.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.channel.middleman.GuildMessageChannel;
import net.dv8tion.jda.api.entities.sticker.Sticker;
import net.dv8tion.jda.api.interactions.Interaction;
import net.dv8tion.jda.api.interactions.callbacks.IPremiumRequiredReplyCallback;
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
Expand Down Expand Up @@ -52,7 +54,8 @@ public class ReplyWith extends AsyncEffect {
static {
Skript.registerEffect(
ReplyWith.class,
"reply with [hidden] %string/messagecreatebuilder/sticker/embedbuilder/messagepollbuilder% [with [the] reference[d] [message] %-message%] [and store (it|the message) in %-objects%]"
"reply with [hidden] %string/messagecreatebuilder/sticker/embedbuilder/messagepollbuilder% [with [the] reference[d] [message] %-message%] [and store (it|the message) in %-objects%]",
"reply with premium [required] message"
);
}

Expand All @@ -61,6 +64,7 @@ public class ReplyWith extends AsyncEffect {
private Expression<Message> exprReference;
private Expression<Object> exprResult;
private boolean hidden;
private boolean premium;

@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
Expand All @@ -70,16 +74,41 @@ public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, Skrip
}

node = getParser().getNode();
hidden = parseResult.expr.startsWith("reply with hidden");
exprMessage = (Expression<Object>) expressions[0];
exprReference = (Expression<Message>) expressions[1];
exprResult = (Expression<Object>) expressions[2];
premium = i == 1;

if (!premium) {
hidden = parseResult.expr.startsWith("reply with hidden");
exprMessage = (Expression<Object>) expressions[0];
exprReference = (Expression<Message>) expressions[1];
exprResult = (Expression<Object>) expressions[2];
}

return exprResult == null || Changer.ChangerUtils.acceptsChange(exprResult, Changer.ChangeMode.SET, Message.class);
}

@Override
public void execute(@NotNull Event e) {
if (premium) {
if (e instanceof InteractionEvent) {
final InteractionEvent event = (InteractionEvent) e;
final Interaction interaction = event.getInteractionEvent().getInteraction();
if (!(interaction instanceof IPremiumRequiredReplyCallback)) {
SkriptUtils.error(node, "You can only use the premium required message in an interaction event!");
return;
}

try {
((IPremiumRequiredReplyCallback) interaction).replyWithPremiumRequired().complete();
} catch (Exception ex) {
DiSky.getErrorHandler().exception(e, ex);
}

} else {
SkriptUtils.error(node, "You can only use the premium required message in an interaction event!");
}
return;
}

final Object message = parseSingle(exprMessage, e);
final Message reference = parseSingle(exprReference, e);
if (message == null)
Expand Down

0 comments on commit 4b794fb

Please sign in to comment.