Example #1
0
        public async Task StartAsync()
        {
            var isDown = false;

            while (true)
            {
                try
                {
                    if (DateTimeOffset.UtcNow.Second % 60 == 0)
                    {
                        await UpdateOnlineUsersAsync();
                    }

                    if (await CrawlAsync())
                    {
                        isDown = false;
                    }
                }
                catch
                {
                    if (!isDown)
                    {
                        isDown = true;
                        await DiscordFormatting.AnnounceDownAsync(_discord);
                    }
                }

                await WaitABitAsync();
            }
        }
Example #2
0
        private async Task <bool> CrawlAsync()
        {
            var items = await Forum.GetNewAsync();

            if (_consumedPosts.Count == 0)
            {
                // if we've consumed nothing, consume all the items
                // that way we don't spam #forums with non-new stuff
                _consumedPosts.AddRange(items.Select(x => x.PostId));
            }

            var filtered = items
                           .Where(item => !_consumedPosts.Contains(item.PostId))
                           .ToArray();

            foreach (var item in filtered)
            {
                _consumedPosts.Add(item.PostId);
                await DiscordFormatting.AnnouncePostAsync(_discord, item);
            }

            return(filtered.Any());
        }
Example #3
0
 private Embed GetMessageEmbed(IUserMessage message, int woots)
 {
     return(DiscordFormatting
            .BuildStarboardEmbed((IGuildUser)message.Author, message, woots, woots >= _configuredWoots).Build());
 }