hasCommand property

bool get hasCommand

Checks if the current update contains a command.

Returns true if the message text starts with a command entity, false otherwise. The result is cached after the first access for better performance.

Implementation

bool get hasCommand {
  if (!_hasCommandCached) {
    final messageText = text;
    final messageEntities = entities;

    if (messageText == null ||
        messageEntities == null ||
        messageEntities.isEmpty) {
      _cachedHasCommand = false;
    } else {
      final firstEntity = messageEntities.first;
      _cachedHasCommand = firstEntity.type == MessageEntityType.botCommand &&
          firstEntity.offset == 0;
    }
    _hasCommandCached = true;
  }
  return _cachedHasCommand ?? false;
}