Minecord (for Discord)

Minecord (for Discord)

570k Downloads

Support lazy values in string templates

axieum opened this issue ยท 0 comments

commented

Is your feature request related to a problem?

To be able to re-use static string templates with dynamic variables.

final @Nullable Object value = variables.get(name);

We should be able to quickly check whether the variable is an instance of Supplier<T> and invoke the supplier for its value instead.

Describe the solution you'd like.

Adjust,

// todo: Prepare a reusable string template for all uptime commands

...to something like,

// Prepare a reusable string template for all uptime commands
private static final StringTemplate TEMPLATE = new StringTemplate()
        .add("uptime", () -> Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime()));

...and then we can reuse that template in the execution to save instantiating a new template every time!

new EmbedBuilder().setDescription(TEMPLATE.format(getConfig().builtin.uptime.message)).build()

Describe alternatives you've considered.

new StringTemplate()
.add("uptime", Duration.ofMillis(ManagementFactory.getRuntimeMXBean().getUptime()))
.format(getConfig().builtin.uptime.message)

Agreements

  • I have searched for and ensured there isn't already an open issue regarding this.
  • I have ensured the feature I'm requesting isn't already in the latest supported mod version.

Other

No response