Exemple #1
0
        public static async Task Main(string[] args)
        {
            Console.Title = "Bot Ido";

            //Always download users to make sure we can always get them
            var config = new DiscordSocketConfig
            {
                AlwaysDownloadUsers = true
            };

            var interactiveConfig = new InteractiveServiceConfig
            {
                DefaultTimeout = TimeSpan.FromMinutes(10)
            };

            // Dependency injection. All objects use constructor injection.
            _client   = new DiscordSocketClient(config);
            _commands = new CommandService();
            _services = new ServiceCollection()
                        .AddSingleton(_client)
                        .AddSingleton(_commands)
                        .AddSingleton <GuildHandler>()
                        .AddSingleton <CommandHandler>()
                        .AddSingleton <LogHandler>()
                        .AddSingleton <UserHandler>()
                        .AddSingleton <ScheduleHandler>()
                        .AddSingleton <DataService>()
                        .AddSingleton <Random>()
                        .AddSingleton <GoogleCalendar>()
                        .AddSingleton <YouTube>()
                        .AddSingleton <ReservationService>()
                        .AddSingleton <PlaytestService>()
                        .AddSingleton <RconService>()
                        .AddSingleton <SrcdsLogService>()
                        .AddSingleton <VoiceChannelHandler>()
                        .AddSingleton <ToolsService>()
                        .AddSingleton <VerificationService>()
                        .AddSingleton <IHelpService, HelpService>()
                        .AddSingleton(s => new InteractiveService(_client, interactiveConfig))
                        .BuildServiceProvider();

            _dataService = _services.GetRequiredService <DataService>();
            _log         = _services.GetRequiredService <LogHandler>();
            _services.GetRequiredService <GuildHandler>();
            _services.GetRequiredService <ScheduleHandler>();
            await _services.GetRequiredService <CommandHandler>().InstallCommandsAsync();

            _services.GetRequiredService <UserHandler>();
            _services.GetRequiredService <VoiceChannelHandler>();
            _services.GetRequiredService <SrcdsLogService>();
            _services.GetRequiredService <ToolsService>();

            //Google APIs
            _services.GetRequiredService <GoogleCalendar>();
            _services.GetRequiredService <YouTube>();

            // Remember to keep token private or to read it from an
            // external source! In this case, we are reading the token
            // from an environment variable. If you do not know how to set-up
            // environment variables, you may find more information on the
            // Internet or by using other methods such as reading from
            // a configuration.

            await _client.LoginAsync(TokenType.Bot,
                                     _services.GetRequiredService <DataService>().RSettings.ProgramSettings.BotToken);

            _dataService.SetLogHandler(_services.GetRequiredService <LogHandler>());

            //Set handlers for static classes
            DatabaseUtil.SetHandlers(_services.GetRequiredService <LogHandler>(),
                                     _services.GetRequiredService <DataService>());
            DownloadHandler.SetHandlers(_services.GetRequiredService <LogHandler>(),
                                        _services.GetRequiredService <DataService>());
            GeneralUtil.SetHandlers(_services.GetRequiredService <LogHandler>(),
                                    _services.GetRequiredService <DataService>(), _services.GetRequiredService <Random>());
            DemoParser.SetHandlers(_services.GetRequiredService <LogHandler>(),
                                   _services.GetRequiredService <DataService>());
            HeatmapGenerator.SetHandlers(_services.GetRequiredService <LogHandler>(),
                                         _services.GetRequiredService <DataService>());

            await _client.StartAsync();

            // Block this task until the program is closed.
            await Task.Delay(-1);
        }