public void CommandReceivedHandler(object sender, CommandReceivedEventArgs e)
        {
            if (sender is IChatClient chatClient)
            {
                string userDisplayName = e.ChatUser.DisplayName;

                _usageTracker.PurgeExpiredUserCommandCooldowns(DateTimeOffset.Now);

                var previousUsage = _usageTracker.GetByUserDisplayName(userDisplayName);
                if (previousUsage != null)
                {
                    if (!previousUsage.WasUserWarned)
                    {
                        chatClient.SendMessage($"Whoa {userDisplayName}! Slow down there cowboy!");
                        previousUsage.WasUserWarned = true;
                    }

                    return;
                }

                IBotCommand botCommand = _commandMessages.FirstOrDefault(c => c.ShouldExecute(e.CommandWord));
                if (botCommand != null)
                {
                    AttemptToRunCommand(e, botCommand, chatClient);
                    _usageTracker.RecordUsage(new CommandUsage(userDisplayName, DateTimeOffset.Now, false));
                }
            }
        }
Beispiel #2
0
        private void DoTheThing(CommandReceivedEventArgs e, IChatClient chatClient, IBotCommand botCommand)
        {
            CommandUsage commandUsage       = AttemptToRunCommand(e, botCommand, chatClient);
            var          commandUsageEntity = new CommandUsageEntity(e.CommandWord, botCommand.GetType().FullName,
                                                                     e.ChatUser.UserId, e.ChatUser.DisplayName, chatClient.GetType().Name);

            _repository.Create(commandUsageEntity);
            _usageTracker.RecordUsage(commandUsage);
        }