public Task <List <CakeEmbedBuilder> > FetchAllCommandInfoAsPages(CommandService service, string commandSearchFilter = "") { List <CakeEmbedBuilder> helpBook = new List <CakeEmbedBuilder>(); int pageNumber = 1; foreach (ModuleInfo module in service.Modules) { if (ModuleHasHideAttribute(module) || module.Commands.Count == 0) { continue; } CakeEmbedBuilder newEmbedPage = new CakeEmbedBuilder(); PopulateEmbedWithModuleInfo(module, ref newEmbedPage); PopulateEmbedFieldsWithModuleCommands(module, ref newEmbedPage, commandSearchFilter); if (newEmbedPage.Fields.Any()) { newEmbedPage.WithFooter(pageNumber.ToString()); ++pageNumber; helpBook.Add(newEmbedPage); } } return(Task.FromResult(helpBook)); }
public static CakeEmbedBuilder ReturnUserProfile(OsuJsonUser user, int mode) { var embedProfile = new CakeEmbedBuilder(); embedProfile.WithAuthor(author => { author .WithName($"User stats of { user.username }") .WithUrl($"{ user.url }") .WithIconUrl($"{ user.flag }"); }) .WithThumbnailUrl($"https://a.ppy.sh/{user.user_id}_1512645682.png") .WithFooter($"{ (OsuModeEnum)mode }") .WithDescription( $"**Ranked Score: **{ user.ranked_score }\n" + $"**Total Score: **{ user.total_score }\n" + $"**Rank: **{ user.pp_rank } ({ user.country } : { user.pp_country_rank })\n" + $"**PP: **{ Math.Round(user.pp_raw, 1) }\n" + $"**Accuracy: **{ user.accuracy }%\n" + $"**Play Count: **{ user.playcount }\n" + $"**Level: **{ user.level }\n" + $"**Creation Date: ** { user.join_date.ToShortDateString() }") .AddField("Links", $"[osu!chan]({ user.osuchan }) [osu!Skills]({ user.osuskills }) [osu!track]({ user.osutrack })\n"); return(embedProfile); }
public static CakeEmbedBuilder ReturnSetModeEmbed(int mode) { var embedResult = new CakeEmbedBuilder(EmbedType.Success); embedResult.WithTitle("osu!") .WithDescription($"Successfully set your mode to \n\n**{(OsuModeEnum)mode}**"); switch (mode) { case 0: embedResult.WithThumbnailUrl("http://cakebot.org/resource/osu/osu.png"); break; case 1: embedResult.WithThumbnailUrl("http://cakebot.org/resource/osu/taiko.png"); break; case 2: embedResult.WithThumbnailUrl("http://cakebot.org/resource/osu/ctb.png"); break; case 3: embedResult.WithThumbnailUrl("http://cakebot.org/resource/osu/mania.png"); break; default: throw new CakeException("Unexpected value in SetMode"); } return(embedResult); }
public static CakeEmbedBuilder ReturnUserBest(OsuJsonUser user, string thumbnail, List <Tuple <string, string> > fields, int mode) { var embedTop = new CakeEmbedBuilder(); embedTop.WithAuthor(author => { author .WithName($"Top play(s) of {user.username}") .WithUrl($"{user.url}") .WithIconUrl($"{user.image}"); }) .WithFooter($"{(OsuModeEnum)mode}") .WithThumbnailUrl(thumbnail); //data of fields. foreach (var field in fields) { embedTop.AddField(x => { x.Name = field.Item1; x.Value = field.Item2; }); } return(embedTop); }
private void Init(string message) { _logger.Log(Logging.Type.Error, message); _embedError = new CakeEmbedBuilder(EmbedType.Error); _embedError.AddField("Error", message); }
private void PopulateEmbedWithModuleInfo(ModuleInfo moduleInfo, ref CakeEmbedBuilder cakeEmbedBuilder) { cakeEmbedBuilder.WithTitle(GetModuleName()); cakeEmbedBuilder.WithDescription(GetModuleDescription()); #region Local_Function string GetModuleDescription() { string moduleDescription = moduleInfo.Summary; if (string.IsNullOrWhiteSpace(moduleDescription)) { moduleDescription = moduleInfo.Remarks; } return(moduleDescription); } string GetModuleName() { string moduleName = moduleInfo.Name; // TODO: Possible refactor? if (string.IsNullOrWhiteSpace(moduleName)) { moduleName = moduleInfo.Summary; } if (string.IsNullOrWhiteSpace(moduleName)) { moduleName = moduleInfo.Remarks; } if (string.IsNullOrWhiteSpace(moduleName)) { moduleName = moduleInfo.Group; } if (string.IsNullOrWhiteSpace(moduleName)) { // No 'name', 'group', 'summary' or 'remark' attribute attached to it; moduleName = moduleInfo.GetType().Name; } return(moduleName); } #endregion }
private void PopulateEmbedFieldsWithModuleCommands(ModuleInfo moduleInfo, ref CakeEmbedBuilder cakeEmbedBuilder, string commandSearchFilter = "") { foreach (CommandInfo command in moduleInfo.Commands) { if (!CanAddCommandToEmbedField(command)) { continue; } EmbedFieldBuilder commandField = GetEmbedFieldWithCommandInfo(command); cakeEmbedBuilder.AddField(commandField); } #region Local_Function bool CanAddCommandToEmbedField(CommandInfo command) { if (CommandHasHideAttribute(command)) { return(false); } if (!string.IsNullOrWhiteSpace(commandSearchFilter)) { if (!CommandContainsSearchFilter(command)) { return(false); } } return(true); } bool CommandContainsSearchFilter(CommandInfo command) { if (!string.IsNullOrWhiteSpace(command.Name)) { if (command.Name.Contains(commandSearchFilter)) { return(true); } } if (!string.IsNullOrWhiteSpace(command.Remarks)) { if (command.Remarks.Contains(commandSearchFilter)) { return(true); } } if (!string.IsNullOrWhiteSpace(command.Summary)) { if (command.Summary.Contains(commandSearchFilter)) { return(true); } } return(false); } EmbedFieldBuilder GetEmbedFieldWithCommandInfo(CommandInfo commandInfo) { EmbedFieldBuilder commandField = new EmbedFieldBuilder(); commandField.WithIsInline(true); commandField.WithName(commandInfo.Name); commandField.WithValue(GetCommandDescriptionFromCommandInfo(commandInfo)); return(commandField); } string GetCommandDescriptionFromCommandInfo(CommandInfo commandInfo) { return($"`{commandInfo.Summary}`{ System.Environment.NewLine + commandInfo.Remarks}"); } #endregion }
public static CakeEmbedBuilder ReturnStatusEmbed(IGuild guild) { CakeEmbedBuilder statusEmbedBuilder = new CakeEmbedBuilder(); statusEmbedBuilder.WithAuthor($"{Main.GetClient().CurrentUser.Username}"); statusEmbedBuilder.WithTitle($"Status of {Main.GetClient().CurrentUser.Username}"); statusEmbedBuilder.WithDescription($"Version: ``{Json.CakeJson.GetConfig().Version}``"); statusEmbedBuilder.WithFields(GetStatusFields()); statusEmbedBuilder.WithFooter(GetUptimeAsString()); return(statusEmbedBuilder); #region Local_Function string GetUptimeAsString() { TimeSpan upTimeSpan = DateTime.UtcNow.Subtract(Process.GetCurrentProcess().StartTime.ToUniversalTime()); StringBuilder message = new StringBuilder(string.Empty); int days = upTimeSpan.Days; int months = GetEstimatedMonthFromSubtractingDays(ref days); int years = GetYearsFromSubtractingMonths(ref months); // TODO: Possible refactor? AppendTimeToStringIfPositive(ref message, "Year", years); AppendTimeToStringIfPositive(ref message, "Month", months); AppendTimeToStringIfPositive(ref message, "Day", days); AppendTimeToStringIfPositive(ref message, "Hour", upTimeSpan.Hours); AppendTimeToStringIfPositive(ref message, "Minute", upTimeSpan.Minutes); var upTimeString = message.ToString(); RemoveLastCommaIfExists(ref upTimeString); return(upTimeString); } void RemoveLastCommaIfExists(ref string str) { int lastCommaIndex = str.LastIndexOf(","); if (lastCommaIndex != -1) { str = str.Substring(0, lastCommaIndex); } } void AppendTimeToStringIfPositive(ref StringBuilder str, string timeText, int time) { if (time > 0) { str.Append($"{time} {timeText}{GivePluralIfNeeded(time)}, "); } } string GivePluralIfNeeded(int test) { if (test > 1) { return("s"); } return(string.Empty); } int GetEstimatedMonthFromSubtractingDays(ref int days) { int month = 0; while (days >= 30) { ++month; days -= 30; } return(month); } int GetYearsFromSubtractingMonths(ref int months) { int years = 0; while (months >= 12) { ++years; months -= 12; } return(years); } EmbedFieldBuilder[] GetStatusFields() { List <EmbedFieldBuilder> statusFields = new List <EmbedFieldBuilder>(); statusFields.Add( new EmbedFieldBuilder().WithName("Discord Latency") .WithValue($"{Main.GetClient().Latency}ms") ); statusFields.Add( new EmbedFieldBuilder().WithName("Guild Shards / Total Shards") .WithValue($"{Main.GetClient().GetShardIdFor(guild) + 1} / {Main.GetClient().Shards.Count}") ); return(statusFields.ToArray()); } #endregion }
protected async Task SendEmbedAsync(CakeEmbedBuilder embed, IMessageChannel channel, bool tts = false, RequestOptions options = null) { await channel.SendMessageAsync("", tts, embed.Build(), options).ConfigureAwait(false); }
protected async Task SendEmbedAsync(CakeEmbedBuilder embed, bool tts = false, RequestOptions options = null) { await SendEmbedAsync(embed, Module.Context.Channel, tts, options).ConfigureAwait(false); }