Skip to content

Commit

Permalink
✨ Added ways to store created embeds in variable in the create embed …
Browse files Browse the repository at this point in the history
…section (#155)
  • Loading branch information
ItsTheSky committed Apr 18, 2024
1 parent f593ec4 commit b1a3883
Showing 1 changed file with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.util.Kleenean;
import info.itsthesky.disky.api.EmbedManager;
import info.itsthesky.disky.api.skript.ReturningSection;
import info.itsthesky.disky.elements.sections.message.CreateMessage;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
import org.bukkit.event.Event;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -41,13 +44,33 @@
"\t\t\tset footer icon of embed to \"https://cdn.discordapp.com/emojis/825811394963177533.png?v=1\"\n" +
"\t\t\tset timestamp of embed to now\n" +
"\t\treply with last embed")
public class EmbedSection extends Section {
public class EmbedSection extends ReturningSection<EmbedBuilder> {

public static EmbedSection lastSection;
public static class embed extends LastBuilderExpression<EmbedBuilder, EmbedSection> { }

public static EmbedBuilder lastEmbed;
private Expression<String> exprID;

static {
Skript.registerSection(EmbedSection.class, "make [new] [discord] [message] embed [using [the] [template] [(named|with name|with id)] %-string%]");
register(
EmbedSection.class,
EmbedBuilder.class,
embed.class,
"make [a] [new] [discord] [message] embed [using [the] [template] [(named|with name|with id)] %-string%]"
);
}

@Override
public EmbedBuilder createNewValue(Event event) {
lastSection = this;

if (exprID != null) {
String id = exprID.getSingle(event);
if (id == null) return new EmbedBuilder();
return new EmbedBuilder(EmbedManager.getTemplate(id));
} else {
return new EmbedBuilder();
}
}

@Override
Expand All @@ -58,20 +81,7 @@ public boolean init(Expression<?>[] exprs,
@Nullable SectionNode sectionNode,
@Nullable List<TriggerItem> triggerItems) {
exprID = (Expression<String>) exprs[0];
loadOptionalCode(sectionNode);
return true;
}

@Override
protected @Nullable TriggerItem walk(@NotNull Event e) {
if (exprID != null) {
String id = exprID.getSingle(e);
if (id == null) lastEmbed = new EmbedBuilder();
lastEmbed = new EmbedBuilder(EmbedManager.getTemplate(id));
} else {
lastEmbed = new EmbedBuilder();
}
return walk(e, true);
return super.init(exprs, matchedPattern, isDelayed, parseResult, sectionNode, triggerItems);
}

@Override
Expand Down

0 comments on commit b1a3883

Please sign in to comment.