Exemple #1
0
        //Build a tweet with useful information about the pokemon, then cram in as many hashtags as will fit.
        private static string ComposeTweet(FoundPokemon pokemon)
        {
            PokewatchLogger.Log("[!]Composing Tweet.", AccountManager.GetAccountName(s_account));
            string latitude   = pokemon.Location.Latitude.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            string longitude  = pokemon.Location.Longitude.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            string mapsLink   = s_config.Pokevision ? $"https://pokevision.com/#/@{latitude},{longitude}" : $"https://www.google.com/maps/place/{latitude},{longitude}";
            string expiration = DateTime.Now.AddSeconds(pokemon.LifeExpectancy).ToLocalTime().ToShortTimeString();
            string tweet      = "";

            try
            {
                tweet = string.Format(s_config.PriorityPokemon.Contains(pokemon.Kind) ? s_config.PriorityTweet : s_config.RegularTweet,
                                      SpellCheckPokemon(pokemon.Kind),
                                      s_currentScan.Prefix,
                                      s_currentScan.Name,
                                      s_currentScan.Suffix,
                                      expiration,
                                      mapsLink);
            }
            catch
            {
                PokewatchLogger.Log("[-]Failed to format tweet. If you made customizations, they probably broke it.", AccountManager.GetAccountName(s_account));
                return(null);
            }

            tweet = Regex.Replace(tweet, @"\s\s", @" ");
            tweet = Regex.Replace(tweet, @"\s[!]", @"!");

            Regex hashtag = new Regex("[^a-zA-Z0-9]");

            if (s_config.TagPokemon && (Tweet.Length(tweet + " #" + hashtag.Replace(SpellCheckPokemon(pokemon.Kind), "")) < 140))
            {
                tweet += " #" + hashtag.Replace(SpellCheckPokemon(pokemon.Kind), "");
            }

            if (s_config.TagRegion && (Tweet.Length(tweet + " #" + hashtag.Replace(s_currentScan.Name, "")) < 140))
            {
                tweet += " #" + hashtag.Replace(s_currentScan.Name, "");
            }

            foreach (string tag in s_config.CustomTags)
            {
                if (Tweet.Length(tweet + " #" + hashtag.Replace(tag, "")) < 140)
                {
                    tweet += " #" + hashtag.Replace(tag, "");
                }
            }

            PokewatchLogger.Log("[!]Sucessfully composed tweet.", AccountManager.GetAccountName(s_account));
            return(tweet);
        }
Exemple #2
0
        private static bool Search()
        {
            RepeatedField <MapCell> mapCells = s_pogoSession.Map.Cells;

            foreach (var mapCell in mapCells)
            {
                foreach (WildPokemon pokemon in mapCell.WildPokemons)
                {
                    FoundPokemon foundPokemon = ProcessPokemon(pokemon, s_tweetedPokemon, s_lastTweet);

                    if (foundPokemon == null)
                    {
                        continue;
                    }

                    string tweet = ComposeTweet(foundPokemon);

                    if (tweet == null)
                    {
                        throw new Exception();
                    }

                    if (Tweet.Length(tweet) > 140)
                    {
                        PokewatchLogger.Log("[-]Tweet exceeds 140 characters. Consider changing your template: " + tweet, AccountManager.GetAccountName(s_account));
                        continue;
                    }
                    try
                    {
                        s_twitterClient.PublishTweet(tweet);
                        PokewatchLogger.Log("[+]Tweet published: " + tweet, AccountManager.GetAccountName(s_account));
                        s_lastTweet = DateTime.Now;
                    }
                    catch (Exception ex)
                    {
                        PokewatchLogger.Log("[-]Tweet failed to publish: " + tweet + " " + ex.Message, AccountManager.GetAccountName(s_account));
                    }

                    s_tweetedPokemon.Enqueue(foundPokemon);

                    if (s_tweetedPokemon.Count > 10)
                    {
                        s_tweetedPokemon.Dequeue();
                    }
                }
            }
            return(true);
        }
Exemple #3
0
        //Evaluate if a pokemon is worth tweeting about.
        private static FoundPokemon ProcessPokemon(WildPokemon pokemon, Queue <FoundPokemon> alreadyFound, DateTime lastTweet)
        {
            FoundPokemon foundPokemon = new FoundPokemon
            {
                Location = new Location {
                    Latitude = pokemon.Latitude, Longitude = pokemon.Longitude
                },
                Kind           = pokemon.PokemonData.PokemonId,
                LifeExpectancy = pokemon.TimeTillHiddenMs / 1000
            };

            if ((s_config.ExcludedPokemon.Contains(foundPokemon.Kind) && !(s_currentScan.Inclusions != null && s_currentScan.Inclusions.Contains(foundPokemon.Kind))) || (s_currentScan.Exclusions != null && s_currentScan.Exclusions.Contains(foundPokemon.Kind)))
            {
                PokewatchLogger.Log($"[!]Excluded: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}", AccountManager.GetAccountName(s_account));
                return(null);
            }

            if (foundPokemon.LifeExpectancy < s_config.MinimumLifeExpectancy || foundPokemon.LifeExpectancy > 1000)
            {
                PokewatchLogger.Log($"[!]Expiring: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}", AccountManager.GetAccountName(s_account));
                return(null);
            }

            if (alreadyFound.Contains(foundPokemon))
            {
                PokewatchLogger.Log($"[!]Duplicate: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}", AccountManager.GetAccountName(s_account));
                return(null);
            }

            if ((lastTweet + TimeSpan.FromSeconds(s_config.RateLimit) > DateTime.Now) && !s_config.PriorityPokemon.Contains(foundPokemon.Kind))
            {
                PokewatchLogger.Log($"[!]Limiting: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}", AccountManager.GetAccountName(s_account));
                return(null);
            }

            PokewatchLogger.Log($"[!]Tweeting: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}", AccountManager.GetAccountName(s_account));
            return(foundPokemon);
        }
