Esempio n. 1
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                logger.LogInformation("Starting up [Bot]");

                await facebookService.Init();

                discordClient.SubscribeToChannelMessage(OnChannelMessageReceived);
                await discordClient.CreateInitialConnection(botSettings.Discord.Token);

                logger.LogInformation("Started [Bot]");
                while (!stoppingToken.IsCancellationRequested)
                {
                    var hasNewPost = await facebookService.UpdateCachedPosts();
                    await SendNewPostNotification(hasNewPost);

                    await Task.Delay((int)TimeSpan.FromMinutes(PollTimeInMin).TotalMilliseconds, stoppingToken);
                }
            }
            catch (Exception e)
            {
                logger.LogError(e, "Error:");
            }
            finally
            {
                await discordClient.Disconnect();

                logger.LogInformation("Stopped [Bot]");
                applicationLifetime.StopApplication();
            }
        }