Index: bot.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bot/Attic/bot.install,v retrieving revision 1.1.2.1.2.1 diff -u -r1.1.2.1.2.1 bot.install --- bot.install 23 Jun 2008 00:52:19 -0000 1.1.2.1.2.1 +++ bot.install 24 Sep 2008 03:27:54 -0000 @@ -2,9 +2,18 @@ // $Id: bot.install,v 1.1.2.1.2.1 2008/06/23 00:52:19 morbus Exp $ /** + * Implementation of hook_install(). + */ +function bot_install() { + drupal_install_schema('bot_queue'); +} + +/** * Implementation of hook_uninstall(). */ function bot_uninstall() { + drupal_uninstall_schema('bot_queue'); + variable_del('bot_auto_retry'); variable_del('bot_auto_reconnect'); variable_del('bot_cache_cleared'); @@ -15,3 +24,52 @@ variable_del('bot_server'); variable_del('bot_server_port'); } + +function bot_queue_schema() { + $schema = array(); + + $schema['bot_queue'] = array( + 'description' => t("Stores the bot's message/action queue."), + 'fields' => array( + 'action_id' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => t("The unique action ID"), + ), + 'receiver' => array( + 'type' => 'varchar', + 'length' => 60, + 'not null' => TRUE, + 'default' => '', + 'description' => t('The receiver of this message or action.'), + ), + 'message' => array( + 'type' => 'text', + 'not null' => TRUE, + 'default' => '', + 'description' => t('The message contents.'), + ), + 'timestamp' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('At what time this message was created.'), + ), + 'action' => array( + 'type' => 'int', + 'size' => 'small', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => t('Set to one to send as an IRC action, set to zero to send as a message.'), + ), + ), + + 'primary key' => array('action_id'), + ); + + return $schema; +} + Index: bot.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bot/bot.module,v retrieving revision 1.9.2.9.2.11 diff -u -r1.9.2.9.2.11 bot.module --- bot.module 27 Jun 2008 00:59:09 -0000 1.9.2.9.2.11 +++ bot.module 24 Sep 2008 03:27:54 -0000 @@ -59,6 +59,27 @@ } /** + * Process the bot's message queue. + */ + +function bot_irc_queue() { + //Get our waiting queue + $res = db_query("SELECT * FROM {bot_queue}"); + + //Send each one in turn + while($row = db_fetch_object($res)) { + if($row->action) { + bot_action($row->receiver, $row->message); + } else { + bot_message($row->receiver, $row->message); + } + } + + //Flush the queue + db_query("DELETE FROM {bot_queue} WHERE 1"); +} + +/** * Framework related messages and features. * * @param $data @@ -93,6 +114,19 @@ } /** + * Enqueue an action to be sent at the next bot cron. + * + * @param $to + * The channel or user to receive the message. + * @param $message + * The message to be sent. + */ +function bot_action_queue($to, $message) { + $SQL = "INSERT INTO {bot_queue} (receiver, message, timestamp, action) VALUES ('%s', '%s', %d, %d)"; + db_query($SQL, $to, $message, time(), 1); +} + +/** * Send an action to a channel or user. * * @param $to @@ -111,6 +145,19 @@ } /** + * Enqueue a message to be sent at the next bot cron. + * + * @param $to + * The channel or user to receive the message. + * @param $message + * The message to be sent. + */ +function bot_message_queue($to, $message) { + $SQL = "INSERT INTO {bot_queue} (receiver, message, timestamp, action) VALUES ('%s', '%s', %d, %d)"; + db_query($SQL, $to, $message, time(), 0); +} + +/** * Send a message to a channel or user. * * @param $to Index: bot_start.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/bot/bot_start.php,v retrieving revision 1.2.2.4.2.3 diff -u -r1.2.2.4.2.3 bot_start.php --- bot_start.php 23 Jun 2008 01:39:28 -0000 1.2.2.4.2.3 +++ bot_start.php 24 Sep 2008 03:27:54 -0000 @@ -73,6 +73,9 @@ // is primarily used in the shipped code to clear cached data. $irc->registerTimehandler(300000, $bot, 'invoke_irc_bot_cron'); +// add a ten-second timer for the web message queue. +$irc->registerTimehandler(10000, $bot, 'invoke_irc_bot_message_queue'); + // connect and begin listening. $irc->connect(variable_get('bot_server', 'irc.freenode.net'), variable_get('bot_server_port', 6667)); $irc->login(variable_get('bot_nickname', 'bot_module'), variable_get('bot_nickname', 'bot_module') . ' :http://drupal.org/project/bot', 8, variable_get('bot_nickname', 'bot_module'), (variable_get('bot_password', '') != '') ? variable_get('bot_password', '') : NULL); @@ -90,6 +93,7 @@ // pass off IRC messages to our modules via Drupal's hook system. class drupal_wrapper { function invoke_irc_bot_cron(&$irc) { module_invoke_all('irc_bot_cron'); } + function invoke_irc_bot_message_queue(&$irc) { bot_irc_queue(); } function invoke_irc_msg_unknown(&$irc, &$data) { module_invoke_all('irc_msg_unknown', $data); } function invoke_irc_msg_channel(&$irc, &$data) { module_invoke_all('irc_msg_channel', $data); } function invoke_irc_msg_query(&$irc, &$data) { module_invoke_all('irc_msg_query', $data); }