BotCommands icon indicating copy to clipboard operation
BotCommands copied to clipboard

Add module for typesafe messages

Open freya022 opened this issue 6 months ago • 0 comments

Please see the readme for details about this feature.

  • [x] Add enum LocaleScope
    • Values:
      • PREFER_USER: Use the user locale if available
      • GUILD: Use the guild locale
  • [x] Add @PreferLocaleScope, warn if both a preferred scope and a required locale parameter exists
    • value: LocaleScope
  • [x] Support first parameter being DiscordLocale/Locale, null = use initial locale
  • [x] Convert camelCase parameters to snake_case
  • [x] Throw if a formattable parameter is nullable or the argument is null at runtime (Use Objects.requireNonNull(T, String) to simplify)
  • [x] (Breaking) Add LocalizableTemplate#arguments: List<FormattableArgument>
  • [ ] ~~Add FormattableArgument#canFormat(Class<?>)~~
    • ~~Return true by default, document that in unknown cases, it should return true and just let it fail at runtime~~
    • ~~Make sure to pass the final type (after conversion)~~

Future work can include:

  • Add FormattableArgumentConverter/ArgumentFormatter, maybe extend on ParameterResolver
    • Examples of built-ins:
      • Do not add Duration unless the user is able to localize those
      • IMentionables where any mentionable entity is transformed into its mention
    • Add @FormatWith to force usage of a specific formatter, for example the default IMentionable formatter could be overridden for Member and instead insert the member's effective name

freya022 avatar Jul 10 '25 16:07 freya022