public async Task GetRecentMatchesAsync([Remainder] string summonerName) { summonerName = FirstLetterToUpper(summonerName); // We normalize the name to account for any capitlizations var matches = await Task.Run(() => LeagueofLegends.GetRecentGamesAsync(summonerName)); if (matches != null) { var counter = 0; var recentGamesString = ""; foreach (var match in matches.Matches) { counter++; var champ = await Task.Run(() => LeagueofLegends.GetChampionInfoAsync((int)match.ChampionID)) .ConfigureAwait(false); var matchInfo = await Task.Run(() => LeagueofLegends.GetMatchInfo(match.GameId)); var time = matchInfo.GameDuration; var matchDetails = LeagueofLegends.GetMatchInfo(matchInfo.GameId); var result = matchDetails.Result; recentGamesString += Format.Code( $"Game: {counter}{Environment.NewLine}Game ID: {match.GameId}{Environment.NewLine}Game Mode: {matchInfo.GameMode}{Environment.NewLine}Lane: {match.Lane.ToString()}{Environment.NewLine}Role: {match.Role}{Environment.NewLine}Season: {FormatSeason(matchInfo.SeasonId)}{Environment.NewLine}Champion: {champ.Name}{Environment.NewLine}Game Length: {ConvertTime(time)}") + Environment.NewLine; } await ReplyAsync($"Last 5 games:{Environment.NewLine}" + recentGamesString); } else { await ReplyAsync("There was an error retrieving recent games. The error has been logged."); } }
public async Task GetMatchInfoAsync([Remainder] long gameId) { var match = await Task.Run(() => LeagueofLegends.GetMatchInfo(gameId)); var matchEx = new MatchExtend(match); var header = string.Format("{0,-25} {1,-15} {2,-8} {3,-15} {4,-13} {5,-15} {6,-15}", "Name:", "Highest Tier:", "Lane:", "Role:", "KDA:", "Damage Dealt:", "Damage Taken:"); var playerStrings = new List <string>(); var titles = new List <string>(); if (match != null) { foreach (var team in matchEx.Teams) { var didTeamWin = team.Stats.Win; var towerKills = team.Stats.TowerKills; var firstBlood = team.Stats.FirstBlood; foreach (var person in team.Participants) { var name = person.SummonerName; var highestTier = person.Participant.HighestAchievedSeasonTier; var timeLine = person.Participant.Timeline; var matchRef = await Task.Run(() => LeagueofLegends.GetSpecificMatchReferenceAsync(person.ParticipantIdentity.Player.AccountId, match.GameId)); var lane = matchRef.Lane; var role = matchRef.Role; var assists = person.Participant.Stats.Assists; var kills = person.Participant.Stats.Kills; var deaths = person.Participant.Stats.Deaths; var damageDealt = string.Format("{0:n0}", person.Participant.Stats.TotalDamageDealtToChampions); var damageTaken = string.Format("{0:n0}", person.Participant.Stats.TotalDamageTaken); var healed = person.Participant.Stats.TotalHeal; //var champ = await Task.Run(() => LeagueofLegends.GetChampionInfo((int) person.ChampionId)); playerStrings.Add(string.Format("{0,-25} {1,-15} {2,-8} {3,-15} {4,-13} {5,-15} {6,-15} {7}", name, highestTier, lane.ToString(), role.ToString(), assists + "/" + kills + "/" + deaths, damageDealt, damageTaken, Environment.NewLine)); } titles.Add( $"Team {team.Stats.TeamId / 100} Outcome: {(didTeamWin == "Win" ? "Victory" : "Defeat")} Towers Killed: {towerKills} First Blood? {(firstBlood ? "Yes" : "No")}"); } string team1; string team2; if (playerStrings.Count == 10) { team1 = string.Join(string.Empty, playerStrings.GetRange(0, 5)); team2 = string.Join(string.Empty, playerStrings.GetRange(5, 5)); } else if (playerStrings.Count == 6) { team1 = string.Join(string.Empty, playerStrings.GetRange(0, 3)); team2 = string.Join(string.Empty, playerStrings.GetRange(3, 3)); } else { team1 = string.Join(string.Empty, playerStrings.GetRange(0, 5)); team2 = string.Join(string.Empty, playerStrings.GetRange(5, 5)); } var team1Header = titles[0] + Environment.NewLine + Environment.NewLine + header + Environment.NewLine; var team2Header = titles[1] + Environment.NewLine + Environment.NewLine + header + Environment.NewLine; var body = team1Header + team1 + Environment.NewLine + Environment.NewLine + Environment.NewLine + team2Header + team2; try { var fileName = $"{matchEx.Match.GameId.ToString()}"; var imageLocation = ImageService.CreateTextImage(body, fileName); await Context.Channel.SendFileAsync(imageLocation); } catch (Exception) { await ReplyAsync("There was an error generating the image for the data. The error was logged."); } } else { await ReplyAsync("There was an error retrieving recent games. The error has been logged."); } }