public async Task Roles() { IEnumerable <Common.Roles.IRole> roles = await Db.GetRolesAsync(); Discord.Messaging.IEmbed embed = new Discord.Messaging.Embed { Title = $"All roles ({roles.Count()})" }; foreach (Common.Roles.IRole role in roles) { long count = await Db.GetSpeciesCountAsync(role); embed.AddField($"{role.GetName()} ({count})", role.GetShortDescription()); } await ReplyAsync(embed); }
private async Task TrophyUnlockedAsync(TrophyUnlockedArgs args) { ICommandContext commandContext = args.Context.CommandContext; ICreator creator = args.Context.Creator; ITrophy trophy = args.TrophyInfo.Trophy; if (commandContext != null) { Discord.Messaging.IEmbed embed = new Discord.Messaging.Embed { Title = "🏆 Trophy unlocked!", Description = string.Format("Congratulations {0}! You've earned the **{1}** trophy.", (await commandContext.Guild.GetUserAsync(creator.UserId.Value)).Mention, trophy.Name), Footer = trophy.Description, Color = System.Drawing.Color.FromArgb(255, 204, 77) }; await commandContext.Channel.SendMessageAsync(embed : embed.ToDiscordEmbed()); } }
public async Task Predates([Remainder] string speciesName) { speciesName = StringUtilities.StripOuterQuotes(speciesName); ISpecies species = await GetSpeciesOrReplyAsync(speciesName); if (species.IsValid()) { IEnumerable <IPredationInfo> predatorSpecies = (await Db.GetPredatorsAsync(species)) .Where(info => !info.Species.IsExtinct()) .OrderBy(info => info.Species.GetShortName()); if (predatorSpecies.Count() > 0) { Discord.Messaging.IEmbed embed = new Discord.Messaging.Embed(); List <string> lines = new List <string>(); foreach (IPredationInfo info in predatorSpecies) { string lineText = TaxonFormatter.GetString(info.Species); if (!string.IsNullOrEmpty(info.Notes)) { lineText += string.Format(" ({0})", info.Notes.ToLowerInvariant()); } lines.Add(lineText); } embed.Title = string.Format("Predators of {0} ({1})", TaxonFormatter.GetString(species, false), lines.Count()); embed.Description = string.Join(Environment.NewLine, lines); await ReplyAsync(embed); } else { await ReplyInfoAsync(string.Format("**{0}** has no extant natural predators.", species.GetShortName())); } } }
// Private members private async Task ReplyRolesAsync(ISpecies species) { // Get the role(s) assigned to this species. IEnumerable <Common.Roles.IRole> roles = await Db.GetRolesAsync(species); if (roles.Count() > 0) { // Display the role(s) to the user. StringBuilder lines = new StringBuilder(); foreach (Common.Roles.IRole role in roles) { lines.Append(role.GetName()); if (!string.IsNullOrEmpty(role.Notes)) { lines.Append(string.Format(" ({0})", role.Notes)); } lines.AppendLine(); } Discord.Messaging.IEmbed embed = new Discord.Messaging.Embed { Title = $"{species.GetShortName().ToPossessive()} role(s) ({roles.Count()})", Description = lines.ToString() }; await ReplyAsync(embed); } else { await ReplyInfoAsync($"{species.GetShortName().ToBold()} has not been assigned any roles."); } }
public async Task TrophyList() { int total_trophies = TrophyService.GetTrophies().Count(); int trophies_per_page = 8; int total_pages = (int)Math.Ceiling((float)total_trophies / trophies_per_page); int current_page = 0; int current_page_trophy_count = 0; IPaginatedMessage message = new PaginatedMessage(); Discord.Messaging.IEmbed embed = null; IEnumerable <ITrophy> trophy_list = TrophyService.GetTrophies(); foreach (ITrophy trophy in trophy_list) { if (current_page_trophy_count == 0) { ++current_page; embed = new Discord.Messaging.Embed(); embed.Title = string.Format("All Trophies ({0})", TrophyService.GetTrophies().Count()); embed.Description = string.Format("For more details about a trophy, use `?trophy <name>` (e.g. `{0}trophy \"{1}\"`).", Config.Prefix, trophy_list.First().Name); embed.Footer = string.Format("Page {0} of {1}", current_page, total_pages); embed.Color = new Color(255, 204, 77).ToSystemDrawingColor(); } double completion_rate = await Db.GetTrophyCompletionRateAsync(trophy); string description = (trophy.Flags.HasFlag(TrophyFlags.Hidden) && completion_rate <= 0.0) ? string.Format("_{0}_", TrophyBase.HiddenTrophyDescription) : trophy.Description; // If this was a first-time trophy, show who unlocked it. if (trophy.Flags.HasFlag(TrophyFlags.OneTime) && completion_rate > 0.0) { IEnumerable <IUnlockedTrophyInfo> user_ids = await Db.GetCreatorsWithTrophyAsync(trophy); if (user_ids.Count() > 0 && Context.Guild != null) { IGuildUser user = await Context.Guild.GetUserAsync(user_ids.First().Creator.UserId.Value); if (user != null) { description += string.Format(" (unlocked by {0})", user.Mention); } } } embed.AddField(string.Format("{0} **{1}** ({2:0.#}%)", trophy.Icon, trophy.Name, completion_rate), description); ++current_page_trophy_count; if (current_page_trophy_count >= trophies_per_page) { message.AddPage(embed); current_page_trophy_count = 0; } } // Add the last embed to the message. if (embed != null) { message.AddPage(embed); } await ReplyAsync(message); }