Search in sources :

Example 1 with PermissionOverride

use of net.dv8tion.jda.api.entities.PermissionOverride in project TechDiscordBot by TechsCode-Team.

the class PluginLabModule method updatePermissions.

public void updatePermissions() {
    for (Member member : TechDiscordBot.getGuild().getMembers()) {
        List<String> roles = member.getRoles().stream().map(Role::getName).collect(Collectors.toList());
        // Skip staff.
        if (roles.contains("Staff"))
            continue;
        // Skip non-verified users.
        if (!roles.contains("Verified"))
            continue;
        plugins.forEach((plugin, channel) -> {
            PermissionOverride permOv = channel.getPermissionOverride(member);
            boolean canSeeChannel = false;
            if (permOv != null)
                canSeeChannel = permOv.getAllowed().size() > 0 && permOv.getDenied().size() == 0;
            if (roles.contains("Plugin Lab") && (channel.getTopic() != null && channel.getTopic().endsWith("Lab FREE") || roles.contains(plugin)) && !canSeeChannel) {
                Collection<Permission> permissions = new ArrayList<>(Arrays.asList(Permission.MESSAGE_ADD_REACTION, Permission.MESSAGE_READ, Permission.MESSAGE_HISTORY, Permission.MESSAGE_WRITE, Permission.MESSAGE_ATTACH_FILES, Permission.MESSAGE_EMBED_LINKS));
                channel.getManager().putPermissionOverride(member, permissions, new ArrayList<>()).queue();
                TechDiscordBot.log("Plugin Lab » Added " + member.getEffectiveName() + " to the " + plugin + "'s Lab.");
                ServerLogs.log("Plugin Lab", "Added " + member.getAsMention() + " to the " + plugin + "'s Lab.");
            } else if (!roles.contains("Plugin Lab") && canSeeChannel) {
                channel.getManager().removePermissionOverride(member).queue();
                TechDiscordBot.log("Plugin Lab » Removed " + plugin + " Lab from (" + member.getEffectiveName() + ")");
                ServerLogs.log("Plugin Lab", "Removed " + plugin + " Lab from (" + member.getAsMention() + ")");
            }
        });
    }
}
Also used : PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride) Permission(net.dv8tion.jda.api.Permission) Member(net.dv8tion.jda.api.entities.Member)

Example 2 with PermissionOverride

use of net.dv8tion.jda.api.entities.PermissionOverride in project JDA by DV8FromTheWorld.

the class ICategorizableChannelMixin method isSynced.

// ---- Default implementations of interface ----
@Override
default boolean isSynced() {
    IPermissionContainerMixin<?> parent = (IPermissionContainerMixin<?>) getParentCategory();
    if (parent == null)
        // Channels without a parent category are always considered synced. Also the case for categories.
        return true;
    TLongObjectMap<PermissionOverride> parentOverrides = parent.getPermissionOverrideMap();
    TLongObjectMap<PermissionOverride> overrides = getPermissionOverrideMap();
    if (parentOverrides.size() != overrides.size())
        return false;
    // Check that each override matches with the parent override
    for (PermissionOverride override : parentOverrides.valueCollection()) {
        PermissionOverride ourOverride = overrides.get(override.getIdLong());
        if (// this means we don't have the parent override => not synced
        ourOverride == null)
            return false;
        // Permissions are different => not synced
        if (ourOverride.getAllowedRaw() != override.getAllowedRaw() || ourOverride.getDeniedRaw() != override.getDeniedRaw())
            return false;
    }
    // All overrides exist and are the same as the parent => synced
    return true;
}
Also used : PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride) PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride)

Example 3 with PermissionOverride

use of net.dv8tion.jda.api.entities.PermissionOverride in project JDA by DV8FromTheWorld.

the class PermOverrideManagerImpl method getPermissionOverride.

@Nonnull
@Override
public PermissionOverride getPermissionOverride() {
    IPermissionContainerMixin<?> channel = (IPermissionContainerMixin<?>) override.getChannel();
    PermissionOverride realOverride = channel.getPermissionOverrideMap().get(override.getIdLong());
    if (realOverride != null)
        override = realOverride;
    return override;
}
Also used : PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride) IPermissionContainerMixin(net.dv8tion.jda.internal.entities.mixin.channel.attribute.IPermissionContainerMixin) Nonnull(javax.annotation.Nonnull) PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride)

Example 4 with PermissionOverride

use of net.dv8tion.jda.api.entities.PermissionOverride in project Sx4 by sx4-discord-bot.

the class LockdownCommand method onCommand.

public void onCommand(Sx4CommandEvent event, @Argument(value = "channel", endless = true, nullDefault = true) TextChannel textChannel) {
    TextChannel channel = textChannel == null ? event.getTextChannel() : textChannel;
    Role role = event.getGuild().getPublicRole();
    PermissionOverride override = channel.getPermissionOverride(role);
    if (override != null && override.getDenied().contains(Permission.MESSAGE_WRITE)) {
        channel.upsertPermissionOverride(role).clear(Permission.MESSAGE_WRITE).flatMap($ -> event.replySuccess(channel.getAsMention() + " is no longer locked down")).queue();
    } else {
        channel.upsertPermissionOverride(role).deny(Permission.MESSAGE_WRITE).flatMap($ -> event.replySuccess(channel.getAsMention() + " is now locked down")).queue();
    }
}
Also used : Role(net.dv8tion.jda.api.entities.Role) PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride) ModuleCategory(com.sx4.bot.category.ModuleCategory) PermissionOverride(net.dv8tion.jda.api.entities.PermissionOverride) Role(net.dv8tion.jda.api.entities.Role) Sx4Command(com.sx4.bot.core.Sx4Command) Sx4CommandEvent(com.sx4.bot.core.Sx4CommandEvent) Permission(net.dv8tion.jda.api.Permission) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Argument(com.jockie.bot.core.argument.Argument) TextChannel(net.dv8tion.jda.api.entities.TextChannel)

Aggregations

PermissionOverride (net.dv8tion.jda.api.entities.PermissionOverride)4 Permission (net.dv8tion.jda.api.Permission)2 Argument (com.jockie.bot.core.argument.Argument)1 ModuleCategory (com.sx4.bot.category.ModuleCategory)1 Sx4Command (com.sx4.bot.core.Sx4Command)1 Sx4CommandEvent (com.sx4.bot.core.Sx4CommandEvent)1 Nonnull (javax.annotation.Nonnull)1 Member (net.dv8tion.jda.api.entities.Member)1 Role (net.dv8tion.jda.api.entities.Role)1 TextChannel (net.dv8tion.jda.api.entities.TextChannel)1 IPermissionContainerMixin (net.dv8tion.jda.internal.entities.mixin.channel.attribute.IPermissionContainerMixin)1