Exemplo n.º 1
0
        /*the main method*/
        public async Task MainAsync()
        {
            config = GetConfiguration();

            //construct the "bot"
            client = new DiscordSocketClient();
            var commands = new CommandService();

            var services = new ServiceCollection()
                           .AddSingleton(client)
                           .AddSingleton(commands)
                           .AddSingleton(config)
                           .AddSingleton <ConnectionService>()
                           .AddSingleton <CommandHandlingService>()
                           .AddSingleton <LoggingService>()
                           .BuildServiceProvider();

            //initialize the logging service
            services.GetRequiredService <LoggingService>();
            //connect to discord
            await services.GetRequiredService <ConnectionService>().StartAsync();

            //initialize the command handling service
            services.GetRequiredService <CommandHandlingService>();

            //sort the RemindMe file initially
            RemindMeService.SortTextFile();

            //start the timer that looks at the file for reminders
            Timer timer = new Timer(CheckIfNeedReminded, "some state", TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));

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