public ILocalisable <string> GetString() { var baseFormat = "**{0}**: {1}"; var entries = new List <LocalisedString> { new LocalisedString(SINGLE_TITLE, ReplyType.Info, Command.Name), (LocalisedString)(Command.Description ?? SINGLE_NODESCRIPTION), new RawString(baseFormat, (LocalisedString)TBLocalisation.GROUP, Group) }; if (!string.IsNullOrWhiteSpace(Aliases)) { entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.ALIASES, Format.Sanitize(Aliases))); } entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.USAGE, Usage)); if (Flags.Count != 0) { entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.FLAGS, Flag)); } if (Notes != null && !string.IsNullOrWhiteSpace(Notes.Key)) { entries.Add(new RawString(baseFormat, (LocalisedString)TBLocalisation.NOTES, Notes)); } if (Usages.Count > 0) { entries.Add(NotesFooter); } return(LocalisedString.JoinEnumerable("\n", entries)); }
public HelpCommandEmbeddable(CommandInfo subject, IEnumerable <CallInfo> permitted, string name, ICommandContext context) { Name = name; Command = subject; Permitted = permitted; Context = context; foreach (var call in Permitted) { Usages.Add(new RawString("`{0}{1} {2} {3} {4}` - {5}", Context.Prefix, Name, call.SubCall, string.Join(" ", call.GetParameters()), call.GetFlags(), (LocalisedString)call.Usage)); } if (Usages.Count == 0) { Usage = (LocalisedString)SINGLE_NOUSAGE; } else { Usage = new DynamicString(tr => string.Join("\n", Usages.Select(u => u.Localise(tr).RegexReplace(" +", " ")))); } Notes = (LocalisedString)Command.Note; NotesFooter = (LocalisedString)SINGLE_USAGE_FOOTER; Aliases = Command.Alias.Length == 0 ? "" : string.Join(", ", Command.Alias.ToList()); Group = (RawString)Command.Group ?? (LocalisedString)SINGLE_NOGROUP; Flags.AddRange(Permitted.SelectMany(c => c.Flags) .GroupBy(f => f.ShortKey) .Select(g => g.First())); Flag = LocalisedString.JoinEnumerable("\n", Flags); }
private Action <ISettingEditorBuilder <TStore[], TAccept[]> > MakeArrayEditor <TStore, TAccept>(Action <ISettingEditorBuilder <TStore, TAccept> > templateEditor = null) => b => { var temp = MakeBuilder <TStore, TAccept>(null, null); templateEditor?.Invoke(temp); b.SetName(temp.Name); b.SetValidator((c, a) => a.Select(v => temp.Validator?.Invoke(c, v)).FirstOrDefault(v => v != null)); b.SetViewer((c, s) => s.Length == 0 ? null : LocalisedString.JoinEnumerable(", ", s.Select(v => temp.Viewer?.Invoke(c, v)))); };
protected async Task ListSettingsAsync(string settingGroup = null) { var builder = new LocalisedEmbedBuilder { Color = new Color(135, 206, 235), //System.Drawing.Color.SkyBlue.ToDiscord(), Timestamp = DateTime.Now, Footer = new LocalisedFooterBuilder().WithRawIconUrl(BotUser.GetAvatarUrl()) .WithText(SettingText.FOOTERTEXT, BotUser.Username) }; if (Settings.Count == 1) { settingGroup = Settings.First().Name; } if (settingGroup == null) { builder.WithTitle(SettingText.TITLE_NOGROUP); var desc = string.Join("\n", Settings.Select(g => g.Name)); if (string.IsNullOrWhiteSpace(desc)) { builder.WithDescription(SettingText.DESCRIPTION_NOSETTINGS); } else { builder.WithRawDescription(desc); } await ReplyAsync(builder); return; } var groups = Settings.Where(g => g.Name.ToLower() == settingGroup.ToLower()).ToList(); if (groups.Count() == 0) { await ReplyAsync(SettingText.INVALIDGROUP, ReplyType.Error, settingGroup); return; } builder.WithTitle(SettingText.TITLE_GROUP, groups.First().Name); foreach (var setting in groups.SelectMany(s => s)) { var value = setting.Display(Context, SettingContext); if (value == null) { builder.AddInlineField(f => f.WithRawName(setting.Name).WithValue(SettingText.NOTSET)); } else { builder.AddInlineField(f => f.WithRawName(setting.Name).WithValue(value)); } } var descriptions = LocalisedString.JoinEnumerable("\n", groups.Where(g => g.Description != null).Select(g => g.Description)); var notes = LocalisedString.JoinEnumerable("\n", groups.Where(g => g.Notes != null).Select(g => g.Notes)); if (groups.Exists(g => g.Description != null)) { builder.WithDescription(descriptions); } if (groups.Exists(g => g.Notes != null)) { builder.AddField(f => f.WithName(TBLocalisation.NOTES).WithValue(notes)); } await ReplyAsync(builder); }