From 4332592dfa921c089da3b51e067f4ab888424242 Mon Sep 17 00:00:00 2001 From: tueem Date: Mon, 2 Dec 2024 13:16:28 +0100 Subject: [PATCH] add Javacord PermissionCheck --- .../javacord/checks/PermissionCheck.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/checks/PermissionCheck.java diff --git a/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/checks/PermissionCheck.java b/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/checks/PermissionCheck.java new file mode 100644 index 0000000..8996ce4 --- /dev/null +++ b/wrapper/javacord/src/main/java/net/tomatentum/marinara/wrapper/javacord/checks/PermissionCheck.java @@ -0,0 +1,35 @@ +package net.tomatentum.marinara.wrapper.javacord.checks; + +import java.util.Optional; + +import org.javacord.api.entity.permission.PermissionType; +import org.javacord.api.entity.server.Server; +import org.javacord.api.interaction.InteractionBase; + +import net.tomatentum.marinara.checks.InteractionCheck; + +public class PermissionCheck implements InteractionCheck { + + public static @interface HasPermission { + public PermissionType[] value(); + } + + @Override + public boolean preExec(Object context, HasPermission annotation) { + throw new UnsupportedOperationException("Unimplemented method 'preExec'"); + } + + public boolean preExec(InteractionBase context, HasPermission annotation) { + Optional server = context.getServer(); + if (!server.isPresent()) + return false; + + return server.get().hasPermissions(context.getUser(), annotation.value()); + } + + @Override + public void postExec(Object context, HasPermission annotation) { + + } + +}