mentionOr function Null safety

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

A Function that can be used as an input to CommandsPlugin.prefix to allow invoking commands by mentioning the bot.

The defaultPrefix parameter will be used if the message does not start with a mention.

Implementation

String Function(IMessage) mentionOr(String Function(IMessage) defaultPrefix) {
  return (message) {
    RegExpMatch? match = _mentionPattern.firstMatch(message.content);

    if (match != null && message.client is INyxxWebsocket) {
      if (int.parse(match.group(1)!) == (message.client as INyxxWebsocket).self.id.id) {
        return match.group(0)!;
      }
    }

    return defaultPrefix(message);
  };
}