From 0f52ee93d92a56f8bc0f89b4e866ffebb298ffdd Mon Sep 17 00:00:00 2001 From: Sky Date: Sun, 24 Nov 2024 15:47:39 +0100 Subject: [PATCH] :sparkles: Added is member timeout property condition --- .../disky/elements/conditions/IsTimeout.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/main/java/info/itsthesky/disky/elements/conditions/IsTimeout.java diff --git a/src/main/java/info/itsthesky/disky/elements/conditions/IsTimeout.java b/src/main/java/info/itsthesky/disky/elements/conditions/IsTimeout.java new file mode 100644 index 0000000..f6448f3 --- /dev/null +++ b/src/main/java/info/itsthesky/disky/elements/conditions/IsTimeout.java @@ -0,0 +1,48 @@ +package info.itsthesky.disky.elements.conditions; + +import ch.njol.skript.config.Node; +import ch.njol.skript.lang.Expression; +import ch.njol.skript.lang.SkriptParser; +import ch.njol.util.Kleenean; +import info.itsthesky.disky.api.ReflectionUtils; +import info.itsthesky.disky.api.skript.PropertyCondition; +import info.itsthesky.disky.elements.sections.handler.DiSkyRuntimeHandler; +import net.dv8tion.jda.api.entities.Member; +import org.jetbrains.annotations.NotNull; + +public class IsTimeout extends PropertyCondition { + + static { + register( + IsTimeout.class, + PropertyType.BE, + "[discord] [member] timeout[ed]", + "member" + ); + } + + private Node node; + + @Override + public boolean init(Expression[] exprs, int matchedPattern, @NotNull Kleenean isDelayed, SkriptParser.@NotNull ParseResult parseResult) { + node = getParser().getNode(); + return super.init(exprs, matchedPattern, isDelayed, parseResult); + } + + @Override + public boolean check(Member member) { + if (member == null) + { + DiSkyRuntimeHandler.exprNotSet(node, ReflectionUtils.getFieldValueViaInstance(this, "expr")); + return false; + } + + return member.isTimedOut(); + } + + @Override + protected String getPropertyName() { + return "timeout"; + } + +}