public async Task GetStats() { string retStr = ""; //check if user is in role in order to proceed with the action var adminRole = IResolver.Current.ApplicationSettings.GetTripleZeroBotSettings().DiscordSettings.BotAdminRole; var userAllowed = DiscordRoles.UserInRole(Context, adminRole); if (!userAllowed) { retStr = "\nNot authorized!!!"; await ReplyAsync($"{retStr}"); return; } //get from cache if possible and exit sub string functionName = "stats-players"; string key = "all"; retStr = cacheClient.GetMessageFromModuleCache(functionName, key); if (!string.IsNullOrWhiteSpace(retStr)) { await ReplyAsync($"{retStr}"); return; } var result = IResolver.Current.MongoDBRepository.GetAllPlayersNoCharactersNoShips().Result; if (result != null) { //if (result.FirstOrDefault().LoadedFromCache) retStr += CacheClient.GetCachedDataRepositoryMessage(); if (result.FirstOrDefault().LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } retStr += string.Format("\nTotal players loaded to DB : **{0}** ", result.Count()); retStr += string.Format("\nSWGoH date - Latest: **{0}** - Oldest: **{1}** ", result.OrderByDescending(p => p.SWGoHUpdateDate).Take(1).FirstOrDefault().SWGoHUpdateDate, result.OrderBy(p => p.SWGoHUpdateDate).Take(1).FirstOrDefault().SWGoHUpdateDate); retStr += string.Format("\nDB date - Latest: **{0}** - Oldest: **{1}** ", result.OrderByDescending(p => p.EntryUpdateDate).Take(1).FirstOrDefault().EntryUpdateDate, result.OrderBy(p => p.EntryUpdateDate).Take(1).FirstOrDefault().EntryUpdateDate); } else { retStr = string.Format("\nSomething is wrong with stats -p!!!"); } await ReplyAsync($"{retStr}"); await cacheClient.AddToModuleCache(functionName, key, retStr); }
private async void SendSecondaryModReply(Player player, ModStatType modStatType, ModValueType secondaryStatValueType, List <Tuple <string, Mod> > result) { if (player.LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } string retStr = ""; if (result != null) { retStr += $"```css\n{modStatType.GetDescription()} secondary mods for player {player.PlayerName} - {player.PlayerNameInGame} \n```"; retStr += string.Format("```Last update : {0}(UTC)```\n", player.SWGoHUpdateDate.ToString("yyyy-MM-dd HH:mm:ss")); retStr += string.Format("Returned mods : {0}", result.Count()); foreach (var row in result) { var modStats = row.Item2.SecondaryStat.Where(p => p.StatType == modStatType && p.ValueType == secondaryStatValueType).FirstOrDefault(); var newString = string.Format("{3}: **{2}{4}** {1} {0}", row.Item1.PadRight(25), EnumExtensions.GetDescription(row.Item2.Type).ToString().PadRight(10), modStats.Value.ToString().PadRight(2), modStatType.ToString(), secondaryStatValueType == ModValueType.Percentage ? "%" : ""); retStr += "\n"; retStr += newString; if (retStr.Length > 1800) { await ReplyAsync($"{retStr}"); retStr = ""; } } if (retStr.Length > 0) { await ReplyAsync($"{retStr}"); } else { await ReplyAsync($"No mods found!"); } } else { retStr = $"I didn't find any mods for username {player.PlayerName}`"; await ReplyAsync($"{retStr}"); } }
public async Task GuildArena(string guildAlias) { guildAlias = guildAlias.Trim(); string retStr = "```Players```"; string loadingStr = $"```I am trying to load guild with alias '{guildAlias}' to show all arena teams```"; var messageLoading = await ReplyAsync($"{loadingStr}"); var guildConfig = IResolver.Current.GuildSettings.GetGuildConfigByAlias(guildAlias).Result; if (guildConfig == null) { await ReplyAsync($"I couldn't find any guild with alias ***{guildAlias}***"); await messageLoading.DeleteAsync(); return; } var characterConfig = IResolver.Current.CharacterSettings.GetCharactersConfig().Result; if (characterConfig == null) { await messageLoading.DeleteAsync(); await ReplyAsync($"I couldn't load character config!"); return; } //var result = IResolver.Current.MongoDBRepository.GetGuildPlayers(guildConfig.Name).Result; var playerData = IResolver.Current.MongoDBRepository.GetGuildPlayersArena(guildConfig.Name).Result.OrderBy(t => t.PlayerName); if (playerData.FirstOrDefault().LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } if (playerData == null || playerData.Count() == 0) { await messageLoading.DeleteAsync(); await ReplyAsync($"I couldn't find data for guild : ***{guildConfig.Name}***."); return; } Dictionary <string, string> dict = new Dictionary <string, string>(); retStr += $"```css\nArena Report for guild {guildConfig.Name}```"; retStr += "```Players```"; foreach (var player in playerData) { int count = 1; string leader = ""; List <string> aliasListNoLeader = new List <string>(); if (player.Arena == null) { continue; } foreach (var arenaCharacter in player.Arena.ArenaTeam) { var alias = characterConfig.Where(p => p.Name == arenaCharacter).FirstOrDefault()?.Aliases?.FirstOrDefault(); if (string.IsNullOrEmpty(alias)) { alias = arenaCharacter; } if (count == 1) { leader = string.Concat(alias, "(L)"); } else { aliasListNoLeader.Add(alias); } count += 1; } aliasListNoLeader.Sort(); List <string> aliasList = new List <string>(); aliasList.Add(leader); aliasList.AddRange(aliasListNoLeader); retStr += $"{player.PlayerName}({player.PlayerNameInGame}) - **{string.Join(", ", aliasList)}** - Average Rank : {player.Arena.AverageRank}\n"; dict.Add($"{player.PlayerName}({player.PlayerNameInGame}", $"{string.Join(", ", aliasList)}"); if (retStr.Length > 1800) { await ReplyAsync($"{retStr}"); retStr = ""; } } //if(messageLoading!=null) // await messageLoading.DeleteAsync(); await messageLoading.DeleteAsync(); if (!string.IsNullOrEmpty(retStr)) { await ReplyAsync($"{retStr}"); } var groupList = dict.GroupBy(r => r.Value).ToDictionary(t => t.Key, t => t.Select(r => r.Key).ToList()); var orderedList = groupList.OrderByDescending(p => p.Value.Count()).ThenBy(t => t.Key).ToList(); string retStr2 = "\n\n```Teams```"; foreach (var row in orderedList) { retStr2 += $"{row.Key} - **#{row.Value.Count()}**\n"; } await ReplyAsync($"{retStr2}"); }
public async Task GetSlackersLevel(string guildAlias) { guildAlias = guildAlias.Trim(); string retStr = ""; var guildConfig = IResolver.Current.GuildSettings.GetGuildConfigByAlias(guildAlias).Result; if (guildConfig == null) { await ReplyAsync($"I couldn't find any guild with alias ***{guildAlias}***"); return; } var res = await IResolver.Current.SWGoHRepository.GetGuildUnits(guildConfig.SWGoHId); if (res.FirstOrDefault().LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } int counter = 1; int totalRows = 300; try { for (int level = 1; level < 50; level++) { //var list = res.SelectMany(p => p.Players.Where(t => t.CombatType == UnitCombatType.Character && t.Level == level).ToList()); //var a = 1; var characters = (from character in res from players in character.Players.Where(t => t.CombatType == UnitCombatType.Character && t.Level == level) select new { character.Name, players } ).ToList().OrderBy(p => p.players.PlayerName); var listCharacters = characters.Select(x => new Tuple <string, GuildPlayerUnit>(x.Name, x.players)).ToList(); if (listCharacters.Count() == 0) { continue; } retStr += $"\n\n-------**Level {level}**-------"; foreach (var row in listCharacters.ToList()) { retStr += $"\n**{row.Item2.PlayerName}** : {row.Item1}"; if (retStr.Length > 1900) { await ReplyAsync($"{retStr}"); retStr = ""; } } //foreach (var guildCharacter in res) //{ // foreach (var player in guildCharacter.Players.Where(p => p.CombatType == UnitCombatType.Character)) // { // if (player.Level == level) // { // retStr += "\n"; // retStr += string.Format("{0} - {1} - level:{2}", player.PlayerName, guildCharacter.CharacterName, player.Level); // if (retStr.Length > 1800) // { // await ReplyAsync($"{retStr}"); // retStr = ""; // } // counter += 1; // if (counter > totalRows) break; // } // } //} if (counter > totalRows) { break; } } } catch (Exception ex) { Consoler.WriteLineInColor(string.Format("Slackers say : {0}", ex.Message), ConsoleColor.Red); } if (retStr.Length > 0) { await ReplyAsync($"{retStr}"); } }
public async Task GetPlayerReport(string playerUserName) { await Task.FromResult(1); playerUserName = playerUserName.Trim(); string retStr = ""; string loadingStr = ""; //get from cache if possible and exit sub string functionName = "player-report"; string key = playerUserName; retStr = cacheClient.GetMessageFromModuleCache(functionName, key); if (!string.IsNullOrWhiteSpace(retStr)) { await ReplyAsync($"{retStr}"); return; } loadingStr = string.Format("```{0} is loading...```", playerUserName); var messageLoading = await ReplyAsync($"{loadingStr}"); var playerData = IResolver.Current.MongoDBRepository.GetPlayer(playerUserName.ToLower()).Result; if (playerData == null) { await ReplyAsync($"I couldn't find data for player with name : ***{playerUserName}***."); return; } //validation need refactor for DI try { var validationResult = DefaultValidatorExtensions.Validate(new PlayerValidator(), playerData, ruleSet: "Basic,WithCharacter,WithShip"); if (!validationResult.IsValid) { await messageLoading.DeleteAsync(); await ReplyAsync(string.Join("\n", validationResult.Errors.Distinct())); return; } } catch (Exception ex) { await messageLoading.DeleteAsync(); await ReplyAsync($"Problem validating Player data - player-report {playerUserName}"); return; } if (playerData.LoadedFromCache) { await ReplyAsync($"{cacheClient.GetCachedDataRepositoryMessage()}"); } retStr += $"```css\nPlayer Report for {playerData.PlayerName} - {playerData.PlayerNameInGame} \n```"; retStr += string.Format("```Last update : {0}(UTC)```\n", playerData.SWGoHUpdateDate.ToString("yyyy-MM-dd HH:mm:ss")); var notActivatedChars = playerData.Characters.Where(p => p.Level == 0).ToList(); var notActivatedShips = playerData.Ships?.Where(p => p.Level == 0).ToList(); //stars characters var chars1star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 1).ToList(); var chars2star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 2).ToList(); var chars3star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 3).ToList(); var chars4star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 4).ToList(); var chars5star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 5).ToList(); var chars6star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 6).ToList(); var chars7star = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Stars == 7).ToList(); //stars ships var ships1star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 1).ToList(); var ships2star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 2).ToList(); var ships3star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 3).ToList(); var ships4star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 4).ToList(); var ships5star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 5).ToList(); var ships6star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 6).ToList(); var ships7star = playerData.Ships.Where(p => p.Level != 0).Where(p => p.Stars == 7).ToList(); //abilities var _allAbilities = (from _Character in playerData.Characters.Where(p => p.Abilities != null) from _Abilities in _Character.Abilities select new { _Character.Name, _Abilities } ).ToList(); var missingAbilitiesTop10 = _allAbilities.GroupBy(d => d.Name) .Select( g => new { Key = g.Key, SumLevels = g.Sum(s => s._Abilities.Level), SumMaxLevels = g.Sum(s => s._Abilities.MaxLevel), MissingLevels = g.Sum(s => s._Abilities.MaxLevel) - g.Sum(s => s._Abilities.Level) }).OrderByDescending(p => p.MissingLevels).Take(10); //level characters var charsLessThan50Level = playerData.Characters.Where(p => p.Level > 0 && p.Level < 50).ToList(); var chars50_59Level = playerData.Characters.Where(p => p.Level >= 50 && p.Level < 60).ToList(); var chars60_69Level = playerData.Characters.Where(p => p.Level >= 60 && p.Level < 70).ToList(); var chars70_79Level = playerData.Characters.Where(p => p.Level >= 70 && p.Level < 80).ToList(); var chars80_84Level = playerData.Characters.Where(p => p.Level >= 80 && p.Level < 85).ToList(); var chars85Level = playerData.Characters.Where(p => p.Level == 85).ToList(); //level characters var shipsLessThan50Level = playerData.Ships.Where(p => p.Level > 0 && p.Level < 50).ToList(); var ships50_59Level = playerData.Ships.Where(p => p.Level >= 50 && p.Level < 60).ToList(); var ships60_69Level = playerData.Ships.Where(p => p.Level >= 60 && p.Level < 70).ToList(); var ships70_79Level = playerData.Ships.Where(p => p.Level >= 70 && p.Level < 80).ToList(); var ships80_84Level = playerData.Ships.Where(p => p.Level >= 80 && p.Level < 85).ToList(); var ships85Level = playerData.Ships.Where(p => p.Level == 85).ToList(); //number of mods var noMods = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Mods == null || p.Mods.Count == 0).ToList(); var oneMod = playerData.Characters.Where(p => p.Mods != null).Where(p => p.Mods.Count() == 1).ToList(); var twoMod = playerData.Characters.Where(p => p.Mods != null).Where(p => p.Mods.Count() == 2).ToList(); var threeMod = playerData.Characters.Where(p => p.Mods != null).Where(p => p.Mods.Count() == 3).ToList(); var fourMod = playerData.Characters.Where(p => p.Mods != null).Where(p => p.Mods.Count() == 4).ToList(); var fiveMod = playerData.Characters.Where(p => p.Mods != null).Where(p => p.Mods.Count() == 5).ToList(); var sixMod = playerData.Characters.Where(p => p.Mods != null).Where(p => p.Mods.Count() == 6).ToList(); //mods level var _allMods = (from _Character in playerData.Characters.Where(p => p.Mods != null) from _Mods in _Character.Mods select new { _Character.Name, _Mods } ).ToList(); var modsLevelLessThan9 = _allMods.Where(p => p._Mods.Level < 9).ToList(); var modsLevel9_11 = _allMods.Where(p => p._Mods.Level >= 9 && p._Mods.Level <= 11).ToList(); var modsLevel12_14 = _allMods.Where(p => p._Mods.Level >= 12 && p._Mods.Level <= 14).ToList(); var modsLevel15 = _allMods.Where(p => p._Mods.Level == 15).ToList(); //gear var gearLessThan5 = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Gear < 5).ToList(); var gear5_7 = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Gear >= 5 && p.Gear <= 7).ToList(); var gear8_9 = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Gear >= 8 && p.Gear <= 9).ToList(); var gear10 = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Gear == 10).ToList(); var gear11 = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Gear == 11).ToList(); var gear12 = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Gear == 12).ToList(); //power var powerLessThan6k = playerData.Characters.Where(p => p.Level != 0).Where(p => p.Power < 6000).ToList(); //build post string retStr += string.Format("{0} characters **not activated** (from total characters : {1})\n", notActivatedChars.Count(), playerData.Characters.Count()); retStr += string.Format("{0} ships **not activated** (from total ships : {1})\n", notActivatedShips.Count(), playerData.Ships.Count()); retStr += string.Format("Total GP: `{0}`\n", playerData.GalacticPowerShips + playerData.GalacticPowerCharacters); retStr += string.Format("Toons GP: `{0}`\n", playerData.GalacticPowerCharacters); retStr += string.Format("Ships GP: `{0}`\n", playerData.GalacticPowerShips); retStr += "\n**Stars Characters**\n"; retStr += string.Format("**1*** : {0}\n", chars1star.Count()); retStr += string.Format("**2*** : {0}\n", chars2star.Count()); retStr += string.Format("**3*** : {0}\n", chars3star.Count()); retStr += string.Format("**4*** : {0}\n", chars4star.Count()); retStr += string.Format("**5*** : {0}\n", chars5star.Count()); retStr += string.Format("**6*** : {0}\n", chars6star.Count()); retStr += string.Format("**7*** : {0}\n", chars7star.Count()); retStr += "\n**Stars Ships**\n"; retStr += string.Format("**1*** : {0}\n", ships1star.Count()); retStr += string.Format("**2*** : {0}\n", ships2star.Count()); retStr += string.Format("**3*** : {0}\n", ships3star.Count()); retStr += string.Format("**4*** : {0}\n", ships4star.Count()); retStr += string.Format("**5*** : {0}\n", ships5star.Count()); retStr += string.Format("**6*** : {0}\n", ships6star.Count()); retStr += string.Format("**7*** : {0}\n", ships7star.Count()); retStr += "\n**Abilities**\n"; foreach (var character in missingAbilitiesTop10) { retStr += string.Format("{0} is missing **{1} abilities**\n", character.Key, character.MissingLevels); } retStr += "\n**Level Characters**\n"; retStr += string.Format("**lvl<50** : {0}\n", charsLessThan50Level.Count()); retStr += string.Format("**lvl 50-59** : {0}\n", chars50_59Level.Count()); retStr += string.Format("**lvl 60-69** : {0}\n", chars60_69Level.Count()); retStr += string.Format("**lvl 70-79** : {0}\n", chars70_79Level.Count()); retStr += string.Format("**lvl 80-84** : {0}\n", chars80_84Level.Count()); retStr += string.Format("**lvl 85** : {0}\n", chars85Level.Count()); retStr += "\n**Level Ships**\n"; retStr += string.Format("**lvl<50** : {0}\n", shipsLessThan50Level.Count()); retStr += string.Format("**lvl 50-59** : {0}\n", ships50_59Level.Count()); retStr += string.Format("**lvl 60-69** : {0}\n", ships60_69Level.Count()); retStr += string.Format("**lvl 70-79** : {0}\n", ships70_79Level.Count()); retStr += string.Format("**lvl 80-84** : {0}\n", ships80_84Level.Count()); retStr += string.Format("**lvl 85** : {0}\n", ships85Level.Count()); retStr += "\n**Mods**\n"; retStr += string.Format("{0} activated characters with **no mods** : {0}\n", noMods.Count()); retStr += string.Format("**1 mod** : {0}\n", oneMod.Count()); retStr += string.Format("**2 mods** : {0}\n", twoMod.Count()); retStr += string.Format("**3 mods** : {0}\n", threeMod.Count()); retStr += string.Format("**4 mods** : {0}\n", fourMod.Count()); retStr += string.Format("**5 mods** : {0}\n", fiveMod.Count()); retStr += string.Format("**6 mods** : {0}\n", sixMod.Count()); retStr += "\n**Mods Level**\n"; retStr += string.Format("{0} mods at **level <9**\n", modsLevelLessThan9.Count()); retStr += string.Format("{0} mods at **level 9-11**\n", modsLevel9_11.Count()); retStr += string.Format("{0} mods at **level 12-14**\n", modsLevel12_14.Count()); retStr += string.Format("{0} mods at **level 15**\n", modsLevel15.Count()); retStr += "\n**Gear**\n"; retStr += string.Format("**4 or less** : {0}\n", gearLessThan5.Count()); retStr += string.Format("**5-7** : {0}\n", gear5_7.Count()); retStr += string.Format("**8-9** : {0}\n", gear8_9.Count()); retStr += string.Format("**10** : {0}\n", gear10.Count()); retStr += string.Format("**11** : {0}\n", gear11.Count()); retStr += string.Format("**12** : {0}\n", gear12.Count()); //power less than 6k retStr += "\n**Power**\n"; retStr += string.Format("{0} characters with **less than 6000 power**\n", powerLessThan6k.Count()); await cacheClient.AddToModuleCache(functionName, key, retStr); await ReplyAsync($"{retStr}"); await messageLoading.DeleteAsync(); }