示例#1
0
        public async Task MainAsync(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += async(sender, eventArgs) =>
            {
                Console.ForegroundColor = ConsoleColor.Red;
                await ConsoleLogger.LogAsync($"Unhandled Exception: {(Exception) eventArgs.ExceptionObject}\n" +
                                             $"Inner Exception: {((Exception) eventArgs.ExceptionObject).InnerException}", LogLvl.ERROR);
            };

            var config = new DiscordSocketConfig
            {
                MessageCacheSize    = 200,
                AlwaysDownloadUsers = true,
                LogLevel            = LogSeverity.Info,
#if DEBUG
                TotalShards = 1
#else
                TotalShards = 5,
#endif
            };

            _client = new DiscordShardedClient(config);

            _client.Log += Log;

            var lavaConfig = new LavaConfig
            {
                EnableResume      = true,
                LogSeverity       = LogSeverity.Verbose,
                ReconnectAttempts = 10,
                SelfDeaf          = true
            };

            _lavaNode = new LavaNode(_client, lavaConfig);

            await SetupKaguya();

            using (ServiceProvider services = new SetupServices().ConfigureServices(config, _client))
            {
                try
                {
                    GlobalPropertySetup(_botConfig);

                    SetupTwitch();

                    DiscordEventLogger.InitLogger();
                    GuildLogger.InitializeGuildLogListener();

                    await TestDatabaseConnection();

                    _client = services.GetRequiredService <DiscordShardedClient>();
                    await services.GetRequiredService <CommandHandler>().InitializeAsync();

                    await _client.LoginAsync(TokenType.Bot, _botConfig.Token);

                    await _client.StartAsync();

                    await _client.SetGameAsync($"v{ConfigProperties.Version}: Booting up!");

                    _client.ShardReady += async c =>
                    {
                        if (!_lavaNode.IsConnected)
                        {
                            await _lavaNode.ConnectAsync();
                        }
                    };

                    await InitializeTimers(AllShardsLoggedIn(_client, config));

                    _lavaNode.OnLog += async message => { await ConsoleLogger.LogAsync("[Kaguya Music]: " + message.Message, LogLvl.INFO); };

                    InitializeEventHandlers();

                    if (AllShardsLoggedIn(_client, config))
                    {
                        ConfigProperties.LavaNode = _lavaNode;
                        OsuBase.Client            = new OsuClient(new OsuSharpConfiguration
                        {
                            ApiKey = _botConfig.OsuApiKey
                        });
                    }

                    // Keep the app running.
                    await Task.Delay(-1);
                }
                catch (HttpException e)
                {
                    await ConsoleLogger.LogAsync("Error when logging into Discord:\n" +
                                                 "-Have you passed in the correct application arguments?\n" +
                                                 $"-Is your token correct? Exception: {e.Message}", LogLvl.ERROR);

                    Console.ReadLine();
                }
                catch (Exception e)
                {
                    await ConsoleLogger.LogAsync("Something really important broke!\n" +
                                                 $"Exception: {e.Message}\n" +
                                                 $"More information: {e}", LogLvl.ERROR);
                }
            }
        }
 public ProgressView()
 {
     setupServices = new SetupServices(new SystemFileHelper(),
                                       new WebDeployHelper(), new SetupRegistry(), new PackageResolver());
     InitializeComponent();
 }