public async Task TestGetSubreddit() { RedditApi api = new RedditApi(); Subreddit subreddit = await api.GetSubredditAsync(TestSubredditName); Assert.Equal(TestSubredditName, subreddit.Name); }
public void CheckChannels(ITextChannel channel) { try { foreach (Subreddit sr in reddits) { var sub = api.GetSubredditAsync(sr.Name).Result; var links = sub.GetNewLinksAsync(new ListingRequest { Limit = 1 }).Result; foreach (Link link in links.OfType <Link>()) { Console.WriteLine("__" + link.Title + " " + link.Url + " " + link.Permalink); if (sr.LastLink != null) { Console.WriteLine("__" + sr.LastLink); } if (sr.LastLink == null) { sr.LastLink = link.Url; } else if (!link.Url.ToLower().Equals(sr.LastLink.ToLower())) { DiscordUtil.SendMessage(channel, "New post in /r/" + sr.Name + "! https://www.reddit.com" + link.Permalink); sr.LastLink = link.Url; } } } } catch (Exception) { } }
public static async Task <List <Link> > HotNews(int limit, string after = null) { var redditService = new RedditApi(); var subreddit = await redditService.GetSubredditAsync("news"); var listings = await subreddit.GetHotLinksAsync(new ListingRequest { Limit = limit, After = after }); return(listings.Select((t, i) => (Link)listings.Children[i]).ToList()); }
public async Task TestGetNextListing() { RedditApi api = new RedditApi(); Subreddit subreddit = await api.GetSubredditAsync(TestSubredditName); Listing listing = await subreddit.GetNewLinksAsync(new ListingRequest { Limit = 1 }); Listing next = await listing.GetNextListingAsync(1); Assert.Equal(1, next.Count); }
public async Task Dankmeme() { try { RedditApi redditService = new RedditApi(); Subreddit subreddit = await redditService.GetSubredditAsync("dankmemes"); RedditNet.Things.Link link = await subreddit.GetRandomLinkAsync(); await ReplyAsync(link.Title + " - " + link.Url); } catch { await ReplyAsync("Sorry, I couldn't find a dank enough post!"); } }
public async Task TestSubredditSearch() { RedditApi api = new RedditApi(); Subreddit subreddit = await api.GetSubredditAsync(TestSubredditName); Listing listing = await subreddit.SearchAsync(new SearchRequest { Sort = SearchSort.Hot, Limit = 10 }); Assert.Equal(10, listing.Count); }
public async Task TestGetSubredditLinks() { RedditApi api = new RedditApi(); Subreddit subreddit = await api.GetSubredditAsync(TestSubredditName); Listing listing = await subreddit.GetNewLinksAsync(new ListingRequest { Limit = 5 }); var result = listing.ToList(); foreach (Thing thing in result) { Assert.IsAssignableFrom(typeof(Link), thing); } }
public async Task RandomPost([Summary("The subreddit to look for a random post")] string rsubreddit) { try { string filtered = Regex.Replace(rsubreddit, "/?r/", ""); RedditApi redditService = new RedditApi(); Subreddit subreddit = await redditService.GetSubredditAsync(filtered); RedditNet.Things.Link link = await subreddit.GetRandomLinkAsync(); await ReplyAsync(link.Title + " - " + link.Url); } catch { await ReplyAsync("Sorry, I couldn't find a random post in that subreddit!"); } }
public async Task <string> PostUrl(string title, string url, string subreddit) { PrepareClient(); Subreddit sub = await RedditApi.GetSubredditAsync(subreddit); try { Post post = await sub.SubmitPostAsync(title, url); return(new Uri(new Uri("https://reddit.com/"), post.Permalink).ToString()); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("reddit post fail: " + e.ToString()); throw e; } }
public async Task Dankmeme() { try { var redditService = new RedditApi(); var subreddit = await redditService.GetSubredditAsync("dankmemes"); var link = await subreddit.GetRandomLinkAsync(); await ReplyAsync(link.Title + " - " + link.Url); ConsoleHelper.Log($"{Helper.GetName(Context.User)} requested a dank meme.", LogSeverity.Info); } catch (Exception ex) { ConsoleHelper.Log($"Error getting random meme from /r/dankmemes! ({ex.Message})", LogSeverity.Error); await ReplyAsync("Sorry, I couldn't find a dank enough post!"); } }
public async Task RandomPost([Summary("The subreddit to look for a random post")] string rsubreddit) { try { string filtered = Regex.Replace(rsubreddit, "/?r/", ""); var redditService = new RedditApi(); var subreddit = await redditService.GetSubredditAsync(filtered); var link = await subreddit.GetRandomLinkAsync(); await ReplyAsync(link.Title + " - " + link.Url); ConsoleHelper.Log($"{Helper.GetName(Context.User)} requested a random link from /r/{filtered}.", LogSeverity.Info); } catch (Exception ex) { ConsoleHelper.Log($"Error getting random link from {rsubreddit}! ({ex.Message})", LogSeverity.Error); await ReplyAsync("Sorry, I couldn't find a random post in that subreddit!"); } }
static void Main(string[] args) { var api = new RedditApi(); var subreddit = api.GetSubredditAsync("noveltranslations").GetAwaiter().GetResult(); var links = subreddit.GetHotLinksAsync(new ListingRequest { Limit = 2 }).Result; foreach (Link link in links.OfType <Link>()) { Console.WriteLine($"Link - {link.Title}"); var comments = link.GetCommentsAsync(new GetCommentsRequest { Limit = 5 }).GetAwaiter().GetResult(); foreach (Comment comment in comments.OfType <Comment>()) { Console.WriteLine($"- Comment - \"{comment.Body}\" by {comment.Author}"); } More more = comments.LastOrDefault() as More; var someMoreComments = more?.Children.Take(2) ?? new List <string>(); foreach (string anotherComment in someMoreComments) { Comment aComment = subreddit.GetCommentAsync(new GetCommentRequest { LinkId = link.Id, CommentId = anotherComment }) .GetAwaiter().GetResult(); Console.WriteLine($"-- Another comment {aComment.Body}"); } } Console.WriteLine(); Console.WriteLine("Done!"); Console.ReadLine(); }