Пример #1
0
        private async Task ProcessBotRequestAsync(SocketMessage message, SocketTextChannel channel, DiscordServerOptions serverOptions, double frequency, string nickname)
        {
            try
            {
                logger.LogInformation("Processing ATIS bot request {guildName} {frequency} {nickname}...", channel.Guild.Name, frequency, nickname);

                var response = await message.Channel.SendMessageAsync("",
                                                                      embed : new EmbedBuilder().WithDescription("⬜ Loading the audio...").Build());

                var filePath = await SaveAudioAsync(message);

                await response.ModifyAsync(props =>
                {
                    props.Embed = new EmbedBuilder().WithDescription("✅ Audio loaded\n⬜ Creating channel...").Build();
                });

                var voiceChannel = await channelMaker.CreateVoiceChannelAsync(serverOptions, channel.Guild, (int)(frequency * 1000));

                await response.ModifyAsync(props =>
                {
                    props.Embed = new EmbedBuilder().WithDescription("✅ Audio loaded\n✅ Channel created\n⬜ Activating ATIS bot...").Build();
                });

                try
                {
                    await atisProcessManager.StartAtisAsync(voiceChannel, filePath, nickname);

                    await response.ModifyAsync(props =>
                    {
                        props.Embed = new EmbedBuilder().WithDescription("✅ Audio loaded\n✅ Channel created\n✅ ATIS Bot activated").Build();
                    });
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Cannot start process");

                    await response.ModifyAsync(props =>
                    {
                        props.Embed = new EmbedBuilder().WithDescription($"✅ Audio loaded\n✅ Channel created\n🟥 Failed to create bot. {ex.Message}").Build();
                    });
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Cannot process ATIS request {guildName} {frequency} {nickname}", channel.Guild.Name, frequency, nickname);
            }
        }
Пример #2
0
        private async Task CreateVoiceChannelAndMoveAsync(string clientId, int?toFrequency)
        {
            var connection = await discordConnectionStorage.GetConnectionAsync(clientId);

            if (connection == null)
            {
                return;
            }

            SocketGuildUser      guildUser     = null;
            DiscordServerOptions serverOptions = null;

            foreach (var options in discordOptions.Servers)
            {
                guildUser     = botClient.Guilds.SingleOrDefault(o => o.Id == options.ServerId)?.GetUser(connection.UserId);
                serverOptions = options;
                if (guildUser?.VoiceChannel != null)
                {
                    break;
                }
            }

            if (guildUser == null)
            {
                logger.LogDebug("Cannot find connected user {userId} in any server!", connection.UserId);
                return;
            }

            if (guildUser.VoiceChannel?.CategoryId != serverOptions.ChannelCategoryId)
            {
                // Do not touch user not connecting to voice or connecting outside the channel
                logger.LogDebug("Cannot move because connected user {userId} is in another voice channel category {categoryId}!", connection.UserId, guildUser.VoiceChannel?.CategoryId);
                return;
            }

            var guild = guildUser.Guild;

            var channel = await channelMaker.CreateVoiceChannelAsync(serverOptions, guild, toFrequency);

            await MoveMemberAsync(guildUser, channel);
        }