public async Task Profile(IUser user) { // Begin building the embed (add default parameters). EmbedBuilder embed = new EmbedBuilder(); embed.WithTitle(string.Format("{0}'s profile", user.Username)); embed.WithThumbnailUrl(user.GetAvatarUrl(size: 64)); // Get basic information about the user. // This will return null if the user hasn't been seen before. UserInfo userInfo = await UserUtils.GetUserInfoAsync(user.Username, user.Id, UserInfoQueryFlags.MatchEither); if (userInfo is null) { embed.WithDescription(string.Format("{0} has not submitted any species.", user.Username)); } else { long daysSinceFirstSubmission = (DateUtils.GetCurrentTimestamp() - userInfo.FirstSubmissionTimestamp) / 60 / 60 / 24; UserRank userRank = await UserUtils.GetRankAsync(userInfo, UserInfoQueryFlags.MatchEither); // Get the user's most active genus. Species[] userSpecies = await UserUtils.GetSpeciesAsync(userInfo, UserInfoQueryFlags.MatchEither); IGrouping <string, string> favoriteGenusGrouping = userSpecies .Select(x => x.GenusName) .GroupBy(x => x) .OrderByDescending(x => x.Count()) .FirstOrDefault(); string favoriteGenus = favoriteGenusGrouping is null ? "N/A" : favoriteGenusGrouping.First(); int favoriteGenusCount = favoriteGenusGrouping is null ? 0 : favoriteGenusGrouping.Count(); int userSpeciesCount = userSpecies.Count(); int speciesCount = await SpeciesUtils.GetSpeciesCount(); // Get the user's rarest trophy. string rarest_trophy = "N/A"; Trophies.UnlockedTrophyInfo[] unlocked = await Global.TrophyRegistry.GetUnlockedTrophiesAsync(user.Id); if (unlocked.Count() > 0) { Array.Sort(unlocked, (lhs, rhs) => lhs.timesUnlocked.CompareTo(rhs.timesUnlocked)); Trophies.Trophy trophy = await Global.TrophyRegistry.GetTrophyByIdentifierAsync(unlocked[0].identifier); rarest_trophy = trophy.GetName(); } // Put together the user's profile. if (OurFoodChainBot.Instance.Config.GenerationsEnabled) { int generationsSinceFirstSubmission = (await GenerationUtils.GetGenerationsAsync()).Where(x => x.EndTimestamp > userInfo.FirstSubmissionTimestamp).Count(); double speciesPerGeneration = generationsSinceFirstSubmission <= 0 ? userSpeciesCount : (double)userSpeciesCount / generationsSinceFirstSubmission; embed.WithDescription(string.Format("{0} made their first species during **{1}**.\nSince then, they have submitted **{2:0.0}** species per generation.\n\nTheir submissions make up **{3:0.0}%** of all species.", user.Username, await BotUtils.TimestampToDateStringAsync(userInfo.FirstSubmissionTimestamp), speciesPerGeneration, (double)userSpeciesCount / speciesCount * 100.0)); } else { embed.WithDescription(string.Format("{0} made their first species on **{1}**.\nSince then, they have submitted **{2:0.0}** species per day.\n\nTheir submissions make up **{3:0.0}%** of all species.", user.Username, await BotUtils.TimestampToDateStringAsync(userInfo.FirstSubmissionTimestamp), daysSinceFirstSubmission == 0 ? userSpeciesCount : (double)userSpeciesCount / daysSinceFirstSubmission, (double)userSpeciesCount / speciesCount * 100.0)); } embed.AddField("Species", string.Format("{0} (Rank **#{1}**)", userSpeciesCount, userRank.Rank), inline: true); embed.AddField("Favorite genus", string.Format("{0} ({1} spp.)", StringUtils.ToTitleCase(favoriteGenus), favoriteGenusCount), inline: true); if (OurFoodChainBot.Instance.Config.TrophiesEnabled) { embed.AddField("Trophies", string.Format("{0} ({1:0.0}%)", (await Global.TrophyRegistry.GetUnlockedTrophiesAsync(user.Id)).Count(), await Global.TrophyRegistry.GetUserCompletionRateAsync(user.Id)), inline: true); embed.AddField("Rarest trophy", rarest_trophy, inline: true); } } await ReplyAsync("", false, embed.Build()); }