private static string FormatParam(ParameterInfo parameter) { var sb = new StringBuilder(); if (parameter.IsMultiple) { sb.Append($"`[{parameter.Name}...]`"); } else if (parameter.IsRemainder) { sb.Append($"`<{parameter.Name}...>`"); } else if (parameter.IsOptional) { sb.Append($"`[{parameter.Name}]`"); } else { sb.Append($"`<{parameter.Name}>`"); } if (!string.IsNullOrWhiteSpace(parameter.Summary)) { sb.Append($" ({parameter.Summary})"); } return(sb.ToString()); }
internal static string FormatParam(this CommandParam param) { var sb = new StringBuilder(); string type = param.Type.Name.StartsWith("Socket") ? param.Type.Name.Substring(6) : param.Type.GetTypeInfo().IsInterface ? param.Type.Name.Substring(1) : param.Type.Name; if (param.IsMultiple) { sb.Append($"`[({type}): {param.Name}...]`"); } else if (param.IsRemainder) //&& IsOptional - decided not to check for the combination { sb.Append($"`<({type}): {param.Name}...>`"); } else if (param.IsOptional) { sb.Append($"`[({type}): {param.Name}]`"); } else { sb.Append($"`<({type}): {param.Name}>`"); } if (!String.IsNullOrWhiteSpace(param.Summary)) { sb.Append($" ({param.Summary})"); } return(sb.ToString()); }
string getInfo(Discord.Commands.ParameterInfo param) { string text = " "; text += param.IsOptional ? span("paramo", "[") : span("paramr", "<"); text += span("paramtype", param.Type.Name); text += param.IsOptional ? span("paramname paramo", " " + param.Name) : span("paramname paramr", " " + param.Name); text += param.IsOptional ? span("paramo", "]") : span("paramr", ">"); return(text); }
public static ParameterHelpData FromParameterInfo(ParameterInfo parameter) { (string typeName, bool isNullable) = GetTypeInfo(parameter.Type); string name = parameter.Name; string summary = parameter.Summary; var options = parameter.Type switch { var t when t.IsEnum => FromEnum(t.GetEnumValues()), var t when t.GetAttribute <NamedArgumentTypeAttribute>() != null => FromNamedArgumentInfo(parameter.Type), _ => null }; return(new ParameterHelpData(name, summary, typeName, isNullable || parameter.IsOptional, options)); }
public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, Discord.Commands.ParameterInfo parameter, object value, IServiceProvider services) { PropertyInfo Property = Type.GetProperty(value as string); if (Property == null || Property.GetCustomAttribute <UserEditableAttribute>() == null) { return(Task.FromResult(PreconditionResult.FromError( string.Format("That is an invalid property. Valid properties are: [{0}]", string.Join(',', Type.GetProperties().Where(x => x.GetCustomAttribute <UserEditableAttribute>() != null).Select(x => x.Name)))))); } return(Task.FromResult(PreconditionResult.FromSuccess())); }
private string IsRequiredParameter(Discord.Commands.ParameterInfo pi) { RequiredAttribute get = pi.Preconditions.FirstOrDefault(x => x is RequiredAttribute) as RequiredAttribute; return(get?.Text); }
public static string GetName(this Discord.Commands.ParameterInfo param) => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(param.Name);
public override Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider services) { PreconditionResult result; if (!int.TryParse(value.ToString(), out var intValue)) { result = PreconditionResult.FromError($"Value: \"{value}\" is not a valid integer."); } else if (intValue < _min || intValue > _max) { result = PreconditionResult.FromError($"{value} is not in range [{_min}, {_max}]."); } else { result = PreconditionResult.FromSuccess(); } return(Task.FromResult(result !)); }
public override async Task <PreconditionResult> CheckPermissionsAsync(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider services) { string catName = value.ToString(); var cat = (await context.Guild.GetChannelsAsync().ConfigureAwait(false)) .OfType <SocketCategoryChannel>() .FirstOrDefault(c => c.Name.Equals(catName, StringComparison.OrdinalIgnoreCase)); if (cat == null) { return(PreconditionResult.FromError($"There is no channel category named {catName}")); } if (cat.Channels.Count == 0 && _notEmpty) { return(PreconditionResult.FromError($"Category {cat.Name} has no channels.")); } if (_text && !cat.Channels.Any(c => c is SocketTextChannel)) { return(PreconditionResult.FromError($"Category {cat.Name} has no text channels.")); } if (_voice && !cat.Channels.Any(c => c is SocketVoiceChannel)) { return(PreconditionResult.FromError($"Category {cat.Name} has no voice channels.")); } return(PreconditionResult.FromSuccess()); }