dmOr function Null safety

String Function(IMessage) dmOr(
  1. String defaultPrefix(
    1. IMessage
    )
)

A wrapper function for prefixes that allows commands to be invoked from messages without a prefix in Direct Messages.

For example:

CommandsPlugin commands = CommandsPlugin(
  prefix: dmOr((_) => '!'),
);

// Add a basic `test` command...

Implementation

String Function(IMessage) dmOr(String Function(IMessage) defaultPrefix) {
  return (message) {
    String found = defaultPrefix(message);

    if (message.guild != null || StringView(message.content).skipString(found)) {
      return found;
    }

    return '';
  };
}