public static void run() { var listing = new Listing("http://test.rafaelestevam.net/small/"); var pages = listing.GetListing(new ListingOptions()) .ToArray(); // to better viewing var tree = Listing.BuildTree(pages); // to see the structure, put a breakpoint [here] tree = tree; // put break point here foreach (var d in tree.GetAllDescendantsAndSelf()) { Console.WriteLine($"[D] {d.Entity.Uri}"); foreach (var files in d.Files) { Console.WriteLine($" > {files.FileName}"); } } }
private static async Task PostFromRedditAsync(RedditSubscriptionModel subscription) { try { var reddit = new Reddit(); Subreddit subreddit = reddit.GetSubreddit(subscription.Subreddit); Listing <Post> listings = subreddit.Hot; Program.Client.DebugLogger.Info("Checking Posts from subreddit: " + subscription.Subreddit); foreach (Post post in listings.GetListing(15)) { // See if one out of the ten posts are unique, if not, nothing will post string urlToPost = post.Url.ToString(); if (!subscription.PostedLinks.Contains(urlToPost)) { Program.Client.DebugLogger.Info("Posting URL: " + urlToPost); // Get the guild and channel to then post the message DiscordGuild guildToPostIn = await Program.Client.GetGuildAsync(subscription.DiscordGuildId); await guildToPostIn.GetChannel(subscription.ChannelId).SendMessageAsync(string.Format(redditPostFormat, post.Title, subscription.Subreddit, post.Permalink.ToString(), urlToPost)); //Notify users if keyword is triggered foreach (PersonalRedditNotification notification in RedditSubscriptionsFile.Instance.PersonalRedditSubscriptions) { if (post.Title.ToLower().Contains(notification.SubscribedKeyword.ToLower())) { await guildToPostIn.GetChannel(subscription.ChannelId).SendMessageAsync($"Keyword `{notification.SubscribedKeyword}` was triggered for {notification.UserMentionString}"); } } // add the post to the list so no repeats and save subscription.PostedLinks.Add(urlToPost); RedditSubscriptionsFile.Instance.SaveFile(); break; } } } catch (Exception ex) { Program.Client.DebugLogger.Critical(ex.StackTrace.ToString()); } }