Esempio n. 1
0
        private void GUI_Load(object sender, EventArgs e)
        {
            // Create missing Files
            System.IO.Directory.CreateDirectory(Program.path);
            System.IO.Directory.CreateDirectory(Program.path_translation);

            // Load Languages Files always UP2Date

            WebClient client       = new WebClient();
            string    translations = client.DownloadString("http://pokemon-go.ar1i.xyz/lang/get.php");

            string[] transArray = translations.Replace("\r", "").Split('\n');
            for (int ijik = 0; ijik < transArray.Count(); ijik++)
            {
                client.DownloadFile("http://pokemon-go.ar1i.xyz/lang/" + transArray[ijik], Program.path_translation + "\\" + transArray[ijik]);
            }

            TranslationHandler.init();

            // Version Infoooo
            groupBox9.Text = "Your Version: " + Assembly.GetExecutingAssembly().GetName().Version + " | Newest: " + Program.getNewestVersion();
            if (Program.getNewestVersion() > Assembly.GetExecutingAssembly().GetName().Version)
            {
                DialogResult dialogResult = MessageBox.Show("There is an Update on Github. do you want to open it ?", "Newest Version: " + Program.getNewestVersion(), MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    Process.Start("https://github.com/Ar1i/PokemonGo-Bot");
                }
                else if (dialogResult == DialogResult.No)
                {
                    //nothing
                }
            }

            comboBox1.DisplayMember = "Text";
            var types = new[] {
                new { Text = "Google" },
                new { Text = "Pokemon Trainer Club" },
            };

            comboBox1.DataSource = types;

            //textBox1.Hide();
            //label2.Hide();
            //textBox2.Hide();
            //label3.Hide();

            var pokeIDS   = new Dictionary <string, int>();
            var evolveIDS = new Dictionary <string, int>();
            int i         = 1;
            int ev        = 1;

            foreach (PokemonId pokemon in Enum.GetValues(typeof(PokemonId)))
            {
                if (pokemon.ToString() != "Missingno")
                {
                    pokeIDS[pokemon.ToString()] = i;
                    gerEng[StringUtils.getPokemonNameGer(pokemon)] = pokemon.ToString();
                    if (checkBox8.Checked)
                    {
                        checkedListBox1.Items.Add(StringUtils.getPokemonNameGer(pokemon));
                        checkedListBox2.Items.Add(StringUtils.getPokemonNameGer(pokemon));
                        if (!(evolveBlacklist.Contains(i)))
                        {
                            checkedListBox3.Items.Add(StringUtils.getPokemonNameGer(pokemon));
                            evolveIDS[pokemon.ToString()] = ev;
                            ev++;
                        }
                    }
                    else
                    {
                        checkedListBox1.Items.Add(pokemon.ToString());
                        checkedListBox2.Items.Add(pokemon.ToString());
                        if (!(evolveBlacklist.Contains(i)))
                        {
                            checkedListBox3.Items.Add(pokemon.ToString());
                            evolveIDS[pokemon.ToString()] = ev;
                            ev++;
                        }
                    }
                    i++;
                }
            }

            if (File.Exists(Program.account))
            {
                string[] lines = System.IO.File.ReadAllLines(@Program.account);
                i = 1;
                int tb = 1;
                foreach (string line in lines)
                {
                    switch (i)
                    {
                    case 1:
                        if (line == "Google")
                        {
                            comboBox1.SelectedIndex = 0;
                        }
                        else
                        {
                            comboBox1.SelectedIndex = 1;
                        }
                        break;

                    case 9:
                        checkBox1.Checked = bool.Parse(line);
                        break;

                    case 10:
                        checkBox2.Checked = bool.Parse(line);
                        break;

                    case 12:
                        checkBox3.Checked = bool.Parse(line);
                        break;

                    case 14:
                        textBox18.Text = line;
                        break;

                    case 15:
                        textBox19.Text = line;
                        break;

                    case 16:
                        textBox20.Text = line;
                        break;

                    case 17:
                        //if (line == "1")
                        //{
                        //    Globals.navigation_option = 1;
                        //    checkBox8.Checked = true;
                        //    checkBox7.Checked = false;
                        //} else
                        //{
                        //    Globals.navigation_option = 2;
                        //    checkBox7.Checked = true;
                        //    checkBox8.Checked = false;
                        //}
                        break;

                    case 18:
                        checkBox7.Checked = bool.Parse(line);
                        break;

                    case 19:
                        checkBox8.Checked = bool.Parse(line);
                        break;

                    case 20:
                        checkBox9.Checked = bool.Parse(line);
                        break;

                    case 21:
                        textBox24.Text = line;
                        break;

                    case 22:
                        checkBox10.Checked = bool.Parse(line);
                        break;

                    case 23:
                        checkBox11.Checked = bool.Parse(line);
                        break;

                    case 24:
                        checkBox12.Checked = bool.Parse(line);
                        break;

                    //case 24:
                    //    checkBox12.Checked = bool.Parse(line);
                    //    break;
                    default:
                        TextBox temp = (TextBox)this.Controls.Find("textBox" + tb, true).FirstOrDefault();
                        temp.Text = line;
                        tb++;
                        break;
                    }
                    i++;
                }
            }
            else
            {
                textBox3.Text  = "40,764883";
                textBox4.Text  = "-73,972967";
                textBox5.Text  = "10";
                textBox6.Text  = "50";
                textBox7.Text  = "5000";
                textBox8.Text  = "3";
                textBox9.Text  = "999";
                textBox20.Text = "5000";
            }

            if (File.Exists(Program.items))
            {
                string[] lines = System.IO.File.ReadAllLines(@Program.items);
                i = 10;
                foreach (string line in lines)
                {
                    if (i == 18)
                    {
                        i = 22;
                    }
                    else if (i == 23)
                    {
                        i = 21;
                    }
                    else if (i == 22)
                    {
                        i = 23;
                    }
                    TextBox temp = (TextBox)this.Controls.Find("textBox" + i, true).FirstOrDefault();
                    temp.Text = line;
                    i++;
                }
            }
            else
            {
                textBox10.Text = "20";
                textBox11.Text = "50";
                textBox12.Text = "100";
                textBox13.Text = "20";
                textBox14.Text = "0";
                textBox15.Text = "0";
                textBox16.Text = "50";
                textBox17.Text = "75";
                textBox22.Text = "200";
                textBox21.Text = "100";
                textBox23.Text = "20";
                textBox24.Text = "90";
            }

            if (File.Exists(Program.keep))
            {
                string[] lines = System.IO.File.ReadAllLines(@Program.keep);
                foreach (string line in lines)
                {
                    if (line != "")
                    {
                        if (checkBox8.Checked)
                        {
                            checkedListBox1.SetItemChecked(pokeIDS[gerEng[line]] - 1, true);
                        }
                        else
                        {
                            checkedListBox1.SetItemChecked(pokeIDS[line] - 1, true);
                        }
                    }
                }
            }

            if (File.Exists(Program.ignore))
            {
                string[] lines = System.IO.File.ReadAllLines(@Program.ignore);
                foreach (string line in lines)
                {
                    if (line != "")
                    {
                        if (checkBox8.Checked)
                        {
                            checkedListBox2.SetItemChecked(pokeIDS[gerEng[line]] - 1, true);
                        }
                        else
                        {
                            checkedListBox2.SetItemChecked(pokeIDS[line] - 1, true);
                        }
                    }
                }
            }

            if (File.Exists(Program.lastcords))
            {
                try
                {
                    var    latlngFromFile = File.ReadAllText(Program.lastcords);
                    var    latlng = latlngFromFile.Split(':');
                    double latitude, longitude;
                    double.TryParse(latlng[0], out latitude);
                    double.TryParse(latlng[1], out longitude);
                    Globals.latitute  = latitude;
                    Globals.longitude = longitude;
                } catch
                {
                }
            }

            if (File.Exists(Program.evolve))
            {
                string[] lines = System.IO.File.ReadAllLines(@Program.evolve);
                foreach (string line in lines)
                {
                    if (line != "")
                    {
                        if (checkBox8.Checked)
                        {
                            checkedListBox3.SetItemChecked(evolveIDS[gerEng[line]] - 1, true);
                        }
                        else
                        {
                            checkedListBox3.SetItemChecked(evolveIDS[line] - 1, true);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// POST: api/Messages
        /// Receive a message from a user and reply to it
        /// </summary>
        //[ResponseType(typeof(void))]
        public async Task <HttpResponseMessage> Post([FromBody] Activity activity)
        {
            //trust Webchat & SMS channel
            MicrosoftAppCredentials.TrustServiceUrl(@"https://webchat.botframework.com", DateTime.MaxValue);
            MicrosoftAppCredentials.TrustServiceUrl(@"https://sms.botframework.com", DateTime.MaxValue);

            Trace.TraceInformation($"Incoming Activity is {activity.ToJson()}");
            if (activity.Type == ActivityTypes.Message)
            {
                if (!string.IsNullOrEmpty(activity.Text))
                {
                    //detect language of input text
                    var userLanguage = TranslationHandler.DetectLanguage(activity);

                    //save user's LanguageCode to Azure Table Storage
                    var message = activity as IMessageActivity;

                    try
                    {
                        using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
                        {
                            var botDataStore = scope.Resolve <IBotDataStore <BotData> >();
                            var key          = new AddressKey()
                            {
                                BotId          = message.Recipient.Id,
                                ChannelId      = message.ChannelId,
                                UserId         = message.From.Id,
                                ConversationId = message.Conversation.Id,
                                ServiceUrl     = message.ServiceUrl
                            };

                            var userData = await botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);

                            var storedLanguageCode = userData.GetProperty <string>(StringConstants.UserLanguageKey);

                            //update user's language in Azure Table Storage
                            if (storedLanguageCode != userLanguage)
                            {
                                userData.SetProperty(StringConstants.UserLanguageKey, userLanguage);
                                await botDataStore.SaveAsync(key, BotStoreType.BotUserData, userData, CancellationToken.None);

                                await botDataStore.FlushAsync(key, CancellationToken.None);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    //translate activity.Text to English before sending to LUIS for intent
                    activity.Text = TranslationHandler.TranslateTextToDefaultLanguage(activity, userLanguage);

                    await Conversation.SendAsync(activity, MakeRoot);
                }
            }
            else
            {
                HandleSystemMessage(activity);
            }
            var response = Request.CreateResponse(HttpStatusCode.OK);

            return(response);
        }
Esempio n. 3
0
        public async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            Message message = messageEventArgs.Message;

            if (message == null || message.Type != MessageType.TextMessage)
            {
                return;
            }
            _chatid = message.Chat.Id;
            try
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Red, "[TelegramAPI] Got Request from " + message.From.Username + " | " + message.Text);
                string username       = _clientSettings.TelegramName;
                string telegramAnswer = string.Empty;

                if (username != message.From.Username)
                {
                    using (System.IO.Stream stream = new System.IO.MemoryStream())
                    {
                        Properties.Resources.norights.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        stream.Position = 0;
                        await _telegram.SendPhotoAsync(_chatid, new FileToSend("norights.jpg", stream), replyMarkup : new ReplyKeyboardHide());
                    }
                    return;
                }

                // [0]-Commando; [1+]-Argument
                string[]         textCMD = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                TelegramUtilTask cmd     = getTask(textCMD[0]);
                switch (cmd)
                {
                case TelegramUtilTask.UNKNOWN:
                    telegramAnswer = string.Format("Usage:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}",
                                                   @"/stats - Get Current Stats",
                                                   @"/livestats - Enable/Disable Live Stats",
                                                   @"/information <topic> - Enable/Disable Information topics",
                                                   @"/top <HowMany?> - Outputs Top (?) Pokemons",
                                                   @"/forceevolve - Forces Evolve");
                    break;

                case TelegramUtilTask.GET_STATS:
                    var inventory = await _client.GetInventory();

                    var profil = await _client.GetProfile();

                    IEnumerable <PlayerStats> stats = inventory.InventoryDelta.InventoryItems
                                                      .Select(i => i.InventoryItemData.PlayerStats)
                                                      .Where(i => i != null);
                    foreach (PlayerStats ps in stats)
                    {
                        int l = ps.Level;

                        long   expneeded     = ((ps.NextLevelXp - ps.PrevLevelXp) - StringUtils.getExpDiff(ps.Level));
                        long   curexp        = ((ps.Experience - ps.PrevLevelXp) - StringUtils.getExpDiff(ps.Level));
                        double curexppercent = (Convert.ToDouble(curexp) / Convert.ToDouble(expneeded)) * 100;
                        string curloc        = _client.CurrentLat + "%20" + _client.CurrentLng;
                        curloc = curloc.Replace(",", ".");
                        string curlochtml = "https://www.google.de/maps/search/" + curloc + "/";
                        double shortenLng = Math.Round(_client.CurrentLng, 3);
                        double shortenLat = Math.Round(_client.CurrentLat, 3);
                        string pokemap    = shortenLat + ";" + shortenLng;
                        pokemap = pokemap.Replace(",", ".").Replace(";", ",");
                        string pokevishtml = "https://skiplagged.com/pokemon/#" + pokemap + ",14";
                        telegramAnswer +=
                            "\nNickname: " + profil.Profile.Username
                            + "\nLevel: " + ps.Level
                            + "\nEXP Needed: " + ((ps.NextLevelXp - ps.PrevLevelXp) - StringUtils.getExpDiff(ps.Level))
                            + $"\nCurrent EXP: {curexp} ({Math.Round(curexppercent)}%)"
                            + "\nEXP to Level up: " + ((ps.NextLevelXp) - (ps.Experience))
                            + "\nKM walked: " + ps.KmWalked
                            + "\nPokeStops visited: " + ps.PokeStopVisits
                            + "\nStardust: " + profil.Profile.Currency.ToArray()[1].Amount
                            + "\nPokemons: " + await _inventory.getPokemonCount() + "/" + profil.Profile.PokeStorage
                            + "\nItems: " + await _inventory.getInventoryCount() + " / " + profil.Profile.ItemStorage
                            + "\nCurentLocation:\n" + curlochtml
                            + "\nPokevision:\n" + pokevishtml;
                    }
                    break;

                case TelegramUtilTask.GET_TOPLIST:
                    int shows = 10;
                    if (textCMD.Length > 1 && !int.TryParse(textCMD[1], out shows))
                    {
                        telegramAnswer += $"Error! This is not a Number: {textCMD[1]}\nNevermind...\n";
                        shows           = 10; //TryParse error will reset to 0
                    }
                    telegramAnswer += "Showing " + shows + " Pokemons...\nSorting...";
                    await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide());

                    var myPokemons = await _inventory.GetPokemons();

                    myPokemons = myPokemons.OrderByDescending(x => x.Cp);
                    var profile = await _client.GetProfile();

                    telegramAnswer = $"Top {shows} Pokemons of {profile.Profile.Username}:";

                    IEnumerable <PokemonData> topPokemon = myPokemons.Take(shows);
                    foreach (PokemonData pokemon in topPokemon)
                    {
                        telegramAnswer += string.Format("\n{0} ({1})  |  CP: {2} ({3}% perfect)",
                                                        pokemon.PokemonId,
                                                        StringUtils.getPokemonNameGer(pokemon.PokemonId),
                                                        pokemon.Cp,
                                                        PokemonInfo.CalculatePokemonPerfection(pokemon));
                    }
                    break;

                case TelegramUtilTask.SWITCH_LIVESTATS:
                    _livestats = SwitchAndGetAnswer(_livestats, out telegramAnswer, "Live Stats");
                    break;

                case TelegramUtilTask.SWITCH_INFORMATION:
                    //_informations = SwitchAndGetAnswer(_informations, out telegramAnswer, "Information");
                    Array topics = Enum.GetValues(typeof(TelegramUtilInformationTopics));
                    if (textCMD.Length > 1)
                    {
                        if (textCMD[1] == "all-enable")
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer     += "Enabled information topic " + niceName + "\n";
                                _information[topic] = true;
                            }
                            break;
                        }
                        else if (textCMD[1] == "all-disable")
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer     += "Disabled information topic " + niceName + "\n";
                                _information[topic] = false;
                            }
                            break;
                        }
                        else
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer      = (_information[topic] ? "Dis" : "En") + "abled information topic " + niceName + "\n";
                                _information[topic] = !_information[topic];
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (TelegramUtilInformationTopics topic in topics)
                        {
                            String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                            telegramAnswer += " - " + niceName + "\n";
                            telegramAnswer += " -     " + _informationDescription[topic] + "\n";
                            telegramAnswer += " -     Currently " + (_information[topic] ? "enabled" : "disabled") + "\n";
                            telegramAnswer += "\n";
                        }

                        telegramAnswer += " - all-disable\n";
                        telegramAnswer += " -     " + TranslationHandler.getString("telegram-disable-all", "Disable all topics") + "\n";
                        telegramAnswer += "\n";

                        telegramAnswer += " - all-enable\n";
                        telegramAnswer += " -     " + TranslationHandler.getString("telegram-enable-all", "Enable all topics") + "\n";
                        telegramAnswer += "\n";
                        break;
                    }

                    break;

                case TelegramUtilTask.RUN_FORCEEVOLVE:
                    IEnumerable <PokemonData> pokemonToEvolve = await _inventory.GetPokemonToEvolve(null);

                    if (pokemonToEvolve.Count() > 3)
                    {
                        await _inventory.UseLuckyEgg(_client);
                    }
                    foreach (PokemonData pokemon in pokemonToEvolve)
                    {
                        if (_clientSettings.pokemonsToEvolve.Contains(pokemon.PokemonId))
                        {
                            var evolvePokemonOutProto = await _client.EvolvePokemon((ulong)pokemon.Id);

                            if (evolvePokemonOutProto.Result == EvolvePokemonOut.Types.EvolvePokemonStatus.PokemonEvolvedSuccess)
                            {
                                await _telegram.SendTextMessageAsync(_chatid, $"Evolved {pokemon.PokemonId} successfully for {evolvePokemonOutProto.ExpAwarded}xp", replyMarkup : new ReplyKeyboardHide());
                            }
                            else
                            {
                                await _telegram.SendTextMessageAsync(_chatid, $"Failed to evolve {pokemon.PokemonId}. EvolvePokemonOutProto.Result was {evolvePokemonOutProto.Result}, stopping evolving {pokemon.PokemonId}", replyMarkup : new ReplyKeyboardHide());
                            }
                            await RandomHelper.RandomDelay(1000, 2000);
                        }
                    }
                    telegramAnswer = "Done.";
                    break;
                }

                await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide());
            }
            catch (Exception ex)
            {
                if (ex is ApiRequestException)
                {
                    await _telegram.SendTextMessageAsync(_chatid, (ex as ApiRequestException).Message, replyMarkup : new ReplyKeyboardHide());
                }
            }
        }
