Exemplo n.º 1
0
        /// <summary>
        ///     Resets the <see cref="Cooldown"/> bucket with a key generated from the provided
        ///     <see cref="ICommandContext"/> and <see cref="IServiceProvider"/> on this <see cref="Command"/>.
        /// </summary>
        /// <param name="cooldown"> The <see cref="Cooldown"/> to reset. </param>
        /// <param name="context"> The <see cref="ICommandContext"/> to use for bucket key generation. </param>
        /// <param name="provider"> The <see cref="IServiceProvider"/> to use for bucket key generation. </param>
        public void ResetCooldown(Cooldown cooldown, ICommandContext context, IServiceProvider provider = null)
        {
            if (CooldownMap == null)
            {
                throw new InvalidOperationException("This command doesn't have any assigned cooldowns.");
            }

            if (provider is null)
            {
                provider = EmptyServiceProvider.Instance;
            }

            var bucket = CooldownMap.GetBucket(cooldown, context, provider);

            bucket?.Reset();
        }
Exemplo n.º 2
0
 public CooldownBucket(Cooldown cooldown)
 {
     Cooldown   = cooldown;
     _remaining = Cooldown.Amount;
 }
        public CooldownBucket GetBucket(Cooldown cooldown, CommandContext context, IServiceProvider provider)
        {
            var key = _command.Service.CooldownBucketKeyGenerator(cooldown.BucketType, context, provider);

            return(key is null ? null : Buckets.GetOrAdd(key, new CooldownBucket(cooldown)));
        }
Exemplo n.º 4
0
        public CooldownBucket GetBucket(Cooldown cooldown, CommandContext context)
        {
            var key = _command.Service.CooldownBucketKeyGenerator(cooldown.BucketType, context);

            return(key == null ? null : _buckets.GetOrAdd(key, new CooldownBucket(cooldown)));
        }