Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//
// MIT License
//
// Copyright (c) 2024 Incendo
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package org.incendo.cloud.discord.jda6.annotation;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import net.dv8tion.jda.api.Permission;
import org.apiguardian.api.API;

/**
* Annotation equivalent of {@link net.dv8tion.jda.api.Permission}.
*
* <p>This requires the installation of {@link JDAPermissionBuilderModifier}.</p>
*
* @since 1.0.0
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@API(status = API.Status.STABLE, since = "1.0.0")
public @interface JDAPermission {

/**
* Corresponds to {@link net.dv8tion.jda.api.Permission} with annotation support.
*
* @return what permission the user needs to run the command
*/
Permission permission();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// MIT License
//
// Copyright (c) 2024 Incendo
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
package org.incendo.cloud.discord.jda6.annotation;

import java.util.Objects;
import org.apiguardian.api.API;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.incendo.cloud.Command;
import org.incendo.cloud.annotations.AnnotationParser;
import org.incendo.cloud.annotations.BuilderModifier;
import org.incendo.cloud.discord.slash.DiscordPermission;

/**
* Builder modifier that enables the use of {@link JDAPermission}.
*
* @param <C> command sender type
* @since 1.0.0
*/
@API(status = API.Status.STABLE, since = "1.0.0")
public final class JDAPermissionBuilderModifier<C> implements BuilderModifier<JDAPermission, C> {

/**
* Installs the builder modifier.
*
* @param <C> command sender type
* @param annotationParser annotation parser
*/
public static <C> void install(final @NonNull AnnotationParser<C> annotationParser) {
Objects.requireNonNull(annotationParser, "annotationParser");
annotationParser.registerBuilderModifier(JDAPermission.class, new JDAPermissionBuilderModifier<>());
}

@Override
public Command.@NonNull Builder<? extends C> modifyBuilder(
final @NonNull JDAPermission annotation,
final Command.@NonNull Builder<C> builder
) {
return builder.permission(DiscordPermission.of(annotation.permission().getRawValue()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.incendo.cloud.discord.immutables.ImmutableImpl;
import org.incendo.cloud.discord.jda6.JDA6CommandManager;
import org.incendo.cloud.discord.jda6.JDAInteraction;
import org.incendo.cloud.discord.jda6.annotation.JDAPermissionBuilderModifier;
import org.incendo.cloud.discord.jda6.annotation.ReplySetting;
import org.incendo.cloud.discord.jda6.annotation.ReplySettingBuilderModifier;
import org.incendo.cloud.discord.jda6.example.Example;
Expand All @@ -63,6 +64,7 @@ public void register(final @NonNull JDA6CommandManager<JDAInteraction> commandMa

// Adds support for the JDA-specific annotations.
ReplySettingBuilderModifier.install(annotationParser);
JDAPermissionBuilderModifier.install(annotationParser);
CommandScopeBuilderModifier.install(annotationParser);

// Parses @Command, @Parser, @Suggestions & @ExceptionHandler...
Expand Down
Loading