Esempio n. 1
0
 public static void Consume()
 {
     if (!_amIin)
     {
         if (!Login())
         {
             Console.WriteLine("Cannot login asshole! Fix it!");
             return;
         }
     }
     foreach (RedditTask task in _tasks)
     {
         RedditSharp.Things.Subreddit _sub = Central.reddit.GetSubreddit(task.SubReddit);
         if (task.OrderBy.ToUpper().Equals("HOT"))
         {
             _consumePosts(_sub.Hot, task.MaxPosts);
         }
         if (task.OrderBy.ToUpper().Equals("TOP"))
         {
             _consumePosts(_sub.GetTop(task.TOPTIME), task.MaxPosts);
         }
         if (task.OrderBy.ToUpper().Equals("NEW"))
         {
             _consumePosts(_sub.New, task.MaxPosts);
         }
     }
 }
Esempio n. 2
0
 public void ConsumeComments(string subreddit)
 {
     _subreddit = reddit.GetSubreddit(subreddit);
     foreach (var comment in _subreddit.CommentStream)
     {
         if (comment.AuthorName == _username)
         {
             _repliedToComments.Add((comment.Id));
             continue;
         }
         if (!_repliedToComments.Contains((comment.Id)))
         {
             string message    = "";
             int    numMatches = 0;
             FindCardsInBrackets(comment, ref message, ref numMatches);
             FindDecklist(comment, ref message, ref numMatches);
             message += "^^^[[cardname]] ^^^to ^^^call ^^^or ^^^post ^^^a ^^^decklist";
             try
             {
                 if (numMatches >= 1)
                 {
                     comment.Reply(message);
                 }
                 File.AppendAllText(_repliedCommentsFile, comment.Id + Environment.NewLine);
                 _repliedToComments.Add((comment.Id));
                 logger.Info("Processed Comment " + comment.Id + " by " + comment.AuthorName + ", there were " + numMatches + " matches");
             }
             catch (RedditException ex)
             {
                 logger.Error(ex.Message);
                 logger.Error(ex.StackTrace);
             }
         }
     }
 }
Esempio n. 3
0
        public bool RedditSetup()
        {
            string Username = string.Empty;
            string Password = string.Empty;

            string RedditLoginQuery = "SELECT * FROM User LIMIT 1";

            using (SQLiteCommand RedditLoginCommand = new SQLiteCommand(RedditLoginQuery, CurrentDB))
            {
                CurrentDB.Open();
                using (SQLiteDataReader RedditLogin = RedditLoginCommand.ExecuteReader())
                {
                    if (RedditLogin.Read())
                    {
                        Username = RedditLogin[0].ToString();
                        Password = RedditLogin[1].ToString();
                    }
                }
                CurrentDB.Close();
            }

            try
            {
                Reddit    = new Reddit(Username, Password, true);
                Subreddit = Reddit.GetSubreddit("/r/" + MainForm.GetSubreddit());

                return(true);
            }
            catch
            {
                MainForm.NewError("Failed reddit login");
                return(false);
            }
        }
Esempio n. 4
0
        static bool RedditSetup()
        {
            string Username = string.Empty;
            string Password = string.Empty;

            string RedditLoginQuery = "SELECT * FROM User LIMIT 1";

            using (SQLiteCommand RedditLoginCommand = new SQLiteCommand(RedditLoginQuery, CurrentDB))
            {
                using (SQLiteDataReader RedditLogin = RedditLoginCommand.ExecuteReader())
                {
                    if (RedditLogin.Read())
                    {
                        Username = RedditLogin[0].ToString();
                        Password = RedditLogin[1].ToString();
                    }
                }
            }

            try
            {
                Reddit    = new Reddit(Username, Password, true);
                Subreddit = Reddit.GetSubreddit("/r/" + SubredditName);

                return(true);
            }
            catch { return(false); }
        }
 public WallpaperGetter(Reddit reddit, RedditSharp.Things.Subreddit subReddit)
 {
     path     = @"C:\Wallpapers\";
     myReddit = reddit;
     client   = new WebClient();
     successfulDownloadCount = 0;
     this.subReddit          = subReddit;
     //this.subRedditName = @"/r/"+subRedditName;
 }