Esempio n. 4
0
        }       //	getAD_Language

        /// <summary>
        ///	    Import Translation.
        //	Uses TranslationHandler to update translation
        /// </summary>
        /// <param name="directory">file</param>
        /// <param name="Trl_Table">table</param>
        /// <returns>status message</returns>
        public String ImportTrl(String directory, String Trl_Table)
        {
            String fileName = directory + "\\" + Trl_Table + "_" + _AD_Language + ".xml";

            log.Info(fileName);
            FileInfo inn = new FileInfo(fileName);

            if (!inn.Exists)
            {
                String msg = "File does not exist: " + fileName;
                log.Log(Level.SEVERE, msg);
                return(msg);
            }

            int       words  = _wordCount;
            XmlReader parser = null;

            try
            {
                bool   _isBaseLanguage = false;
                string _tableName      = "";

                TranslationHandler handler = new TranslationHandler(_AD_Client_ID);
                handler.SetByExportD(_InsertExportID);

                XmlReaderSettings factory = new XmlReaderSettings();

                factory.IgnoreComments = true;
                factory.IgnoreProcessingInstructions = true;
                factory.IgnoreWhitespace             = true;
                parser = XmlReader.Create(inn.FullName, factory);                       //
                while (parser.Read())
                {
                    try
                    {
                        switch (parser.NodeType)
                        {
                        case XmlNodeType.Element:
                            bool isEmptyElement = false;
                            isEmptyElement = parser.IsEmptyElement;
                            string        strURI   = parser.NamespaceURI;
                            string        strName  = parser.Name;
                            string        strlocal = parser.LocalName;
                            List <string> att      = new List <string>();
                            if (parser.HasAttributes)
                            {
                                for (int i = 0; i < parser.AttributeCount; i++)
                                {
                                    att.Add(parser.GetAttribute(i));
                                }
                            }

                            if (strURI.Equals(Translation.XML_TAG) || strURI.Equals(Translation.XML_TAG_Vienna) || strURI.Equals(Translation.XML_TAG_Adam))
                            {
                                string lang = att[0];               //attributes[Translation.XML_ATTRIBUTE_LANGUAGE].Value;
                                _isBaseLanguage = Language.IsBaseLanguage(lang);
                                _tableName      = att[1].ToUpper(); //attributes[Translation.XML_ATTRIBUTE_TABLE].Value;
                            }



                            handler.StartElement(strURI, strlocal, strName, att);
                            if (strName == "value")
                            {
                                if (att[1] != "")
                                {
                                    //preventive Check skip Name column updation for some tables
                                    if (_isBaseLanguage && lstTableHasDisplayCol.Contains(_tableName))
                                    {
                                        if (att[0].ToUpper() == "NAME")
                                        {
                                            break;
                                        }
                                    }

                                    if (parser.Read())
                                    {
                                        switch (parser.NodeType)
                                        {
                                        case XmlNodeType.Text:

                                            string trlValue = parser.Value;
                                            if (!String.IsNullOrEmpty(trlValue))
                                            {
                                                char[] ch = trlValue.ToCharArray();
                                                handler.Characters(ch);
                                            }
                                            break;
                                        }
                                    }
                                }
                            }
                            break;

                        case XmlNodeType.EndElement:
                            string URI  = parser.NamespaceURI;
                            string Name = parser.Name;
                            handler.EndElement(URI, "", Name);
                            break;
                        }
                    }
                    catch (Exception ec)
                    {
                        log.Info("error in importing record...Invalid Record.. in table " + Trl_Table + " error=>" + ec.Message);
                    }
                }
                _wordCount += handler.GetWordCount();
                log.Info("Updated=" + handler.GetUpdateCount() + ", Words=" + (_wordCount - words));
                if (parser != null)
                {
                    parser.Close();
                }
                return(Msg.GetMsg(_ctx, "Updated") + "=" + handler.GetUpdateCount());
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, "importTrl", e);
                if (parser != null)
                {
                    parser.Close();
                }
                return(e.ToString());
            }
        }       //	importTrl
