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() + ")");
}
});
}
}
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;
}
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;
}
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();
}
}
Aggregations