예제 #1
0
    public static async Task Main(string[] args)
    {
        InitUtils.InitStatic();
        await BuildInfoService.LoadVersion();

        var host   = CreateHostBuilder(args).Build();
        var config = host.Services.GetRequiredService <CoreConfig>();
        await host.Services.GetRequiredService <RedisService>().InitAsync(config);

        await host.RunAsync();
    }
예제 #2
0
        static Task Main(string[] args)
        {
            // Load configuration and run global init stuff
            var config = InitUtils.BuildConfiguration(args).Build();

            InitUtils.InitStatic();

            // Set up DI container and modules
            var services = BuildContainer(config);

            return(RunWrapper(services, async ct =>
            {
                var logger = services.Resolve <ILogger>().ForContext <Init>();

                // Initialize Sentry SDK, and make sure it gets dropped at the end
                using var _ = Sentry.SentrySdk.Init(services.Resolve <CoreConfig>().SentryUrl);

                // "Connect to the database" (ie. set off database migrations and ensure state)
                logger.Information("Connecting to database");
                await services.Resolve <IDatabase>().ApplyMigrations();

                // Init the bot instance itself, register handlers and such to the client before beginning to connect
                logger.Information("Initializing bot");
                var bot = services.Resolve <Bot>();
                bot.Init();

                // Install observer for request/responses
                DiscordRequestObserver.Install(services);

                // Start the Discord shards themselves (handlers already set up)
                logger.Information("Connecting to Discord");
                var info = await services.Resolve <DiscordApiClient>().GetGatewayBot();
                await services.Resolve <Cluster>().Start(info);
                logger.Information("Connected! All is good (probably).");

                // Lastly, we just... wait. Everything else is handled in the DiscordClient event loop
                try
                {
                    await Task.Delay(-1, ct);
                }
                catch (TaskCanceledException)
                {
                    // Once the CancellationToken fires, we need to shut stuff down
                    // (generally happens given a SIGINT/SIGKILL/Ctrl-C, see calling wrapper)
                    await bot.Shutdown();
                }
            }));
        }
예제 #3
0
    public static async Task Main(string[] args)
    {
        _metrics = AppMetrics.CreateDefaultBuilder()
                   .OutputMetrics.AsPrometheusPlainText()
                   .OutputMetrics.AsPrometheusProtobuf()
                   .Build();

        InitUtils.InitStatic();
        await BuildInfoService.LoadVersion();

        var host   = CreateHostBuilder(args).Build();
        var config = host.Services.GetRequiredService <CoreConfig>();
        await host.Services.GetRequiredService <RedisService>().InitAsync(config);

        await host.RunAsync();
    }
예제 #4
0
    private static async Task Main(string[] args)
    {
        // Load configuration and run global init stuff
        var config = InitUtils.BuildConfiguration(args).Build();

        InitUtils.InitStatic();

        await BuildInfoService.LoadVersion();

        var services = BuildContainer(config);

        var cfg = services.Resolve <CoreConfig>();

        if (cfg.UseRedisMetrics)
        {
            await services.Resolve <RedisService>().InitAsync(cfg);
        }

        services.Resolve <TaskHandler>().Run();

        await Task.Delay(-1);
    }
예제 #5
0
    private static async Task Main(string[] args)
    {
        // Load configuration and run global init stuff
        var config = InitUtils.BuildConfiguration(args).Build();

        InitUtils.InitStatic();

        // init version service
        await BuildInfoService.LoadVersion();

        // Set up DI container and modules
        var services = BuildContainer(config);

        await RunWrapper(services, async ct =>
        {
            var logger = services.Resolve <ILogger>().ForContext <Init>();

            // Initialize Sentry SDK, and make sure it gets dropped at the end

            using var _ = SentrySdk.Init(opts =>
            {
                opts.Dsn                 = services.Resolve <CoreConfig>().SentryUrl;
                opts.Release             = BuildInfoService.FullVersion;
                opts.AutoSessionTracking = true;
                opts.DisableTaskUnobservedTaskExceptionCapture();
            });

            var config     = services.Resolve <BotConfig>();
            var coreConfig = services.Resolve <CoreConfig>();

            // initialize Redis
            var redis = services.Resolve <RedisService>();
            if (config.UseRedisRatelimiter)
            {
                await redis.InitAsync(coreConfig);
            }

            if (config.Cluster == null)
            {
                // "Connect to the database" (ie. set off database migrations and ensure state)
                logger.Information("Connecting to database");
                await services.Resolve <IDatabase>().ApplyMigrations();

                // Clear shard status from Redis
                if (redis.Connection != null)
                {
                    await redis.Connection.GetDatabase().KeyDeleteAsync("pluralkit:shardstatus");
                }
            }

            // Init the bot instance itself, register handlers and such to the client before beginning to connect
            logger.Information("Initializing bot");
            var bot = services.Resolve <Bot>();
            bot.Init();


            // Start the Discord shards themselves (handlers already set up)
            logger.Information("Connecting to Discord");
            await StartCluster(services);
            logger.Information("Connected! All is good (probably).");

            // Lastly, we just... wait. Everything else is handled in the DiscordClient event loop
            try
            {
                await Task.Delay(-1, ct);
            }
            catch (TaskCanceledException)
            {
                // Once the CancellationToken fires, we need to shut stuff down
                // (generally happens given a SIGINT/SIGKILL/Ctrl-C, see calling wrapper)
                await bot.Shutdown();
            }
        });
    }
예제 #6
0
 public static void Main(string[] args)
 {
     InitUtils.InitStatic();
     CreateHostBuilder(args).Build().Run();
 }