remaining method

Duration remaining(
  1. CommandContext context
)

Return the remaining cooldown time for a given context.

If the context is not on cooldown, Duration.zero is returned.

You might also be interested in:

  • getKey, for getting the ID of the bucket the context was sorted into.

Implementation

Duration remaining(CommandContext context) {
  if (check(context) as bool) {
    return Duration.zero;
  }

  DateTime now = DateTime.now();

  int key = getKey(context);
  if (_currentBucket.containsKey(key)) {
    DateTime end = _currentBucket[key]!.start.add(duration);

    return end.difference(now);
  }

  if (_previousBucket.containsKey(key)) {
    DateTime end = _previousBucket[key]!.start.add(duration);

    return end.difference(now);
  }

  return Duration.zero;
}