title: How can I implement an anti-spamming technique on my IRC bot?
body: <p>I run my bot in a public channel with hundreds of users. Yesterday a person came in and just abused it.</p>
  
  <p>I would like to let anyone use the bot, but if they spam commands consecutively  and if they aren't a bot "owner" like me when I debug then I would like to add them to an ignored list which expires in an hour or so.</p>
  
  <p>One way I'm thinking would be to save all commands by all users, in a dictionary such as:</p>
  
  <pre><code>({
    'meder@freenode': [{command:'.weather 20851', timestamp: 209323023 }],
    'jack@efnet': [{command:'.seen john' }]
  })
  </code></pre>
  
  <p>I would setup a cron job to flush this out every 24 hours, but I would basically determine if a person has made X number of commands in a duration of say, 15 seconds and add them to an ignore list.</p>
  
  <p>Actually, as I'm writing this answer I thought of a better idea.. maybe instead of storing each users commands, just store the the bot's commands in a list and keep on pushing until it reaches a limit of say, 15.</p>
  
  <pre><code>lastCommands = [], limit = 5;
  
  function handleCommand( timeObj, action ) {
      if ( lastCommands.length &lt; limit ) {
          action();
      } else {
          // enumerate through lastCommands and compare the timestamps of all 5 commands
          // if the user is the same for all 5 commands, and...
          // if the timestamps are all within the vicinity of 20 seconds
          // add the user to the ignoreList
      }  
  }
  
  
  watch_for('command', function() {
     handleCommand({timestamp: 2093293032, user: user}, function(){ message.say('hello there!') })
  });
  </code></pre>
  
  <p>I would appreciate any advice on the matter.</p>