Exemple #4
0
        //Build a tweet with useful information about the pokemon, then cram in as many hashtags as will fit.
        private static string ComposeTweet(FoundPokemon pokemon, Region region)
        {
            Log("[!]Composing Tweet");
            string latitude = pokemon.Location.Latitude.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            string longitude = pokemon.Location.Longitude.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            string mapsLink = $"https://www.google.com/maps/place/{latitude},{longitude}";
            string expiration = DateTime.Now.AddSeconds(pokemon.LifeExpectancy).ToLocalTime().ToShortTimeString();
            string tweet = "";

            if (s_config.PriorityPokemon.Contains(pokemon.Kind))
            {
                tweet = string.Format(s_config.PriorityTweet, SpellCheckPokemon(pokemon.Kind), region.Prefix, region.Name, region.Suffix, expiration, mapsLink);
            }
            else
            {
                tweet = string.Format(s_config.RegularTweet, SpellCheckPokemon(pokemon.Kind), region.Prefix, region.Name, region.Suffix, expiration, mapsLink);
            }

            tweet = Regex.Replace(tweet, @"\s\s", @" ");
            tweet = Regex.Replace(tweet, @"\s[!]", @"!");

            if (s_config.TagPokemon && (Tweet.Length(tweet + " #" + SpellCheckPokemon(pokemon.Kind, true)) < 138))
                tweet += " #" + SpellCheckPokemon(pokemon.Kind, true);

            if (s_config.TagRegion && (Tweet.Length(tweet + " #" + Regex.Replace(region.Name, @"\s+", "")) < 138))
                tweet += " #" + Regex.Replace(region.Name, @"\s+", "");

            foreach(string tag in s_config.CustomTags)
            {
                if(Tweet.Length(tweet + tag) < 138)
                    tweet += " #" + tag;
            }

            Log("[!]Sucessfully composed tweet.");
            return tweet;
        }
Exemple #5
0
        //Evaluate if a pokemon is worth tweeting about.
        private static FoundPokemon ProcessPokemon(WildPokemon pokemon, Queue<FoundPokemon> alreadyFound, DateTime lastTweet)
        {
            FoundPokemon foundPokemon = new FoundPokemon
            {
                Location = new Location { Latitude = pokemon.Latitude, Longitude = pokemon.Longitude},
                Kind = pokemon.PokemonData.PokemonId,
                LifeExpectancy = pokemon.TimeTillHiddenMs / 1000
            };

            if (s_config.ExcludedPokemon.Contains(foundPokemon.Kind))
            {
                Log($"[!]Excluded: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}");
                return null;
            }

            if (foundPokemon.LifeExpectancy < s_config.MinimumLifeExpectancy)
            {
                Log($"[!]Expiring: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}");
                return null;
            }

            if (alreadyFound.Contains(foundPokemon))
            {
                Log($"[!]Duplicate: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}");
                return null;
            }

            if ((lastTweet + TimeSpan.FromSeconds(s_config.RateLimit) > DateTime.Now) && !s_config.PriorityPokemon.Contains(foundPokemon.Kind))
            {
                Log($"[!]Limiting: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}");
                return null;
            }

            Log($"[!]Tweeting: {foundPokemon.Kind} ({foundPokemon.LifeExpectancy} seconds): {Math.Round(foundPokemon.Location.Latitude, 6)},{Math.Round(foundPokemon.Location.Longitude, 6)}");
            return foundPokemon;
        }
Exemple #6
0
        //Build a tweet with useful information about the pokemon, then cram in as many hashtags as will fit.
        private static string ComposeTweet(FoundPokemon pokemon, Region region)
        {
            Log("[!]Composing Tweet");
            string latitude = pokemon.Location.Latitude.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            string longitude = pokemon.Location.Longitude.ToString(System.Globalization.CultureInfo.GetCultureInfo("en-us"));
            string mapsLink = $"https://www.google.com/maps/place/{latitude},{longitude}";
            string expiration = DateTime.Now.AddSeconds(pokemon.LifeExpectancy).ToLocalTime().ToShortTimeString();
            string tweet = "";

            if (s_config.PriorityPokemon.Contains(pokemon.Type))
            {
                tweet = $"BREAKING NEWS: {SpellCheckPokemon(pokemon.Type)} has appeared {region.Prefix} {region.Name} {region.Suffix}! Hurry, it will vanish at {expiration}! {mapsLink}";
            }
            else
            {
                tweet = $"A wild {SpellCheckPokemon(pokemon.Type)} appeared! It will be {region.Prefix} {region.Name} {region.Suffix} until {expiration}. {mapsLink}";
            }

            tweet = Regex.Replace(tweet, @"\s\s", @" ");
            tweet = Regex.Replace(tweet, @"\s[!]", @"!");

            if (Tweet.Length(tweet + " #" + SpellCheckPokemon(pokemon.Type, true)) < 140)
                tweet += " #" + SpellCheckPokemon(pokemon.Type, true);

            if (Tweet.Length(tweet + " #PokemonGO") < 140)
                tweet += " #PokemonGO";

            return tweet;
        }