/// <summary> /// TODO Documentation comment /// </summary> /// <param name="member"></param> /// <param name="requestedPublicity"></param> /// <param name="requestedRegion"></param> /// <param name="error"></param> /// <returns></returns> public bool CheckPermission(DiscordMember member, string name, ChannelPublicity requestedPublicity, VoiceRegion requestedRegion, out string error) { VoiceChannelCreationPermissions highestPrecedencePermissions = null; int existingChannels = (CreatedChannels.ContainsKey(member) ? CreatedChannels[member]?.Count : 0) ?? 0; int highestRolePosition = -1; DiscordRole highestRole = null; foreach (DiscordRole role in member.Roles) { if (highestRolePosition < role.Position) { highestRole = role; highestRolePosition = role.Position; } } if (RolewisePermissions.ContainsKey(highestRole)) { highestPrecedencePermissions = RolewisePermissions[highestRole]; } if (MemberwisePermissions.ContainsKey(member)) { highestPrecedencePermissions = MemberwisePermissions[member]; } return((highestPrecedencePermissions ?? EveryonePermission).ValidateChannelCreationAuthority(!((name is null) || name == string.Empty), requestedPublicity, existingChannels, requestedRegion, out error)); }
bool ValidateVCParameterInput(DiscordGuild guild, ChannelPublicity publicity, int?maxUsers, int?bitrate, VoiceRegion region, out string error) { error = string.Empty; if (registeredGuildData[guild] is null || registeredGuildData[guild].ParentCategory is null || registeredGuildData[guild].WaitingRoomVC is null || registeredGuildData[guild].CommandListenChannel is null) { error = $"``Be sure to have an admin set the parent category, waiting room vc and the command channel before using this command``"; goto Completed; } if (publicity == ChannelPublicity.Unknown) { error = "``The publicity option you selected is not supported. Available options are: public|private|supporter|hidden``"; goto Completed; } if (maxUsers < 0 || maxUsers > 99) { error = "``You cannot create a channel with a limit less than 0 or larger than 99 people``"; goto Completed; } if (bitrate < 8000 || bitrate > 96000) { error = "``You cannot create a channel with a bitrate less than 8kbps or larger than 96kbps``"; goto Completed; } if (region == VoiceRegion.Unknown) { error = "``The region option you selected is not supported. Available options are: auto|automatic|brazil|europe|hongkong|india|japan|russia|singapore|southafrica|sydney|uscentral|useast|ussouth|uswest``"; goto Completed; } Completed: return(error == string.Empty); }
bool ValidateMemberCreationPermissions(DiscordGuild guild, DiscordMember member, string channelName, ChannelPublicity requestedPublicity, VoiceRegion requestedRegion, out string error) { return(registeredGuildData[guild].CheckPermission(member, channelName, requestedPublicity, requestedRegion, out error)); }
//TODO need a better way to store/specify permissions, and preferably one where no permissions is left out (because of my OCD) List <DiscordOverwriteBuilder> GeneratePermissionOverwrites(DiscordGuild guild, DiscordMember creator, ChannelPublicity publicity, params DiscordMember[] permittedMembers) { //TODO implement the ranking method that allows moderators to specify what roles have access to naming capabilities, publicity options, and bitrate options List <DiscordOverwriteBuilder> channelPermissionsBuilderList = new List <DiscordOverwriteBuilder> { new DiscordOverwriteBuilder().For(guild.EveryoneRole).Deny(Permissions.AccessChannels | Permissions.UseVoice), //Prevent everyone from viewing any channel new DiscordOverwriteBuilder().For(registeredGuildData[guild].MemberRole).Allow(publicity == ChannelPublicity.Hidden ? Permissions.None : Permissions.AccessChannels).Deny(publicity == ChannelPublicity.Private ? Permissions.UseVoice : Permissions.None).Deny(publicity == ChannelPublicity.Hidden ? Permissions.AccessChannels : Permissions.None), //Allow members to see private channels new DiscordOverwriteBuilder().For(registeredGuildData[guild].MutedRole).Allow(publicity == ChannelPublicity.Hidden ? Permissions.None : Permissions.AccessChannels).Deny(Permissions.UseVoice | Permissions.Speak | Permissions.UseVoiceDetection | Permissions.Stream) //Dissallow muted members from accessing or viewing }; //TODO this might be redundant...need to test if the muted role overwrite will disallow the muted role from joining even if this allows them...though i think i know the behavior that the role system will produce //TODO may need to accomodate other blacklist roles foreach (var member in permittedMembers) { if (member.Roles.Contains(registeredGuildData[guild].MutedRole)) { continue; //TODO we want to inform the creator this member was not whitelisted in the vc because they have the muted role } channelPermissionsBuilderList.Add(new DiscordOverwriteBuilder().For(member).Allow(Permissions.AccessChannels | Permissions.UseVoice | Permissions.Speak | Permissions.UseVoiceDetection | Permissions.Stream)); } return(channelPermissionsBuilderList); }
public async Task UpdateVC(CommandContext ctx, ChannelPublicity publicity = ChannelPublicity.Public, int?maxUsers = 0, int?bitrate = 64000, VoiceRegion region = VoiceRegion.Automatic) { await RespondAsync(ctx.Message, "NYI"); }
public async Task CreateVC(CommandContext ctx, ChannelPublicity publicity = ChannelPublicity.Public, int?maxUsers = 0, int?bitrate = 64000, VoiceRegion region = VoiceRegion.Automatic, params DiscordMember[] permittedMembers) { List <KeyValuePair <string, string> > embedResponseFields = new List <KeyValuePair <string, string> >(10); MessageType messageType = MessageType.Success; string warning = string.Empty; if (ValidateServerRegistered(ctx) && ValidateCommandChannel(ctx)) { if (!ValidateVCParameterInput(ctx.Guild, publicity, maxUsers, bitrate, region, out string error)) //ensure the provided parameters arent s***e { messageType = MessageType.Error; goto Completed; } if (!ValidateMemberCreationPermissions(ctx.Guild, ctx.Member, null, publicity, region, out error)) //TODO implement channel name { messageType = MessageType.Error; goto Completed; } if (ctx.Member.VoiceState is null || ctx.Member.VoiceState.Channel is null || !ctx.Member.VoiceState.Channel.Equals(registeredGuildData[ctx.Guild].WaitingRoomVC)) //ensure the member is in the waiting room { error = $"``You cannot create a voice channel if you arent in the waiting room: {registeredGuildData[ctx.Guild].WaitingRoomVC.Name}``"; messageType = MessageType.Error; goto Completed; } List <DiscordOverwriteBuilder> channelPermissionsBuilderList = GeneratePermissionOverwrites(ctx.Guild, ctx.Member, publicity, permittedMembers); DiscordChannel createdChannel = await CreateChannelAndMoveMemberAsync(ctx.Guild, ctx.Member, maxUsers, bitrate, region, channelPermissionsBuilderList); embedResponseFields.Add(new KeyValuePair <string, string>("Channel Publicity", publicity.ToString())); embedResponseFields.Add(new KeyValuePair <string, string>("Max Users", maxUsers.ToString())); embedResponseFields.Add(new KeyValuePair <string, string>("Bitrate", bitrate.ToString())); embedResponseFields.Add(new KeyValuePair <string, string>("Region", region.ToString())); embedResponseFields.Add(new KeyValuePair <string, string>("Permitted Members", $"{permittedMembers?.Length ?? 0} members permitted")); if (permittedMembers is null || permittedMembers.Length == 0) { warning = $"You have created a private voice channel but have not specified anyone permitted to join. Be sure to whitelist members you want to have access to it"; messageType = MessageType.Warning; goto Completed; } if (permittedMembers.Length > 0) { await AttemptInformPermittedMembersDirectly(ctx.Member, createdChannel, permittedMembers); goto Completed; } Completed: if (error != string.Empty) { embedResponseFields.Add(new KeyValuePair <string, string>("Error", error)); } if (warning != string.Empty) { embedResponseFields.Add(new KeyValuePair <string, string>("Warning", warning)); } await ctx.Message.RespondAsync(CreateEmbedMessage(ctx, messageType, "Member Create Voice Channel", embedResponseFields)); } }