--- bot.module.orig	2008-03-28 17:30:51.000000000 +0100
+++ bot.module	2008-03-28 16:37:00.000000000 +0100
@@ -60,6 +60,36 @@
   // recreates the variable cache.
   variable_set('bot_cache_cleared', time());
   $GLOBALS['conf'] = variable_init();
+  
+  // sends messages in queue
+  bot_irc_msg_queue();
+  
+  // sends actions in queue
+  bot_irc_action_queue();
+}
+
+/**
+ * Sends messages in queue.
+ */
+function bot_irc_msg_queue() {
+  $res = db_query("SELECT message_id, receiver, message FROM {bot_message_queue}");
+  
+  while($row = db_fetch_object($res)) {
+	  bot_message($row->receiver, $row->message);
+	  db_query("DELETE FROM {bot_message_queue} WHERE message_id = ".$row->message_id." LIMIT 1");
+	}
+}
+
+/**
+ * Sends actions in queue.
+ */
+function bot_irc_action_queue() {
+  $res = db_query("SELECT action_id, receiver, message FROM {bot_action_queue}");
+  
+  while($row = db_fetch_object($res)) {
+	  bot_action($row->receiver, $row->message);
+	  db_query("DELETE FROM {bot_action_queue} WHERE action_id = ".$row->action_id." LIMIT 1");
+	}
 }
 
 /**
@@ -116,6 +148,21 @@
 }
 
 /**
+ * Send an action to a channel or user for use with hook instances.
+ * It stores the message in a database table that gets checked every 5 minutes
+ * in the running IRC instance, which then sends the message.  
+ *
+ * @param $to
+ *   A channel or user.
+ * @param $message
+ *   The message string to send.
+ */
+function bot_action_queue($to, $message) {
+
+	db_query("INSERT INTO {bot_action_queue} (receiver, message, timestamp) VALUES ('%s', '%s', %d)", $to, $message, time());
+}
+
+/**
  * Send a message to a channel or user.
  *
  * @param $to
@@ -135,6 +182,21 @@
 }
 
 /**
+ * Send a message to a channel or user for use with hook instances.
+ * It stores the message in a database table that gets checked every 5 minutes
+ * in the running IRC instance, which then sends the message.  
+ *
+ * @param $to
+ *   A channel or user.
+ * @param $message
+ *   The message string to send.
+ */
+function bot_message_queue($to, $message) {
+
+	db_query("INSERT INTO {bot_message_queue} (receiver, message, timestamp) VALUES ('%s', '%s', %d)", $to, $message, time());
+}
+
+/**
  * Displays a quick page listing all the enabled features of the bot.
  * This is a wrapper around the IRC help features, and spits those helps
  * verbatim (meaning URLs won't be linked, etc.). @todo Someday, urlfilter.