-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Added retrieve start message of thread effect
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/main/java/info/itsthesky/disky/elements/effects/retrieve/RetrieveStartMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package info.itsthesky.disky.elements.effects.retrieve; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.classes.Changer; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser; | ||
import ch.njol.skript.util.AsyncEffect; | ||
import ch.njol.util.Kleenean; | ||
import info.itsthesky.disky.DiSky; | ||
import net.dv8tion.jda.api.entities.Message; | ||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; | ||
import org.bukkit.event.Event; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class RetrieveStartMessage extends AsyncEffect { | ||
|
||
static { | ||
Skript.registerEffect( | ||
RetrieveStartMessage.class, | ||
"retrieve start message (from|with|of|in) %threadchannel% and store (it|the message) in %~objects%" | ||
); | ||
} | ||
|
||
private Expression<ThreadChannel> exprChannel; | ||
private Expression<?> exprResult; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { | ||
exprChannel = (Expression<ThreadChannel>) expressions[0]; | ||
exprResult = expressions[1]; | ||
return Changer.ChangerUtils.acceptsChange(exprResult, Changer.ChangeMode.SET, Message.class); | ||
} | ||
|
||
@Override | ||
protected void execute(@NotNull Event event) { | ||
ThreadChannel channel = exprChannel.getSingle(event); | ||
if (channel == null) | ||
return; | ||
|
||
final Message message; | ||
try { | ||
message = channel.retrieveStartMessage().complete(); | ||
} catch (Exception ex) { | ||
DiSky.getErrorHandler().exception(event, ex); | ||
return; | ||
} | ||
|
||
exprResult.change(event, new Message[] {message}, Changer.ChangeMode.SET); | ||
} | ||
|
||
@Override | ||
public @NotNull String toString(@Nullable Event event, boolean debug) { | ||
return "retrieve start message from " + exprChannel.toString(event, debug) + " and store it in " + exprResult.toString(event, debug); | ||
} | ||
} |