Skip to content

Commit

Permalink
Merge pull request #3754 from MineMalox/master
Browse files Browse the repository at this point in the history
Update Telegram: Fixes, /status, Sorting
  • Loading branch information
GrimmGringo committed Aug 9, 2016
2 parents 89618ca + 9703b50 commit 3d0ad39
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
2 changes: 1 addition & 1 deletion FeroxRev
6 changes: 3 additions & 3 deletions PoGo.NecroBot.CLI/Config/Translations/translation.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,15 @@
},
{
"Key": "ProfileStatsTemplateString",
"Value": "----- LVL {0} | {1} ----- \n Erfahrungspunkte: {2}/{3} \n Pokemons gefangen: {4} \n Pokemons verschickt: {5} \n Pokestops besucht: {6} \n Eier geschlüpft: {6} \n Pokemons entwickelt: {7} \n Pokedex Einträge: {8} \n KM gelaufen: {9}"
"Value": "----- LVL {0} | {1} ----- \n Erfahrungspunkte: {2}/{3} \n Pokemons gefangen: {4} \n Pokemons verschickt: {5} \n Pokestops besucht: {6} \n Eier geschlüpft: {7} \n Pokemons entwickelt: {8} \n Pokedex Einträge: {9} \n KM gelaufen: {10} \n Pokemons: {11}/{12}"
},
{
"Key": "ShowPokeTemplate",
"Value": " \n WP {0} | Name: {1}"
"Value": " \n WP {0} | IV : {1}% | Name: {2}"
},
{
"Key": "HelpTemplate",
"Value": "Kommandos: \n \n /top <amount> - Zeigt die besten Pokemons an. \n /all - Zeigt dir alle Pokemons an. \n /profile - Zeigt dein Profil. \n /loc - Zeigt deine Position an. \n /items - Zeigt dir deine Items"
"Value": "Kommandos: \n \n /top <cp/iv> <amount> - Zeigt die besten Pokemons an. \n /all <cp/iv> - Zeigt dir alle Pokemons an. \n /profile - Zeigt dein Profil. \n /loc - Zeigt deine Position an. \n /items - Zeigt dir deine Items \n /status - Zeigt den Status vom Bot. "
},
{
"Key": "StatsXpTemplateString",
Expand Down
6 changes: 3 additions & 3 deletions PoGo.NecroBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ public class Translation : ITranslation
new KeyValuePair<TranslationString, string>(TranslationString.StatsTemplateString,
"{0} - Runtime {1} - Lvl: {2} | EXP/H: {3:n0} | P/H: {4:n0} | Stardust: {5:n0} | Transfered: {6:n0} | Recycled: {7:n0}"),
new KeyValuePair<TranslationString, string>(TranslationString.ProfileStatsTemplateString,
"----- LVL {0} | {1} ----- \n Experience: {2}/{3} \n Pokemons caught: {4} \n Pokemons deployed: {5} \n Pokestops visited: {6} \n Eggs hatched: {6} \n Pokemons envolved: {7} \n Pokedex entries: {8} \n KM walked: {9}"),
"----- LVL {0} | {1} ----- \n Experience: {2}/{3} \n Pokemons caught: {4} \n Pokemons deployed: {5} \n Pokestops visited: {6} \n Eggs hatched: {7} \n Pokemons envolved: {8} \n Pokedex entries: {9} \n KM walked: {10} \n Pokemons: {11}/{12}"),
new KeyValuePair<TranslationString, string>(TranslationString.ShowPokeTemplate,
"\n CP {0} | Name: {1}"),
"\n CP: {0} | IV: {1}% | Name: {2}"),
new KeyValuePair<TranslationString, string>(TranslationString.HelpTemplate,
"Commands: \n \n /top <amount> - Shows you top Pokemons. \n /all - Shows you all Pokemons. \n /profile - Shows you profile. \n /loc - Shows you location. \n /items - Shows your items."),
"Commands: \n \n /top <cp/iv> <amount> - Shows you top Pokemons. \n /all <cp/iv> - Shows you all Pokemons. \n /profile - Shows you profile. \n /loc - Shows you location. \n /items - Shows your items. \n /status - Shows you the Status of the Bot. "),
new KeyValuePair<TranslationString, string>(TranslationString.StatsXpTemplateString,
"{0} (Advance in {1}h {2}m | {3:n0}/{4:n0} XP)"),
new KeyValuePair<TranslationString, string>(TranslationString.RequireInputText,
Expand Down
55 changes: 40 additions & 15 deletions PoGo.NecroBot.Logic/Service/TelegramService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Text;
using System.Threading.Tasks;
using PoGo.NecroBot.Logic.Common;
using PoGo.NecroBot.Logic.PoGoUtils;
using POGOProtos.Data;
using POGOProtos.Inventory.Item;
using Telegram.Bot;
using Telegram.Bot.Args;
Expand Down Expand Up @@ -36,8 +38,6 @@ public TelegramService(string apiKey, ISession session)

private async void OnTelegramMessageReceived(object sender, MessageEventArgs messageEventArgs)
{


var message = messageEventArgs.Message;

if (message == null || message.Type != MessageType.TextMessage)
Expand All @@ -56,16 +56,28 @@ private async void OnTelegramMessageReceived(object sender, MessageEventArgs mes
{
case "/top":
var times = 10;
if (messagetext.Length != 1)
var sortby = "cp";
if (messagetext.Length == 3)
{
times = Convert.ToInt32(messagetext[1]);
times = Convert.ToInt32(messagetext[2]);
} else if (messagetext.Length >= 2)
{
sortby = "iv";
}

var topPokemons = await session.Inventory.GetHighestsCp(times);
IEnumerable<PokemonData> topPokemons;
if (sortby == "iv")
{
topPokemons = await session.Inventory.GetHighestsPerfect(times);
}
else
{
topPokemons = await session.Inventory.GetHighestsCp(times);
}

foreach (var pokemon in topPokemons)
{
answerTextmessage += session.Translation.GetTranslation(TranslationString.ShowPokeTemplate, new object[] { pokemon.Cp, session.Translation.GetPokemonTranslation(pokemon.PokemonId) });
answerTextmessage += session.Translation.GetTranslation(TranslationString.ShowPokeTemplate, new object[] { pokemon.Cp, PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00"), session.Translation.GetPokemonTranslation(pokemon.PokemonId) });

if (answerTextmessage.Length > 3800)
{
Expand All @@ -80,11 +92,18 @@ private async void OnTelegramMessageReceived(object sender, MessageEventArgs mes
var myPokemons = await session.Inventory.GetPokemons();
var allMyPokemons = myPokemons.ToList();

var allPokemons = allMyPokemons.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
IEnumerable<PokemonData> allPokemons = await session.Inventory.GetHighestsCp(allMyPokemons.Count); ;
if (messagetext.Length == 2)
{
if (messagetext[1] == "iv")
{
allPokemons = await session.Inventory.GetHighestsPerfect(allMyPokemons.Count);
}
}

foreach (var pokemon in allPokemons)
{
answerTextmessage += session.Translation.GetTranslation(TranslationString.ShowPokeTemplate, new object[] { pokemon.Cp, session.Translation.GetPokemonTranslation(pokemon.PokemonId) });
answerTextmessage += session.Translation.GetTranslation(TranslationString.ShowPokeTemplate, new object[] { pokemon.Cp, PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00"), session.Translation.GetPokemonTranslation(pokemon.PokemonId) });

if (answerTextmessage.Length > 3800)
{
Expand All @@ -97,8 +116,9 @@ private async void OnTelegramMessageReceived(object sender, MessageEventArgs mes
case "/profile":
var stats = session.Inventory.GetPlayerStats().Result;
var stat = stats.FirstOrDefault();

answerTextmessage += session.Translation.GetTranslation(TranslationString.ProfileStatsTemplateString,

var myPokemons2 = await session.Inventory.GetPokemons();
answerTextmessage += session.Translation.GetTranslation(TranslationString.ProfileStatsTemplateString,
new object[]
{
stat.Level,
Expand All @@ -110,7 +130,9 @@ private async void OnTelegramMessageReceived(object sender, MessageEventArgs mes
stat.EggsHatched,
stat.Evolutions,
stat.UniquePokedexEntries,
stat.KmWalked
stat.KmWalked,
myPokemons2.ToList().Count,
session.Profile.PlayerData.MaxPokemonStorage
});
SendMessage(message.Chat.Id, answerTextmessage);
break;
Expand All @@ -128,14 +150,14 @@ private async void OnTelegramMessageReceived(object sender, MessageEventArgs mes
await inventory.GetItemAmountByType(ItemId.ItemMasterBall)
});
answerTextmessage += "\n";
answerTextmessage += session.Translation.GetTranslation(TranslationString.CurrentPotionInv,
new object[]
{
answerTextmessage += session.Translation.GetTranslation(TranslationString.CurrentPotionInv,
new object[]
{
await inventory.GetItemAmountByType(ItemId.ItemPotion),
await inventory.GetItemAmountByType(ItemId.ItemSuperPotion),
await inventory.GetItemAmountByType(ItemId.ItemHyperPotion),
await inventory.GetItemAmountByType(ItemId.ItemMaxPotion)
});
});
answerTextmessage += "\n";
answerTextmessage += session.Translation.GetTranslation(TranslationString.CurrentReviveInv,
new object[]
Expand All @@ -161,6 +183,9 @@ await session.Inventory.GetItemAmountByType(ItemId.ItemTroyDisk)
});
SendMessage(message.Chat.Id, answerTextmessage);
break;
case "/status":
SendMessage(message.Chat.Id, Console.Title);
break;
default:
answerTextmessage += session.Translation.GetTranslation(TranslationString.HelpTemplate);
SendMessage(message.Chat.Id, answerTextmessage);
Expand Down

0 comments on commit 3d0ad39

Please sign in to comment.