Ejemplo n.º 1
0
        public TwitterConfig(bool autoLoad = false)
        {
            if (autoLoad)
            {
                string twitterConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), ConfigFilename);
                if (!File.Exists(twitterConfigPath))
                {
                    try
                    {
                        File.Copy(Path.Combine(Environment.CurrentDirectory, ConfigFilename), twitterConfigPath);
                    }
                    catch (Exception)
                    {
                        // If we can't find the resource file, just re-create it.  --Kris
                        File.WriteAllText(twitterConfigPath, JsonConvert.SerializeObject(new TwitterConfig()));
                    }
                }

                try
                {
                    ConfigJSON = File.ReadAllText(twitterConfigPath);
                }
                catch (Exception) { }

                if (string.IsNullOrWhiteSpace(ConfigJSON))
                {
                    ConsumerKey    = DEFAULT_CONSUMER_KEY;
                    ConsumerSecret = DEFAULT_CONSUMER_SECRET;
                }
                else
                {
                    TwitterConfig twitterConfig = Load();

                    ConsumerKey = (twitterConfig.ConsumerKey != null && !twitterConfig.ConsumerKey.Equals("YourConsumerKey")
                        ? twitterConfig.ConsumerKey : DEFAULT_CONSUMER_KEY);
                    ConsumerSecret = (twitterConfig.ConsumerSecret != null && !twitterConfig.ConsumerSecret.Equals("YourConsumerSecret")
                        ? twitterConfig.ConsumerSecret : DEFAULT_CONSUMER_SECRET);
                    AccessToken       = (twitterConfig.AccessToken != null && !twitterConfig.AccessToken.Equals("YourAccessToken") ? twitterConfig.AccessToken : null);
                    AccessTokenSecret = (twitterConfig.AccessTokenSecret != null && !twitterConfig.AccessTokenSecret.Equals("YourAccessTokenSecret") ? twitterConfig.AccessTokenSecret : null);
                }
            }
        }
Ejemplo n.º 2
0
        public BirdieLib(bool testMode = false, bool scriptMode = false, bool autoStart = false)
        {
            Active = BirdieStatus.Active;

            TwitterUsers = new Dictionary <string, TwitterUser>();
            TestMode     = testMode;
            ScriptMode   = scriptMode;

            Request = new Request();

            // Load config, stats, and retweet history.  --Kris
            string targetsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "targets.json");

            if (File.Exists(targetsPath))
            {
                try
                {
                    Targets = JsonConvert.DeserializeObject <Dictionary <string, Target> >(File.ReadAllText(targetsPath));
                }
                catch (Exception) { }
            }

            string retweetHistoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "retweetHistory.json");

            if (File.Exists(retweetHistoryPath))
            {
                try
                {
                    RetweetHistory = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(retweetHistoryPath));
                }
                catch (Exception) { }
            }

            TwitterConfig = new TwitterConfig(true);
            if (!string.IsNullOrWhiteSpace(TwitterConfig.AccessToken) && !string.IsNullOrWhiteSpace(TwitterConfig.AccessTokenSecret))
            {
                LoadTwitterCredentials();
            }

            TweetinviConfig.CurrentThreadSettings.TweetMode = TweetMode.Extended;
            TweetinviConfig.CurrentThreadSettings.InitialiseFrom(TweetinviConfig.ApplicationSettings);

            // Only Bernie's tweets are monitored by default.  --Kris
            if (Targets == null || Targets.Count == 0)
            {
                Targets = new Dictionary <string, Target>
                {
                    {
                        "Bernie Sanders", new Target("Bernie Sanders", new List <string>
                        {
                            "BernieSanders",
                            "SenSanders"
                        },
                                                     new Dictionary <int, string> // The score value is the number of retweets.  --Kris
                        {
                            { 0, "Poser" },
                            { 1, "Rookie Berner" },
                            { 50, "Volunteer" },
                            { 250, "Aspiring Revolutionary" },
                            { 500, "Birdie Bro" },
                            { 1000, "Berner" },
                            { 2500, "Fictional Chair-Thrower" },
                            { 5000, "Social Media Soldier" },
                            { 7000, "Berning Man" },
                            { 8000, "Diabolical Socalist" },
                            { 10000, "Berner-Elite" },
                            { 15000, "Revolutionary Legend" }
                        })
                    },
                    {
                        "Tulsi Gabbard", new Target("Tulsi Gabbard", new List <string> {
                            "TulsiGabbard"
                        },
                                                    new Dictionary <int, string>
                        {
                            { 0, "Poser" },
                            { 1, "Tulsi Gabbard Supporter" }
                        }, false)
                    },
                    {
                        "Jill Stein", new Target("Jill Stein", new List <string> {
                            "DrJillStein"
                        },
                                                 new Dictionary <int, string>
                        {
                            { 0, "Poser" },
                            { 1, "Jill Stein Supporter" }
                        }, false)
                    }
                };
            }

            if (RetweetHistory == null)
            {
                RetweetHistory = new Dictionary <string, string>();
            }

            TwitterUserFullnames = new Dictionary <string, string>
            {
                { "BernieSanders", "Bernie Sanders" },
                { "SenSanders", "Bernie Sanders" },
                { "TulsiGabbard", "Tulsi Gabbard" },
                { "DrJillStein", "Jill Stein" }
            };

            GetStats();

            if (autoStart)
            {
                Start();
            }
        }