Exemplo n.º 1
0
        public async Task Run()
        {
            using var serviceProvider = new ServiceContainer();

            using var client = GetDiscordClient();

            if (_discordSettings.LogLevel == "Debug")
            {
                try
                {
                    SoundDevice.DetectDevices();
                }
                catch (Exception e)
                {
                    logger.Error(e, "Sound device detection failed: {exception}");
                }
            }

            using var soundPlayer = new SoundPlayer(new SoundDevice(_soundSettings.InputDeviceName, _soundSettings.InputDeviceId), _soundSettings);
            serviceProvider.AddService(typeof(ISoundPlayer), soundPlayer);

            var discordManager = new DiscordManager(client, _discordSettings);

            serviceProvider.AddService(typeof(DiscordManager), discordManager);

            var commandImplementations = new CommandImplementations(discordManager, soundPlayer, _discordSettings);

            serviceProvider.AddService(typeof(ICommandImplementations), commandImplementations);

            SetupCommands(client, serviceProvider);
            SetupVoice(client);

            await client.ConnectAsync();

            await Task.Run(() => new ConsoleCommands(commandImplementations).Listen());
        }