Esempio n. 5
0
        public async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            Message message = messageEventArgs.Message;

            if (message == null || message.Type != MessageType.TextMessage)
            {
                return;
            }
            _chatid = message.Chat.Id;
            try
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Red, "[TelegramAPI] Got Request from " + message.From.Username + " | " + message.Text);
                string username       = _botSettings.TelegramName;
                string telegramAnswer = string.Empty;

                if (username != message.From.Username)
                {
                    using (System.IO.Stream stream = new System.IO.MemoryStream())
                    {
                        Properties.Resources.norights.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        stream.Position = 0;
                        await _telegram.SendPhotoAsync(_chatid, new FileToSend("norights.jpg", stream), replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                    }
                    return;
                }

                // [0]-Commando; [1+]-Argument
                var              msgText = message.Text;
                string[]         textCMD = msgText.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                TelegramUtilTask cmd     = getTask(textCMD[0]);
                switch (cmd)
                {
                case TelegramUtilTask.UNKNOWN:
                    telegramAnswer = string.Format("Usage:\r\n{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\n{6}\r\n{7}\r\n{8}\r\n{9}",
                                                   @"/stats - Get Current Stats",
                                                   @"/livestats - Enable/Disable Live Stats",
                                                   @"/information <topic> - Enable/Disable Information topics",
                                                   @"/top <HowMany?> - Outputs Top (?) Pokemons",
                                                   @"/transfer pokemon cp - transfer pokemons that matches with the given data",
                                                   @"/items  - Outputs Items List",
                                                   @"/drop item amount  - Throws the amount of items given",
                                                   @"/forceevolve - Forces Evolve",
                                                   @"/snipe pokemon latitude, longitude - snipe desired pokemon",
                                                   @"/stopbot - stop running bot");
                    break;

                case TelegramUtilTask.GET_STATS:
                    var ps = _client.Inventory.GetPlayerStats();

                    int    l             = ps.First().Level;
                    long   expneeded     = ((ps.First().NextLevelXp - ps.First().PrevLevelXp) - StringUtils.getExpDiff(ps.First().Level));
                    long   curexp        = ((ps.First().Experience - ps.First().PrevLevelXp) - StringUtils.getExpDiff(ps.First().Level));
                    double curexppercent = (Convert.ToDouble(curexp) / Convert.ToDouble(expneeded)) * 100;
                    string curloc        = _client.CurrentLatitude + "%20" + _client.CurrentLongitude;
                    curloc = curloc.Replace(",", ".");
                    string curlochtml = "https://www.google.com/maps/search/" + curloc + "/";
                    double shortenLng = Math.Round(_client.CurrentLongitude, 3);
                    double shortenLat = Math.Round(_client.CurrentLatitude, 3);
                    var    player     = _client.Player.GetPlayer();
                    telegramAnswer += "\nNickname: " + player.PlayerData.Username;
                    telegramAnswer += "\nLevel: " + ps.First().Level;
                    telegramAnswer += "\nEXP Needed: " + ((ps.First().NextLevelXp - ps.First().PrevLevelXp) - StringUtils.getExpDiff(ps.First().Level));
                    telegramAnswer += $"\nCurrent EXP: {curexp} ({Math.Round(curexppercent)}%)";
                    telegramAnswer += "\nEXP to Level up: " + ((ps.First().NextLevelXp) - (ps.First().Experience));
                    telegramAnswer += "\nKM walked: " + ps.First().KmWalked;
                    telegramAnswer += "\nPokeStops visited: " + ps.First().PokeStopVisits;
                    telegramAnswer += "\nStardust: " + player.PlayerData.Currencies.ToArray()[1].Amount;
                    telegramAnswer += "\nPokemons: " + (_client.Inventory.GetPokemons()).Count() + "/" + player.PlayerData.MaxPokemonStorage;
                    telegramAnswer += "\nItems: " + _client.Inventory.GetItems().Count() + " / " + player.PlayerData.MaxItemStorage;
                    telegramAnswer += "\nCurentLocation:\n" + curlochtml;
                    break;

                case TelegramUtilTask.GET_TOPLIST:
                    int shows = 10;
                    if (textCMD.Length > 1 && !int.TryParse(textCMD[1], out shows))
                    {
                        telegramAnswer += $"Error! This is not a Number: {textCMD[1]}\nNevermind...\n";
                        shows           = 10; //TryParse error will reset to 0
                    }
                    telegramAnswer += "Showing " + shows + " Pokemons...\nSorting...";
                    await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);

                    var myPokemons = _client.Inventory.GetPokemons();
                    myPokemons = myPokemons.OrderByDescending(x => x.Cp);
                    var PogoUsername = _client.Player.GetPlayer().PlayerData.Username;
                    telegramAnswer = $"Top {shows} Pokemons of {PogoUsername}:";

                    IEnumerable <PokemonData> topPokemon = myPokemons.Take(shows);
                    foreach (PokemonData pokemon in topPokemon)
                    {
                        telegramAnswer += string.Format("\n{0} |  CP: {1} ({2}% perfect)",
                                                        pokemon.PokemonId,
                                                        pokemon.Cp,
                                                        Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon), 2));
                    }
                    break;

                case TelegramUtilTask.SWITCH_LIVESTATS:
                    _livestats = SwitchAndGetAnswer(_livestats, out telegramAnswer, "Live Stats");
                    break;

                case TelegramUtilTask.SWITCH_INFORMATION:
                    //_informations = SwitchAndGetAnswer(_informations, out telegramAnswer, "Information");
                    Array topics = Enum.GetValues(typeof(TelegramUtilInformationTopics));
                    if (textCMD.Length > 1)
                    {
                        if (textCMD[1] == "all-enable")
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer     += "Enabled information topic " + niceName + "\n";
                                _information[topic] = true;
                            }
                            break;
                        }
                        else if (textCMD[1] == "all-disable")
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                telegramAnswer     += "Disabled information topic " + niceName + "\n";
                                _information[topic] = false;
                            }
                            break;
                        }
                        else
                        {
                            foreach (TelegramUtilInformationTopics topic in topics)
                            {
                                if (textCMD[1].ToLower() == topic.ToString().ToLower())
                                {
                                    String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                                    _information[topic] = !_information[topic];
                                    telegramAnswer      = (_information[topic] ? "En" : "Dis") + "abled information topic " + niceName + "\n";
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (TelegramUtilInformationTopics topic in topics)
                        {
                            String niceName = topic.ToString().Substring(0, 1).ToUpper() + topic.ToString().Substring(1).ToLower();
                            telegramAnswer += " - " + niceName + "\n";
                            telegramAnswer += " -     " + _informationDescription[topic] + "\n";
                            telegramAnswer += " -     Currently " + (_information[topic] ? "enabled" : "disabled") + "\n";
                            telegramAnswer += "\n";
                        }

                        telegramAnswer += " - all-disable\n";
                        telegramAnswer += " -     " + TranslationHandler.GetString("telegram-disable-all", "Disable all topics") + "\n";
                        telegramAnswer += "\n";

                        telegramAnswer += " - all-enable\n";
                        telegramAnswer += " -     " + TranslationHandler.GetString("telegram-enable-all", "Enable all topics") + "\n";
                        telegramAnswer += "\n";
                        break;
                    }

                    break;

                case TelegramUtilTask.RUN_FORCEEVOLVE:
                    IEnumerable <PokemonData> pokemonToEvolve = Setout.GetPokemonToEvolve(true);
                    if (pokemonToEvolve.Count() > 3)
                    {
                        Setout.UseLuckyEgg(_client);
                    }
                    foreach (PokemonData pokemon in pokemonToEvolve)
                    {
                        if (_botSettings.pokemonsToEvolve.Contains(pokemon.PokemonId))
                        {
                            var evolvePokemonOutProto = _client.Inventory.EvolvePokemon((ulong)pokemon.Id);
                            if (evolvePokemonOutProto.Result == POGOProtos.Networking.Responses.EvolvePokemonResponse.Types.Result.Success)
                            {
                                await _telegram.SendTextMessageAsync(_chatid, $"Evolved {pokemon.PokemonId} successfully for {evolvePokemonOutProto.ExperienceAwarded}xp", replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                            }
                            else
                            {
                                await _telegram.SendTextMessageAsync(_chatid, $"Failed to evolve {pokemon.PokemonId}. EvolvePokemonOutProto.Result was {evolvePokemonOutProto.Result}, stopping evolving {pokemon.PokemonId}", replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                            }
                            RandomHelper.RandomSleep(2000);
                        }
                    }
                    telegramAnswer = "Done.";
                    break;

                case TelegramUtilTask.RUN_SNIPE:
                    telegramAnswer = ProcessSnipeCommand(msgText.Replace(textCMD[0], "").Trim());
                    break;

                case TelegramUtilTask.FORCE_STOP:
                    var secs = 1;
                    if (textCMD.Length > 1)
                    {
                        int.TryParse(textCMD[1].Trim(), out secs);
                    }
                    telegramAnswer = $"Stopping bot in {secs} seconds";
                    await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);

                    _telegram.StopReceiving();
                    RandomHelper.RandomSleep(secs * 1000);
                    Environment.Exit(0);
                    break;

                case TelegramUtilTask.TRANSFER_POKEMON:
                    telegramAnswer = ProcessTransferPokemon(msgText.Replace(textCMD[0], "").Trim());
                    break;

                case TelegramUtilTask.GET_ITEMSLIST:
                    telegramAnswer = ProcessGetItemList();
                    break;

                case TelegramUtilTask.DROP_ITEM:
                    telegramAnswer = ProcessDropItem(msgText.Replace(textCMD[0], "").Trim());
                    break;
                }

                await _telegram.SendTextMessageAsync(_chatid, telegramAnswer, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                Logger.Debug(ex.ToString());
                var apiRequestException = ex as ApiRequestException;
                if (apiRequestException != null)
                {
                    await _telegram.SendTextMessageAsync(_chatid, apiRequestException.Message, replyMarkup : new ReplyKeyboardHide()).ConfigureAwait(false);
                }
            }
        }
Esempio n. 6
0
 public void Translate_TranllationThwowsExceptionIfNotFound(string fromWord, string fromLanguage, string toWord, string toLanguage)
 {
     TranslationHandler.AddEntry("Hello", "EN", "Привет", "RU");
     Assert.ThrowsException <Exception>(() => TranslationHandler.Translate(fromWord, fromLanguage, toLanguage), $"{fromWord} {fromLanguage} {toLanguage}");
 }
Esempio n. 7
0
 public void Translate_TranllationReturnsValidValue(string fromWord, string fromLanguage, string toWord, string toLanguage)
 {
     TranslationHandler.AddEntry(fromWord, fromLanguage, toWord, toLanguage);
     Assert.AreEqual(toWord, TranslationHandler.Translate(fromWord, fromLanguage, toLanguage));
 }
Esempio n. 8
0
 public void Translate_HasNullParameters(string fromWord, string fromLanguage, string toLanguage)
 {
     Assert.ThrowsException <ArgumentNullException>(() => TranslationHandler.Translate(null, fromLanguage, toLanguage));
     Assert.ThrowsException <ArgumentNullException>(() => TranslationHandler.Translate(fromWord, null, toLanguage));
     Assert.ThrowsException <ArgumentNullException>(() => TranslationHandler.Translate(fromWord, fromLanguage, null));
 }
Esempio n. 9
0
 public void Clear_TranllationCountIsZero(string fromWord, string fromLanguage, string toWord, string toLanguage)
 {
     TranslationHandler.AddEntry(fromWord, fromLanguage, toWord, toLanguage); //we don't check if it added because it's tested in other place
     TranslationHandler.Clear();
     Assert.AreEqual(0, TranslationHandler.Translations.Count);
 }
Esempio n. 10
0
 public void AddNewRecord_HasInvalidLanguage(string fromWord, string fromLanguage, string toWord, string toLanguage)
 {
     Assert.ThrowsException <ArgumentException>(() => TranslationHandler.AddEntry(fromWord, fromLanguage, toWord, toLanguage));
 }
Esempio n. 11
0
 public UnitTest1()
 {
     TranslationHandler.Clear();
 }
Esempio n. 12
0
        private void GUI_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Use at your own risk, Niantic is banning these days!");
            MessageBox.Show("Use the Bot only for 8 hours and turn off in afterwards for at least 2 hours + Spin per day not more than ~500-700 PokeStops and dont Catch more than ~500 Pokemon per day!!");
            _clientSettings = new Settings();
            // Create missing Files
            Directory.CreateDirectory(Program.path);
            Directory.CreateDirectory(Program.path_translation);
            Directory.CreateDirectory(devicePath);

            if (!File.Exists(deviceinfo))
            {
                var f = File.Create(deviceinfo);
                f.Close();
                File.WriteAllLines(deviceinfo, new string[] { "galaxy6", " " });
            }
            else
            {
                // Try to read the device name
                string[] arrLine = File.ReadAllLines(deviceinfo);
                try
                {
                    if (arrLine[0] != null)
                    {
                        comboBox2.Text = arrLine[0];
                    }
                } catch (Exception) {
                }
            }

            List <string> b = new List <string>();

            b.Add("de.json");
            b.Add("france.json");
            b.Add("italian.json");
            b.Add("ptBR.json");
            b.Add("ru.json");
            b.Add("spain.json");
            b.Add("tr.json");
            b.Add("th.json");

            foreach (var l in b)
            {
                Extract("PokemonGo.RocketAPI.Console", Program.path_translation, "Lang", l);
            }

            TranslationHandler.Init();

            // Version Infoooo
            groupBox9.Text = "Your Version: " + Assembly.GetExecutingAssembly().GetName().Version + " | Newest: " + Program.getNewestVersion();
            if (Program.getNewestVersion() > Assembly.GetExecutingAssembly().GetName().Version)
            {
                DialogResult dialogResult = MessageBox.Show("There is an Update on Pokecrot. do you want to redownload it ?", "Newest Version: " + Program.getNewestVersion(), MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    Process.Start("https://pokecrot.com/");
                }
                else if (dialogResult == DialogResult.No)
                {
                    //nothing
                }
            }

            comboBox1.DisplayMember = "Text";
            var types = new[] {
                new { Text = "Google" },
                new { Text = "Pokemon Trainer Club" },
            };

            comboBox1.DataSource = types;

            //textBox1.Hide();
            //label2.Hide();
            //textBox2.Hide();
            //label3.Hide();

            var pokeIDS   = new Dictionary <string, int>();
            var evolveIDS = new Dictionary <string, int>();
            int i         = 1;
            int ev        = 1;

            foreach (PokemonId pokemon in Enum.GetValues(typeof(PokemonId)))
            {
                if (pokemon.ToString() != "Missingno")
                {
                    pokeIDS[pokemon.ToString()] = i;
                    gerEng[StringUtils.getPokemonNameGer(pokemon)] = pokemon.ToString();
                    if (checkBox8.Checked)
                    {
                        checkedListBox1.Items.Add(StringUtils.getPokemonNameGer(pokemon));
                        checkedListBox2.Items.Add(StringUtils.getPokemonNameGer(pokemon));
                        if (!(evolveBlacklist.Contains(i)))
                        {
                            checkedListBox3.Items.Add(StringUtils.getPokemonNameGer(pokemon));
                            evolveIDS[pokemon.ToString()] = ev;
                            ev++;
                        }
                    }
                    else
                    {
                        checkedListBox1.Items.Add(pokemon.ToString());
                        checkedListBox2.Items.Add(pokemon.ToString());
                        if (!(evolveBlacklist.Contains(i)))
                        {
                            checkedListBox3.Items.Add(pokemon.ToString());
                            evolveIDS[pokemon.ToString()] = ev;
                            ev++;
                        }
                    }
                    i++;
                }
            }

            if (File.Exists(Program.account))
            {
                string[] lines = File.ReadAllLines(@Program.account);
                i = 1;
                int tb = 1;
                foreach (string line in lines)
                {
                    switch (i)
                    {
                    case 1:
                        if (line == "Google")
                        {
                            comboBox1.SelectedIndex = 0;
                        }
                        else
                        {
                            comboBox1.SelectedIndex = 1;
                        }
                        break;

                    case 9:
                        checkBox1.Checked = bool.Parse(line);
                        break;

                    case 10:
                        checkBox2.Checked = bool.Parse(line);
                        break;

                    case 12:
                        checkBox3.Checked = bool.Parse(line);
                        break;

                    case 14:
                        textBox18.Text = line;
                        break;

                    case 15:
                        textBox19.Text = line;
                        break;

                    case 16:
                        textBox20.Text = line;
                        break;

                    case 17:
                        //if (line == "1")
                        //{
                        //    Globals.navigation_option = 1;
                        //    checkBox8.Checked = true;
                        //    checkBox7.Checked = false;
                        //} else
                        //{
                        //    Globals.navigation_option = 2;
                        //    checkBox7.Checked = true;
                        //    checkBox8.Checked = false;
                        //}
                        break;

                    case 18:
                        checkBox7.Checked = bool.Parse(line);
                        break;

                    case 19:
                        checkBox8.Checked = bool.Parse(line);
                        break;

                    case 20:
                        checkBox9.Checked = bool.Parse(line);
                        break;

                    case 21:
                        textBox24.Text = line;
                        break;

                    case 22:
                        checkBox10.Checked = bool.Parse(line);
                        break;

                    case 23:
                        checkBox11.Checked = bool.Parse(line);
                        break;

                    case 24:
                        checkBox12.Checked = bool.Parse(line);
                        break;

                    case 25:
                        chkAutoIncubate.Checked = bool.Parse(line);
                        chkAutoIncubate_CheckedChanged(null, EventArgs.Empty);
                        break;

                    case 26:
                        chkUseBasicIncubators.Checked = bool.Parse(line);
                        break;

                    case 27:
                        checkBox15.Checked = bool.Parse(line);
                        break;

                    case 28:
                        //langSelected = line;
                        break;

                    case 29:
                        checkBox16.Checked = bool.Parse(line);
                        break;

                    case 30:
                        textBox26.Text = line;
                        break;

                    case 31:
                        checkBox17.Checked = bool.Parse(line);
                        break;

                    default:
                        TextBox temp = (TextBox)Controls.Find("textBox" + tb, true).FirstOrDefault();
                        temp.Text = line;
                        tb++;
                        break;
                    }
                    i++;
                }
            }
            else
            {
                textBox3.Text  = "40,764883";
                textBox4.Text  = "-73,972967";
                textBox5.Text  = "10";
                textBox6.Text  = "5";
                textBox7.Text  = "5000";
                textBox8.Text  = "3";
                textBox9.Text  = "999";
                textBox20.Text = "5000";
            }

            if (File.Exists(Program.items))
            {
                string[] lines = File.ReadAllLines(@Program.items);
                i = 10;
                foreach (string line in lines)
                {
                    if (i == 18)
                    {
                        i = 22;
                    }
                    else if (i == 23)
                    {
                        i = 21;
                    }
                    else if (i == 22)
                    {
                        i = 23;
                    }
                    TextBox temp = (TextBox)Controls.Find("textBox" + i, true).FirstOrDefault();
                    temp.Text = line;
                    i++;
                }
            }
            else
            {
                textBox10.Text = "20";
                textBox11.Text = "50";
                textBox12.Text = "100";
                textBox13.Text = "20";
                textBox14.Text = "0";
                textBox15.Text = "0";
                textBox16.Text = "50";
                textBox17.Text = "75";
                textBox22.Text = "200";
                textBox21.Text = "100";
                textBox23.Text = "20";
                textBox24.Text = "90";
            }

            if (File.Exists(Program.keep))
            {
                string[] lines = File.ReadAllLines(@Program.keep);
                foreach (string line in lines)
                {
                    if (line != string.Empty)
                    {
                        if (checkBox8.Checked)
                        {
                            checkedListBox1.SetItemChecked(pokeIDS[gerEng[line]] - 1, true);
                        }
                        else
                        {
                            checkedListBox1.SetItemChecked(pokeIDS[line] - 1, true);
                        }
                    }
                }
            }

            if (File.Exists(Program.ignore))
            {
                string[] lines = File.ReadAllLines(@Program.ignore);
                foreach (string line in lines)
                {
                    if (line != string.Empty)
                    {
                        if (checkBox8.Checked)
                        {
                            checkedListBox2.SetItemChecked(pokeIDS[gerEng[line]] - 1, true);
                        }
                        else
                        {
                            checkedListBox2.SetItemChecked(pokeIDS[line] - 1, true);
                        }
                    }
                }
            }

            if (File.Exists(Program.lastcords))
            {
                try
                {
                    var    latlngFromFile = File.ReadAllText(Program.lastcords);
                    var    latlng = latlngFromFile.Split(':');
                    double latitude, longitude;
                    double.TryParse(latlng[0], out latitude);
                    double.TryParse(latlng[1], out longitude);
                    Globals.latitute  = latitude;
                    Globals.longitude = longitude;
                }
                catch
                {
                }
            }

            if (File.Exists(Program.evolve))
            {
                string[] lines = File.ReadAllLines(@Program.evolve);
                foreach (string line in lines)
                {
                    if (line != string.Empty)
                    {
                        if (checkBox8.Checked)
                        {
                            checkedListBox3.SetItemChecked(evolveIDS[gerEng[line]] - 1, true);
                        }
                        else
                        {
                            checkedListBox3.SetItemChecked(evolveIDS[line] - 1, true);
                        }
                    }
                }
            }
            // Load Proxy Settings
            if (_clientSettings.UseProxyHost != string.Empty)
            {
                prxyIP.Text = _clientSettings.UseProxyHost;
            }

            if (_clientSettings.UseProxyPort != 0)
            {
                prxyPort.Text = "" + _clientSettings.UseProxyPort;
            }

            if (_clientSettings.UseProxyUsername != string.Empty)
            {
                prxyUser.Text = _clientSettings.UseProxyUsername;
            }

            if (_clientSettings.UseProxyPassword != string.Empty)
            {
                prxyPass.Text = "" + _clientSettings.UseProxyPassword;
            }

            if (prxyIP.Text != "HTTPS Proxy IP")
            {
                _clientSettings.UseProxyVerified = true;
            }
            else
            {
                _clientSettings.UseProxyVerified = false;
            }

            if (prxyUser.Text != "Proxy Username")
            {
                _clientSettings.UseProxyAuthentication = true;
            }
            else
            {
                _clientSettings.UseProxyAuthentication = false;
            }

            // Placeholder event add
            prxyIP.GotFocus   += new EventHandler(prxy_GotFocus);
            prxyPort.GotFocus += new EventHandler(prxy_GotFocus);
            prxyUser.GotFocus += new EventHandler(prxy_GotFocus);
            prxyPass.GotFocus += new EventHandler(prxy_GotFocus);
        }