dmOr function Null safety

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

A Function that can be used as an input to CommandsPlugin.prefix to allow users to optionally omit the prefix if the command is ran in a DM with the bot.

The defaultPrefix parameter will be used if the message was sent in a guild or if the message starts with the prefix returned anyways.


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 '';