check method
- CommandContext context
override
Validate context
against this check.
If true
is returned from this method, this check is considered to be successful, in which
case the next check on the command is checked. Else, if false
is returned, this check is
considered to have failed, and the command will not be executed.
This check's state should not be changed in check; instead, developers should use preCallHooks and postCallHooks to update the check's state.
Implementation
@override
FutureOr<bool> check(CommandContext context) {
if (DateTime.now().isAfter(_currentStart.add(duration))) {
_previousBucket = _currentBucket;
_currentBucket = {};
_currentStart = DateTime.now();
}
int key = getKey(context);
if (_currentBucket.containsKey(key)) {
return _currentBucket[key]!.count < tokensPer;
}
if (_previousBucket.containsKey(key)) {
return !_isActive(_previousBucket[key]!) || _previousBucket[key]!.count < tokensPer;
}
return true;
}