Ejemplo n.º 1
0
        public async ValueTask <CommandResult> HandleAsync(ICommandContext context)
        {
            if (Category is not null && !Category.IsCategory)
            {
                return(CommandResult.InvalidParameter("Channel must be a category."));
            }

            var settings = await _unitOfWork.AutoVoiceSettings.GetOrCreateAsync(context.Guild);

            if (settings.ChannelCreatorId is not null)
            {
                return(CommandResult.InvalidOperation("Auto Voice is already enabled on this server."));
            }

            var voiceChannelCreator = await _service.CreateAsync(context.Guild, Category, settings.Bitrate);

            settings.ChannelCreatorId = voiceChannelCreator.Id;
            await _unitOfWork.CompleteAsync();

            var sb = new StringBuilder();

            sb.AppendLine("Auto Voice has been enabled.");
            sb.Append($"Created new voice channel `{voiceChannelCreator.Name}`");

            if (voiceChannelCreator.Parent != null)
            {
                sb.Append($" under category `{voiceChannelCreator.Parent.Name}`");
            }

            sb.AppendLine(".");

            return(CommandResult.Success(sb.ToString()));
        }
        private async Task OnUserJoin(DiscordChannel?voiceChannel, AutoVoiceSettings settings)
        {
            if (voiceChannel is null)
            {
                return;
            }

            if (settings.ContainsChannel(voiceChannel))
            {
                await _autoVoiceService.UpdateNameAsync(voiceChannel);
            }
            else if (settings.ChannelCreatorId == voiceChannel.Id)
            {
                await _autoVoiceService.UpdateNameAsync(voiceChannel);

                var newVoiceChannel = await _autoVoiceService.CreateAsync(voiceChannel.Guild, voiceChannel.Parent, settings.Bitrate);

                settings.AddChannel(newVoiceChannel);
            }
        }