title: Is my logic for a .tell ( notification ) function on my IRC bot sound?
body: <p>I have a bot in node.js and I'm wondering what logic I should use for a <code>.tell</code> function. The purpose of the function will be to give a message to users who are offline. So, if <code>john</code> was offline on freenode.net/#foo and I typed <code>.tell john your mother was great last night</code>, I want the bot to store this message and display it whenever <code>john</code> joins the channel.</p>
  
  <p>If <code>john</code> is already in the channel, I want the bot to immediately just display the message. </p>
  
  <p>I am already using <code>mongodb</code> as a database to store information, so I can probably store all my messages in there. Here's the logic I had in mind so far:</p>
  
  <p><strong>1.</strong> After user A types <code>.tell john your mother was great</code>, a listener will pickup the pattern <code>/\.tell ([\w-]+) (.*)/</code> and store a variable for the message ( <code>var msg</code>, the user who posted the message ( <code>var from</code> ), and the name of the user to be messaged ( <code>var to</code> ). I will also have a global variable signifying the channel name and network of the server.</p>
  
  <p><strong>2.</strong> I'll store a row in mongodb such as:</p>
  
  <pre><code>to   from   message                 network       channel        delivered   time
  --------------------------------------------------------------------------------
  john meder  your mother was great   freenode.net  #foobar        0           (TS)
              last night
  </code></pre>
  
  <p><strong>3.</strong> Setup a listener for <em>anyone</em> joining a channel since the bot can live in multiple channels under <em>one</em> network, and detect if there any messages that are not delivered and if there are, attempt to match the <code>to</code> and <code>network</code> and <code>channel</code> to the stored messages, and if row(s) are found, display them.</p>
  
  <p>This sounds ok, but can anyone review it and maybe offer advice? I'll be forced to have a listener listen for anyone entering any channel, right? There's no alternative to that?</p>