/// <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));
        }
コード例 #2
0
 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));
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        //TODO thinking this should be moved to the GuildData class
        async Task <DiscordChannel> CreateChannelAndMoveMemberAsync(DiscordGuild guild, DiscordMember channelCreator, int?maxUsers, int?bitrate, VoiceRegion region /*TODO not yet supported by D#+ but will be soon (hopefully)*/, IEnumerable <DiscordOverwriteBuilder> permissions)
        {
            DiscordChannel createdChannel = null;

            try
            {
                createdChannel = await guild.CreateVoiceChannelAsync(channelCreator.Nickname ?? $"{channelCreator.DisplayName}'s VC", registeredGuildData[guild].ParentCategory, bitrate, maxUsers, permissions, $"Channel created via command by member {channelCreator.DisplayName}#{channelCreator.Discriminator}:{channelCreator.Id}");

                registeredGuildData[guild].AddChannel(channelCreator, createdChannel);                 //Add the channel to the registerred guild's data container
            }
            catch (Exception)
            {
                //TODO log, respond letting the creator know the issue that occurred
                return(null);
            }

            await channelCreator.ModifyAsync(m => m.VoiceChannel = createdChannel);

            return(createdChannel);
        }
コード例 #5
0
 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");
 }
コード例 #6
0
        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));
            }
        }