private static void AuthorizeFimFictionBot() { if (string.IsNullOrEmpty(C.FimFiction.Token)) { string receiveStream = Get.FimFictionGetAuthToken(BotClient); FfAuthorization authorization = JsonConvert.DeserializeObject <FfAuthorization>(receiveStream); C.FimFiction.Token = authorization.access_token; Save.Config(); } BotClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); BotClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", C.FimFiction.Token); }
static void Main() { Console.Title = "BookHorseBot"; List <string> ignoredUsers = new List <string> { "nightmirrormoon" }; if (string.IsNullOrEmpty(Default.FF_Token)) { string receiveStream = FimFictionGetAuthToken(); FfAuthorization authorization = JsonConvert.DeserializeObject <FfAuthorization>(receiveStream); Default.FF_Token = authorization.access_token; Default.Save(); } BotClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); BotClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Default.FF_Token); BotWebAgent webAgent = new BotWebAgent(Default.R_Username, Default.R_Password, Default.R_client_id, Default.R_client_secret, "https://google.com"); Reddit reddit = new Reddit(webAgent, true); reddit.LogIn(Default.R_Username, Default.R_Password); string redditName = reddit.User.FullName; if (redditName.ToLower() == Default.R_Username.ToLower()) { Console.WriteLine("Logged in!"); } Subreddit subreddit = reddit.GetSubreddit("mylittlepony"); IEnumerable <Comment> comments = subreddit.CommentStream.Where(c => !ignoredUsers.Contains(c.AuthorName.ToLower()) && c.CreatedUTC >= DateTime.UtcNow.AddMinutes(-5) ); foreach (Comment comment in comments) { if (!comment.Body.Contains("{") && !comment.Body.Contains("}")) { continue; } Comment qualifiedComment = reddit.GetComment(new Uri(comment.Shortlink)); if (qualifiedComment.Comments.All(x => x.AuthorName != redditName)) { List <string> list = ExtractStoryNames(comment); if (list.Count > 0) { List <Story.Rootobject> stories = GetPostText(list); string postReplyBody = GeneratePostBody(stories); comment.Reply(postReplyBody); Console.WriteLine($"Reply posted to {comment.AuthorName}!"); } } } }