Esempio n. 6
0
        public WikiTests(AuthenticatedTestsFixture authenticatedFixture)
        {
            authFixture = authenticatedFixture;
            RedditSharp.WebAgent agent = new RedditSharp.WebAgent(authFixture.AccessToken);
            reddit = new RedditSharp.Reddit(agent);
            sub    = reddit.GetSubredditAsync(authFixture.Config["TestSubreddit"]).Result;

            var names = sub.GetWiki.GetPageNamesAsync().Result;

            if (!names.Select(n => n.ToLower()).Contains(WIKI_PAGE_NAME))
            {
                sub.GetWiki.EditPageAsync(WIKI_PAGE_NAME, "**test** content ***up*** in *hur*").Wait();
            }
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            //WebClient client = new WebClient();
            //client.DownloadFile(@"http://i.imgur.com/rt1xXSe.jpg", @"C:\Temp\test.jpeg");
            //client.DownloadFile(@"http://www.reddit.com/r/wallpapers/", @"C:\\Temp\tesePage.html");
            WallpaperGetter wallpaperGetter;
            Reddit          myReddit = new Reddit();

            RedditSharp.Things.Subreddit subReddit = null;
            do
            {
                try
                {
                    subReddit = Driver.GetSubredditName(myReddit);
                }
                catch (FileNotFoundException ex)
                {
                    Console.WriteLine("The requested subreddit was not found!");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }while(subReddit == null);

            try
            {
                wallpaperGetter = new WallpaperGetter(myReddit, subReddit);
                wallpaperGetter.GetWallpapers();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong!");
                Console.WriteLine(ex.Message);
            }
            Console.Read();
        }
Esempio n. 8
0
 public AutoModWrangler( RedditSharp.Things.Subreddit subreddit ) {
     Subreddit = subreddit;
 }
Esempio n. 9
0
        public bool RedditSetup()
        {
            string Username = string.Empty;
            string Password = string.Empty;

            string RedditLoginQuery = "SELECT * FROM User LIMIT 1";
            using (SQLiteCommand RedditLoginCommand = new SQLiteCommand(RedditLoginQuery, CurrentDB))
            {
                CurrentDB.Open();
                using (SQLiteDataReader RedditLogin = RedditLoginCommand.ExecuteReader())
                {
                    if (RedditLogin.Read())
                    {
                        Username = RedditLogin[0].ToString();
                        Password = RedditLogin[1].ToString();
                    }
                }
                CurrentDB.Close();
            }

            try
            {
                Reddit = new Reddit(Username, Password, true);
                Subreddit = Reddit.GetSubreddit("/r/" + MainForm.GetSubreddit());

                return true;
            }
            catch
            {
                MainForm.NewError("Failed reddit login");
                return false;
            }
        }
Esempio n. 10
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                //-user HFYBot -pass password -sub HFY -maxcount 500

                string username          = "";
                string password          = "";
                string subname           = "HFY"; // GetSubreddit will remove /r/ from the front anyways. Lowercase doesn't matter
                int    maxCount          = 500;
                int    maxDays           = 60;
                bool   fastcutoff        = false;
                bool   reallypost        = false;
                bool   verbose           = false;
                bool   quiet             = false;
                bool   showhelp          = false;
                string oAuthClientID     = "";
                string oAuthClientSecret = "";

                var optsParse = new NDesk.Options.OptionSet()
                {
                    { "user="******"{username} of the account to run this bot under (required).", v => { if (v != null)
                                                                                                     {
                                                                                                         username = v;
                                                                                                     }
                      } },
                    { "pass="******"{password} for the account to run this bot under (required).", v => { if (v != null)
                                                                                                      {
                                                                                                          password = v;
                                                                                                      }
                      } },
                    { "oauthid=", "{client id} as generated by https://www.reddit.com/prefs/apps (optional).", v => { if (v != null)
                                                                                                                      {
                                                                                                                          oAuthClientID = v;
                                                                                                                      }
                      } },
                    { "oauthsecret=", "{client secret} as generated by https://www.reddit.com/prefs/apps (optional).", v => { if (v != null)
                                                                                                                              {
                                                                                                                                  oAuthClientSecret = v;
                                                                                                                              }
                      } },
                    { "sub=", "{subbedit} to process (optional, defaults to HFY).", v => { if (v != null)
                                                                                           {
                                                                                               subname = v;
                                                                                           }
                      } },
                    { "maxcount=", "{max} # of posts to scan (optional, defaults to 500).", (int v) => maxCount = v },
                    { "maxdays=", "{max} # of days to scan into the past for unprocessed posts (optional, defaults to 60).", (int v) => maxDays = v },
                    { "fastcutoff", "if set, then only considers posts made after the last HFY bot comment.", v => { if (v != null)
                                                                                                                     {
                                                                                                                         fastcutoff = true;
                                                                                                                     }
                      } },
                    { "reallypost", "if set, the posts are actually made; if not set, then dumped to console.", v => { if (v != null)
                                                                                                                       {
                                                                                                                           reallypost = true;
                                                                                                                       }
                      } },
                    { "v|verbose", "if set, then progress lines are displayed as the posts and comments are built.", v => { if (v != null)
                                                                                                                            {
                                                                                                                                verbose = true;
                                                                                                                            }
                      } },
                    { "q|quiet", "if set, then as little output as possible is generated.", v => { if (v != null)
                                                                                                   {
                                                                                                       quiet = true;
                                                                                                   }
                      } },
                    { "h|help", "show this help.", v => { if (v != null)
                                                          {
                                                              showhelp = true;
                                                          }
                      } },
                };

                try
                {
                    List <string> leftovers = optsParse.Parse(args);
                }
                catch (NDesk.Options.OptionException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("Try 'hfybot --help' for more information.");
                    return;
                }

                if (showhelp)
                {
                    optsParse.WriteOptionDescriptions(Console.Out);
                    return;
                }

                if (username == "" || password == "")
                {
                    Console.WriteLine("Username and password must be supplied.");
                    System.Environment.Exit(0);
                }

                if (subname == "")
                {
                    Console.WriteLine("Subbedit name must be supplied.");
                    System.Environment.Exit(0);
                }

                if (maxCount < 1 || maxCount > 500)
                {
                    maxCount = 500; // enforce default
                }
                if (maxDays < 1 || maxDays > 90)
                {
                    maxDays = 60; // enforce default
                }
                if (verbose)
                {
                    quiet = false;
                }

                if (oAuthClientID != "" && oAuthClientSecret != "")
                {
                    // Log in via oauth (which still requires the username and password, but also a secondary username and password called a client id and secret)
                    if (!quiet)
                    {
                        Console.WriteLine("Logging in user {0} via OAUTH2 protocol...", username);
                    }

                    try
                    {
                        authProvider    = new AuthProvider(oAuthClientID, oAuthClientSecret, "http://reddit.com");
                        authTokenString = authProvider.GetOAuthToken(username, password);
                        if (authTokenString == "")
                        {
                            Console.WriteLine("Login for user {0} (user:{1}) refused, empty token returned.", oAuthClientID, username);
                            System.Environment.Exit(0);
                        }
                        if (verbose)
                        {
                            Console.WriteLine("Auth token is {0}", authTokenString);
                        }
                        reddit = new Reddit(authTokenString);
                    }
                    catch (System.Security.Authentication.AuthenticationException)
                    {
                        Console.WriteLine("Login for user {0} (user:{1}) refused.", oAuthClientID, username);
                        System.Environment.Exit(0);
                    }
                    catch (System.Net.WebException we)
                    {
                        Console.WriteLine("Network error when connecting to reddit. Please check your connection. {0}", we.ToString());
                        System.Environment.Exit(0);
                    }
                }
                else
                {
                    // Log in without oauth in a traditional mode.
                    if (!quiet)
                    {
                        Console.WriteLine("Logging in user {0}...", username);
                    }

                    try
                    {
                        reddit = new Reddit(username, password);
                    }
                    catch (System.Security.Authentication.AuthenticationException)
                    {
                        Console.WriteLine("Login for user {0} refused.", username);
                        System.Environment.Exit(0);
                    }
                    catch (System.Net.WebException we)
                    {
                        Console.WriteLine("Network error when connecting to reddit. Please check your connection. {0}", we.ToString());
                        System.Environment.Exit(0);
                    }
                }

                reddit.RateLimit = WebAgent.RateLimitMode.Burst;

                if (!quiet)
                {
                    Console.WriteLine("Login successful. Getting sub {0}...", subname);
                }

                RedditSharp.Things.Subreddit subit = reddit.GetSubreddit(subname);
                if (subit == null)
                {
                    Console.WriteLine("Subbedit {0} does not exist.", subname);
                    System.Environment.Exit(0);
                }

                if (!quiet)
                {
                    Console.WriteLine("Processing posts and creating new comments as needed (maxcount={0}, maxdays={1}).", maxCount, maxDays);
                    if (!reallypost)
                    {
                        Console.WriteLine("NOTE: running in TEST mode only, will not actually make comments.");
                    }
                }

                ProcessNewPosts prm = new ProcessNewPosts(reddit, subit);
                prm.Run(maxCount, maxDays, fastcutoff, reallypost, verbose);
            }
            catch (Exception e)
            {
                Console.WriteLine("General exception: {0}", e.ToString());
                System.Environment.Exit(0);
            }
        }
Esempio n. 11
0
        static bool RedditSetup()
        {
            string Username = string.Empty;
            string Password = string.Empty;

            string RedditLoginQuery = "SELECT * FROM User LIMIT 1";
            using (SQLiteCommand RedditLoginCommand = new SQLiteCommand(RedditLoginQuery, CurrentDB))
            {
                using (SQLiteDataReader RedditLogin = RedditLoginCommand.ExecuteReader())
                {
                    if (RedditLogin.Read())
                    {
                        Username = RedditLogin[0].ToString();
                        Password = RedditLogin[1].ToString();
                    }
                }
            }

            try
            {
                Reddit = new Reddit(Username, Password, true);
                Subreddit = Reddit.GetSubreddit("/r/" + SubredditName);

                return true;
            }
            catch { return false; }
        }
Esempio n. 12
0
 public AutoModWrangler(RedditSharp.Things.Subreddit subreddit)
 {
     Subreddit = subreddit;
 }