refactor: Standardize Mention formatting helpers#379
Conversation
RegisteredApplicationCommandsMention formatting helpers
KubaZ2
left a comment
There was a problem hiding this comment.
I think it also may be a good idea to add for example Mention.Timestamp and Mention.TryFormatTimestamp overloads. I think they can just call the Timestamp.ToString() and Timestamp.TryFormat methods on the passed Timestamp. It would be just for completeness. There may also be some other methods missing. I think it would be nice to provide all of them via the Mention class, similar to the application command methods, in this refactor.
| public static string ApplicationCommand(string fullName, ulong id) | ||
| { | ||
| return string.Create( | ||
| length: 4 + fullName.Length + CountDigits(id), | ||
| state: (Id: id, FullName: fullName), | ||
| action: static (destination, state) => TryFormatApplicationCommand(destination, out _, state.Id, state.FullName) | ||
| ); | ||
| } | ||
|
|
||
| public static string ApplicationCommand(string name, string subCommandName, ulong id) | ||
| { | ||
| return string.Create( | ||
| length: 5 + name.Length + subCommandName.Length + CountDigits(id), | ||
| state: (Id: id, Name: name, SubCommandName: subCommandName), | ||
| action: static (destination, state) => TryFormatApplicationCommand(destination, out _, state.Id, state.Name, state.SubCommandName) | ||
| ); | ||
| } | ||
|
|
||
| public static string ApplicationCommand(string name, string subCommandGroupName, string subCommandName, ulong id) | ||
| { | ||
| return string.Create( | ||
| length: 6 + name.Length + subCommandGroupName.Length + subCommandName.Length + CountDigits(id), | ||
| state: (Id: id, Name: name, SubCommandGroupName: subCommandGroupName, SubCommandName: subCommandName), | ||
| action: static (destination, state) => TryFormatApplicationCommand(destination, out _, state.Id, state.Name, state.SubCommandGroupName, state.SubCommandName) | ||
| ); | ||
| } |
There was a problem hiding this comment.
I am not sure about the API. I think fullName is quite confusing since there is no overload with just name. I think it may be a good idea to leave the fullName (that is a space separated list of names) an implementation detail and just expose a string ApplicationCommand(string name, ulong id) method. And then create an internal method like string ApplicationCommandCore(string fullName, ulong id) that ApplicationCommandOption. uses. Then the string ApplicationCommand(string name, ulong id) could use it as well.
There was a problem hiding this comment.
Done, but Im not sure if this is what you were aiming for. Leaving the conversation open for now, lmk if this is it
|
The documentation preview is available at https://preview.netcord.dev/379. |
No description provided.