mirror of
https://git.lewd.wtf/PGR/ascnet
synced 2025-12-13 07:04:34 +01:00
helpful help + forcing people learn regex
This commit is contained in:
@@ -88,8 +88,19 @@ namespace AscNet.GameServer.Commands
|
||||
{
|
||||
Command? cmd = CommandFactory.CreateCommand(command, session, args, false);
|
||||
if (cmd is not null)
|
||||
helpText += $"{command}\n\t└─{cmd.Help}\n";
|
||||
{
|
||||
List<PropertyInfo> argsProperties = cmd.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).Where(x => x.GetCustomAttribute(typeof(ArgumentAttribute)) is not null).ToList();
|
||||
|
||||
helpText += $"{command} {string.Join(" ", argsProperties.Select(x => $"<{x.Name}>"))}\n└─{cmd.Help}\n";
|
||||
foreach (var argProp in argsProperties)
|
||||
{
|
||||
ArgumentAttribute attr = (ArgumentAttribute)argProp.GetCustomAttribute(typeof(ArgumentAttribute))!;
|
||||
helpText += string.Format($"└─{argProp.Name} \"{attr.Pattern}\"{{0}}\n", string.IsNullOrEmpty(attr.Description) ? string.Empty : $", {attr.Description}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw new CommandMessageCallbackException(helpText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,4 +140,10 @@ namespace AscNet.GameServer.Commands
|
||||
return (Command)Activator.CreateInstance(command, new object[] { session, args, validate })!;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandMessageCallbackException : Exception
|
||||
{
|
||||
public CommandMessageCallbackException(string message)
|
||||
: base(message) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +170,10 @@ namespace AscNet.GameServer.Handlers
|
||||
|
||||
cmd?.Execute();
|
||||
}
|
||||
catch (CommandMessageCallbackException ex)
|
||||
{
|
||||
notifyWorldChat.ChatMessages.Add(MakeLuciaMessage(ex.Message));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
notifyWorldChat.ChatMessages.Add(MakeLuciaMessage($"Command {cmdStrings.First().Split('/').Last()} failed to execute!"));
|
||||
|
||||
Reference in New Issue
Block a user