Index: bot.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/bot/bot.module,v
retrieving revision 1.9.2.9.2.19
diff -u -p -r1.9.2.9.2.19 bot.module
--- bot.module	12 May 2010 17:01:15 -0000	1.9.2.9.2.19
+++ bot.module	22 Sep 2010 05:24:08 -0000
@@ -200,13 +200,7 @@ function bot_irc_msg_unknown($data) {
  *   The action to perform.
  */
 function bot_action($to, $action) {
-  global $irc; // from bot_start.php.
-  $irc->message(SMARTIRC_TYPE_ACTION, $to, $action);
-
-  // allow modules to react to bot responses. do NOT use
-  // bot_action() in your implementation as you'll cause
-  // an infinite loop! and that'd look really really retarded.
-  module_invoke_all('irc_bot_reply_action', $to, $action);
+  bot_message_helper($to, $action, 'action', SMARTIRC_TYPE_ACTION);
 }
 
 /**
@@ -218,14 +212,45 @@ function bot_action($to, $action) {
  *   The message string to send.
  */
 function bot_message($to, $message) {
-  global $irc; // from bot_start.php.
   $type = strpos($to, '#') == 0 ? 'CHANNEL' : 'QUERY';
-  $irc->message(constant('SMARTIRC_TYPE_' . $type), $to, $message);
+  bot_message_helper($to, $message, 'message', constant('SMARTIRC_TYPE_' . $type));
+}
+
+/**
+ * Helper function for bot_message() and bot_action().
+ *
+ * Invokes hooks and interfaces with SmartIRC.
+ *
+ * @param $to String
+ *    The nick of the user or the name of the channel to send the message to.
+ * @param $mssage string
+ *    The message to send.
+ * @param $reply_hook String
+ *    The name of the reply hook, either 'message' or 'action'.
+ * @param $type Constant
+ *    The SmartIRC type.  One of:
+ *      SMARTIRC_TYPE_ACTION
+ *      SMARTIRC_TYPE_CHANNEL
+ *      SMARTIRC_TYPE_QUERY
+ */
+function bot_message_helper($to, $message, $reply_hook, $type) {
+  global $irc; // from bot_start.php.
 
-  // allow modules to react to bot responses. do NOT use
-  // bot_message() in your implementation as you'll cause
+  // allow modules to alter bot responses. do NOT use
+  // bot_action() in your implementation as you'll cause
   // an infinite loop! and that'd look really really retarded.
-  module_invoke_all('irc_bot_reply_message', $to, $message);
+  $hook = "irc_bot_reply_{$reply_hook}_alter";
+  foreach (module_implements($hook) as $module) {
+    $function = "{$module}_$hook";
+    // allow implementations to receive the parameters by reference.
+    $function($to, $message);
+  }
+
+  // send the message over IRC.
+  $irc->message($type, $to, $message);
+
+  // allow modules to react to bot responses.
+  module_invoke_all("irc_bot_reply_{$reply_hook}", $to, $message);
 }
 
 /**
