/// <summary> /// Display detailed view of command. /// </summary> /// <param name="command"></param> /// <param name="output"></param> /// <returns></returns> async Task DisplayCommand(YCommand command) { Example[] examples = command.GetAttributes <Example>(true); string joinedParams = ConcatParameters(command); string joinedName = string.Join(' ', command.Structure); string commandSummary = !string.IsNullOrWhiteSpace(command.Summary) ? command.Summary + "\n" : "No description.\n"; string output = "```"; output += $"{command.Name} command:\n"; output += commandSummary; output += $" !{joinedName} {joinedParams}\n"; for (int i = 0; i < command.Parameters.Count; i++) { YParameter parameter = command.Parameters[i]; string parameterSummary = parameter.Summary == null ? "No description." : parameter.Summary; output += $" {i}: {parameter.Name} -- {parameterSummary}\n"; } if (!(examples is null)) { output += "\nExample:"; foreach (Example example in examples) { output += $"\n{example.Value}"; } } await Message?.Channel?.SendMessageAsync(output + "```"); }
/// <summary> /// Converts yCommand parameters into one continious string. /// </summary> /// <param name="command"></param> /// <returns></returns> string ConcatParameters(YCommand command) { string output = ""; for (int i = 0; i < command.Parameters.Count; i++) { YParameter parameter = command.Parameters[i]; string hasParam = parameter.IsParam ? "params " : ""; string shorthandType = TypeToShorthand(parameter.Type.Name).ToLower(); output += $"<{hasParam}{shorthandType} {parameter.Name.ToLower()}> "; } return(output); }