Search in sources :

Example 1 with PermissionListPaginationWidget

use of net.robinfriedli.aiode.command.widget.widgets.PermissionListPaginationWidget in project aiode by robinfriedli.

the class PermissionCommand method listPermissions.

private void listPermissions() {
    CommandContext context = getContext();
    Guild guild = context.getGuild();
    GuildContext guildContext = context.getGuildContext();
    SecurityManager securityManager = Aiode.get().getSecurityManager();
    List<PermissionTarget> targets = Lists.newArrayList();
    for (PermissionTarget.TargetType targetType : PermissionTarget.TargetType.values()) {
        if (!targetType.isChildTargetOnly()) {
            Set<? extends PermissionTarget> permissionTargetsInCategory = targetType.getAllPermissionTargetsInCategory();
            permissionTargetsInCategory.stream().sorted(Comparator.comparingInt((ToIntFunction<PermissionTarget>) permissionTarget -> permissionTarget.getPermissionTypeCategory().getSorting()).thenComparing(PermissionTarget::getPermissionTargetIdentifier)).forEach(permissionTarget -> {
                List<PermissionTarget> flattenedPermissionHierarchy = Lists.newArrayList();
                LinkedList<List<PermissionTarget>> stack = new LinkedList<>();
                stack.push(flattenedPermissionHierarchy);
                flattenPermissionTargetHierarchy(permissionTarget, stack, securityManager, guild, true);
                targets.addAll(flattenedPermissionHierarchy);
            });
        }
    }
    PermissionListPaginationWidget permissionListPaginationWidget = new PermissionListPaginationWidget(guildContext.getWidgetRegistry(), guild, context.getChannel(), targets, securityManager);
    permissionListPaginationWidget.initialise();
}
Also used : CommandContext(net.robinfriedli.aiode.command.CommandContext) SecurityManager(net.robinfriedli.aiode.command.SecurityManager) Guild(net.dv8tion.jda.api.entities.Guild) LinkedList(java.util.LinkedList) PermissionTarget(net.robinfriedli.aiode.command.PermissionTarget) CustomPermissionTarget(net.robinfriedli.aiode.entities.CustomPermissionTarget) GuildContext(net.robinfriedli.aiode.discord.GuildContext) PermissionListPaginationWidget(net.robinfriedli.aiode.command.widget.widgets.PermissionListPaginationWidget) ToIntFunction(java.util.function.ToIntFunction) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

LinkedList (java.util.LinkedList)1 List (java.util.List)1 ToIntFunction (java.util.function.ToIntFunction)1 Guild (net.dv8tion.jda.api.entities.Guild)1 CommandContext (net.robinfriedli.aiode.command.CommandContext)1 PermissionTarget (net.robinfriedli.aiode.command.PermissionTarget)1 SecurityManager (net.robinfriedli.aiode.command.SecurityManager)1 PermissionListPaginationWidget (net.robinfriedli.aiode.command.widget.widgets.PermissionListPaginationWidget)1 GuildContext (net.robinfriedli.aiode.discord.GuildContext)1 CustomPermissionTarget (net.robinfriedli.aiode.entities.CustomPermissionTarget)1