/// <summary> /// Clears all channel permission overwrites from the given channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>A modification result which may or may not have succeeded.</returns> private async Task <ModifyEntityResult> ClearChannelPermissionOverwrites(IGuildChannel channel) { var guild = channel.Guild; foreach (var overwrite in channel.PermissionOverwrites) { switch (overwrite.TargetType) { case PermissionTarget.Role: { var role = guild.GetRole(overwrite.TargetId); if (role is null) { continue; } if (role.Id == guild.EveryoneRole.Id) { await channel.AddPermissionOverwriteAsync(role, OverwritePermissions.InheritAll); } else { await channel.RemovePermissionOverwriteAsync(role); } break; } case PermissionTarget.User: { var user = await guild.GetUserAsync(overwrite.TargetId); if (user is null) { continue; } if (user.IsMe(_client)) { continue; } await channel.RemovePermissionOverwriteAsync(user); break; } default: { throw new ArgumentOutOfRangeException(); } } } return(ModifyEntityResult.FromSuccess()); }
private static async Task ConfigureChannelMuteRolePermissionsAsync(IGuildChannel channel, IRole muteRole) { try { var permissionOverwrite = channel.GetPermissionOverwrite(muteRole); if (permissionOverwrite != null) { var deniedPermissions = permissionOverwrite.GetValueOrDefault().ToDenyList(); if (!_mutePermissions.ToDenyList().Except(deniedPermissions).Any()) { Log.Debug("Skipping setting mute permissions for channel #{Channel} as they're already set.", channel.Name); return; } Log.Debug("Removing permission overwrite for channel #{Channel}.", channel.Name); await channel.RemovePermissionOverwriteAsync(muteRole); } await channel.AddPermissionOverwriteAsync(muteRole, _mutePermissions); Log.Debug("Set mute permissions for role {Role} in channel #{Channel}.", muteRole.Name, channel.Name); } catch (Exception e) { Log.Error(e, "Failed setting channel mute role on #{Channel}", channel.Name); throw; } }
public async Task <ModifyEntityResult> RevokeUserDedicatedChannelAccessAsync ( [NotNull] ICommandContext context, [NotNull] IGuildChannel dedicatedChannel, [NotNull] IUser participant ) { if (!(await context.Guild.GetUserAsync(context.Client.CurrentUser.Id)).GuildPermissions.ManageChannels) { return(ModifyEntityResult.FromError ( "I don't have permission to manage channels, so I can't change permissions on dedicated RP channels." )); } var user = await context.Guild.GetUserAsync(participant.Id); if (user is null) { return(ModifyEntityResult.FromError("User not found in guild.")); } await dedicatedChannel.RemovePermissionOverwriteAsync(user); return(ModifyEntityResult.FromSuccess()); }
public async Task ArchiveChannel([Remainder] IGuildChannel channel) { //First we need to move channel var cat = await Context.Guild.GetCategoriesAsync(); ICategoryChannel category = cat.Where(x => x.Id == 548238743476240405).FirstOrDefault(); if (category == null) { return; } //Move it now await channel.ModifyAsync(x => x.CategoryId = category.Id); //Get role overwrites var everyoneOverwrite = category.GetPermissionOverwrite(Context.Guild.EveryoneRole); var adminOverwrite = category.GetPermissionOverwrite(Context.Guild.GetRole(217696310168518657)); //First remove all perms var curPerms = channel.PermissionOverwrites; foreach (Overwrite ow in curPerms) { if (ow.TargetType == PermissionTarget.Role) { await channel.RemovePermissionOverwriteAsync(Context.Guild.GetRole(ow.TargetId)); } else { await channel.RemovePermissionOverwriteAsync(await Context.Guild.GetUserAsync(ow.TargetId)); } } //Okay now we set perms await channel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, everyoneOverwrite.Value); await channel.AddPermissionOverwriteAsync(Context.Guild.GetRole(217696310168518657), adminOverwrite.Value); //Will add an output await Context.Channel.SendSuccessAsync($"The channel {channel.Name} has been archived."); }
private async Task ConfigureChannelMuteRolePermissionsAsync(IGuildChannel channel, IRole muteRole) { var permissionOverwrite = channel.GetPermissionOverwrite(muteRole); if (permissionOverwrite != null) { if ((permissionOverwrite.Value.AllowValue == _mutePermissions.AllowValue) && (permissionOverwrite.Value.DenyValue == _mutePermissions.DenyValue)) { Log.Debug("Skipping setting mute permissions for channel #{Channel} as they're already set.", channel.Name); return; } Log.Debug("Removing permission overwrite for channel #{Channel}.", channel.Name); await channel.RemovePermissionOverwriteAsync(muteRole); } await channel.AddPermissionOverwriteAsync(muteRole, _mutePermissions); Log.Debug("Set mute permissions for role {Role} in channel #{Channel}.", muteRole.Name, channel.Name); }
public async Task Unmute(IGuildUser user, IGuildChannel channel = null) { //If there's no specified channel, use the channel the command was sent in if (channel == null) { channel = (ITextChannel)Context.Channel; } //Ensure this is a text channel if (channel == null) { await Context.Channel.SendErrorAsync($"{channel.Name} is not a text channel."); return; } //Try and get the perms for teh user var userPerms = channel.GetPermissionOverwrite(user); //If there *are* user perms, it's safe to check to unmute them otherwise they aren't muted if (userPerms == null) { await Context.Channel.SendErrorAsync($"{user.NicknameUsername()} is not muted."); return; } //Check to see if they're muted if (userPerms.Value.SendMessages != PermValue.Deny) { await Context.Channel.SendErrorAsync($"{user.NicknameUsername()} is not muted."); return; } //Delete their perms, they're gucci await channel.RemovePermissionOverwriteAsync(user); await Context.Channel.SendSuccessAsync($"{user.NicknameUsername()} has been unmuted."); }