コード例 #1
0
ファイル: Command.cs プロジェクト: Kuromu/Qmmands
        /// <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();
        }
コード例 #2
0
 public CooldownBucket(Cooldown cooldown)
 {
     Cooldown   = cooldown;
     _remaining = Cooldown.Amount;
 }
コード例 #3
0
        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)));
        }
コード例 #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)));
        }