public Cooldown GetActiveCooldown(ChatUser chatUser, IBotCommand botCommand) { if (chatUser.IsInThisRoleOrHigher(UserRole.Mod) || botCommand.IsActiveGame()) { return(new NoCooldown()); } try { PurgeExpiredUserCommandCooldowns(DateTimeOffset.UtcNow); } catch (Exception e) { _loggerAdapter.LogError(e, "Failed to Purge Expried User Command Cooldowns"); } List <CommandUsage> global = GetUsagesByUserSubjectToCooldown(chatUser.DisplayName, DateTimeOffset.UtcNow); if (global != null && global.Any()) { if (!global.Any(x => x.WasUserWarned)) { global.ForEach(x => x.WasUserWarned = true); } return(new UserCooldown { Message = $"Whoa {chatUser.DisplayName}! Slow down there cowboy!" }); } List <CommandUsage> commandCooldown = GetByCommand(botCommand); if (commandCooldown != null && commandCooldown.Any()) { string timeRemaining = botCommand.GetCooldownTimeRemaining().ToExpandingString(); return(new CommandCooldown { Message = $"\"{botCommand.PrimaryCommandText}\" is currently on cooldown - Remaining time: {timeRemaining}" }); } // TODO: Check for UserCommandCooldown needed. return(new NoCooldown()); }