private void UpdateHelpInformation(IMessageHandler handler) { Type type = handler.GetType(); foreach (MethodInfo methodInfo in type.GetMethods(BindingFlags.Instance | BindingFlags.Public)) { object[] helpAttributes = methodInfo.GetCustomAttributes(typeof(HelpAttribute), true); if (!_helpers.ContainsKey(type.Name)) { var helper = new HelpInformation { Plugin = type.Name, Commands = new List <Command>() }; _helpers.Add(type.Name, helper); } foreach (HelpAttribute helpAttribute in helpAttributes) { _helpers[type.Name].Commands.Add(new Command(helpAttribute.Syntax.FormatWith(_configuration.Name, _configuration.Alias), helpAttribute.Description.FormatWith(_configuration.Name, _configuration.Alias), helpAttribute.Example.FormatWith(_configuration.Name, _configuration.Alias))); } } }
public HelpInformationDto(HelpInformation helpInformation) { Name = helpInformation.Names.First(); MethodFullName = helpInformation.MethodFullName; Arguments = helpInformation.ArgumentInfos.Select(x => new ArgumentInfoDto(x)); Descriptions = helpInformation.Descriptions.Select(x => new DescriptionDto(x)); IsDefault = helpInformation.IsDefault; }
public HelpInformationDto(HelpInformation helpInformation) { this.CommandName = helpInformation.CommandName; this.AreaName = helpInformation.AreaName; this.Arguments = helpInformation.ArgumentInformations.Select(x => new ArgumentInfoDto(x)); this.Descriptions = helpInformation.Descriptions.Select(x => new DescriptionDto(x)); this.ServerId = helpInformation.ServerId; this.DefaultLanguage = helpInformation.DefaultLanguage; this.ExampleUsage = helpInformation.ExampleUsage; this.IsDefault = helpInformation.IsDefault; }
public string GetExampleUsage(HelpInformation helpInformation, DiscordServerContext server) { var exampleBuilder = new StringBuilder(); exampleBuilder.Append('-'); exampleBuilder.Append(helpInformation.CommandName.ToLowerInvariant().Replace("command", string.Empty)); var arguments = helpInformation.ArgumentInformations.Where(x => !x.IsOptional).ToList(); if (helpInformation.ArgumentInformations.Any(x => x.IsOptional)) { arguments.Add(helpInformation.ArgumentInformations.First(x => x.IsOptional)); } foreach (var argument in arguments) { exampleBuilder.Append(" -"); exampleBuilder.Append(this.GetExampleArgument(argument, server)); } return(exampleBuilder.ToString()); }
/// <summary> /// /// </summary> /// <param name="showOwner"></param> /// <param name="messageContent"></param> /// <param name="caption"></param> /// <param name="iconVisibility"></param> /// <param name="borderType"></param> /// <param name="buttonCount"></param> /// <param name="buttons"></param> /// <param name="options"></param> /// <param name="helpInfo"></param> /// <param name="defaultButton"></param> /// <param name="icon"></param> /// <param name="buttonTextCollection"></param> /// <param name="checkBoxText"></param> /// <param name="customIcon"></param> private ExtendedKryptonMessageboxOld(IWin32Window showOwner, string messageContent, string caption, KryptonMessageBoxExtendedApplicationIconVisibility iconVisibility, KryptonMessageBoxExtendedBorderType borderType, KryptonMessageBoxExtendedBoxButtonCount buttonCount, KryptonMessageBoxExtendedButtons buttons, KryptonMessageBoxExtendedBoxOptions options, HelpInformation helpInfo, KryptonMessageBoxExtendedDefaultButton defaultButton, KryptonMessageBoxExtendedIcon icon, string[] buttonTextCollection, string checkBoxText, Image customIcon) { this.showOwner = showOwner; this.messageContent = messageContent; this.caption = caption; this.iconVisibility = iconVisibility; this.borderType = borderType; this.buttonCount = buttonCount; this.buttons = buttons; this.options = options; this.helpInfo = helpInfo; this.defaultButton = defaultButton; this.icon = icon; this.buttonTextCollection = buttonTextCollection; this.checkBoxText = checkBoxText; this.customIcon = customIcon; InitializeComponent(); UpdateText(); UpdateCheckBox(); UpdateBorderStyle(); UpdateIconVisibility(); UpdateIconType(); UpdateButtonCount(); UpdateButtons(); UpdateMessageboxDefaultButton(); UpdateHelp(); UpdateTextExtra(); UpdateSizing(showOwner); }
/// <summary> /// Internals the show. /// </summary> /// <param name="owner">The owner.</param> /// <param name="messageContent">Content of the message.</param> /// <param name="caption">The caption.</param> /// <param name="iconVisibility">The icon visibility.</param> /// <param name="borderType">Type of the border.</param> /// <param name="buttonCount">The button count.</param> /// <param name="buttons">The buttons.</param> /// <param name="options">The options.</param> /// <param name="helpInfo">The help information.</param> /// <param name="defaultButton">The default button.</param> /// <param name="icon">The icon.</param> /// <param name="result">The result.</param> /// <param name="buttonTextCollection">The button text collection.</param> /// <param name="customIcon">The custom icon.</param> /// <returns></returns> /// <exception cref="InvalidOperationException">Cannot show modal dialog when non-interactive</exception> /// <exception cref="ArgumentException"> /// Cannot show message box from a service with an owner specified - options /// or /// Cannot show message box from a service with help specified - options /// </exception> private static KryptonMessageBoxExtendedResult InternalShow(IWin32Window owner, string messageContent, string caption, KryptonMessageBoxExtendedApplicationIconVisibility iconVisibility, KryptonMessageBoxExtendedBorderType borderType, KryptonMessageBoxExtendedBoxButtonCount buttonCount, KryptonMessageBoxExtendedButtons buttons, KryptonMessageBoxExtendedBoxOptions options, HelpInformation helpInfo = null, KryptonMessageBoxExtendedDefaultButton defaultButton = KryptonMessageBoxExtendedDefaultButton.BUTTON1, KryptonMessageBoxExtendedIcon icon = KryptonMessageBoxExtendedIcon.NONE, string[] buttonTextCollection = null, string checkBoxText = null, Image customIcon = null) // KryptonMessageBoxExtendedResult result = KryptonMessageBoxExtendedResult.OK, { // Check if trying to show a message box from a non-interactive process, this is not possible if (!SystemInformation.UserInteractive && ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) == 0)) { throw new InvalidOperationException("Cannot show modal dialog when non-interactive"); } // Check if trying to show a message box from a service and the owner has been specified, this is not possible if ((owner != null) && ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) != 0)) { throw new ArgumentException(@"Cannot show message box from a service with an owner specified", nameof(options)); } // Check if trying to show a message box from a service and help information is specified, this is not possible if ((helpInfo != null) && ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) != 0)) { throw new ArgumentException(@"Cannot show message box from a service with help specified", nameof(options)); } // If help information provided or we are not a service/default desktop application then grab an owner for showing the message box IWin32Window showOwner = null; if ((helpInfo != null) || ((options & (KryptonMessageBoxExtendedBoxOptions.SERVICENOTIFICATION | KryptonMessageBoxExtendedBoxOptions.DEFAULTDESKTOPONLY)) == 0)) { // If do not have an owner passed in then get the active window and use that instead showOwner = owner ?? FromHandle(PI.GetActiveWindow()); } using (ExtendedKryptonMessageboxOld ekmb = new ExtendedKryptonMessageboxOld(showOwner, messageContent, caption, iconVisibility, borderType, buttonCount, buttons, options, helpInfo, defaultButton, icon, buttonTextCollection, checkBoxText, customIcon)) { ekmb.StartPosition = showOwner == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent; return(ekmb.ShowDialogExtended(showOwner)); } }
public IEnumerable <KeyValuePair <string, string> > MapHelpForOneCommandToEmbed(HelpInformation helpInformation, DiscordServerContext server) { var helpBuilder = new StringBuilder(); var typeResponse = this._responsesService.GetResponse(server.Id, x => x.Type()); var exampleResponse = this._responsesService.GetResponse(server.Id, x => x.Example()); foreach (var argument in helpInformation.ArgumentInformations) { helpBuilder.AppendLine($"**{argument.Name}**"); helpBuilder.AppendLine($"```{typeResponse.ToLowerInvariant()}: {argument.ExpectedTypeName}"); var exampleValue = argument.ExampleValue ?? this._helpExampleUsageGenerator.GetExampleValue(argument, server); helpBuilder.AppendLine(!string.IsNullOrWhiteSpace(exampleValue) ? $"{exampleResponse.ToLowerInvariant()}: {exampleValue}```" : "```"); } var parametersResponse = this._responsesService.GetResponse(server.Id, x => x.Parameters()); yield return(new KeyValuePair <string, string>($"__{parametersResponse}__", helpBuilder.ToString())); var exampleCommandUsage = helpInformation.ExampleUsage ?? this._helpExampleUsageGenerator.GetExampleUsage(helpInformation, server); yield return(new KeyValuePair <string, string>($"__{exampleResponse}__", exampleCommandUsage)); }
private void ShowHelpInfo(GuiView view) { EditorUtility.DisplayDialog("使用说明", HelpInformation.GetHelpInformation(), "确定"); }