Index: bot_tell/bot_tell.info =================================================================== RCS file: bot_tell/bot_tell.info diff -N bot_tell/bot_tell.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bot_tell/bot_tell.info 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,6 @@ +; $Id$ +name = Bot Tell +package = Bot +dependencies[] = bot +description = "Allows messaging between users." +core = 6.x Index: bot_tell/bot_tell.module =================================================================== RCS file: bot_tell/bot_tell.module diff -N bot_tell/bot_tell.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bot_tell/bot_tell.module 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,123 @@ +nick : $data->channel; + + // Check for tells + if (preg_match("/^($addressed)tell (.*)$/i", $data->message, $matches)) { + list($recipient, $content) = explode(' ', $matches[2], 2); + // See if they're sending a factoid + if (module_exists('bot_factoid') && (substr($content, 0, 5) == 'about') && ($factoid = bot_factoid_load(substr($content, 6)))) { + bot_tell_save($data->nick, $recipient, time(), $factoid['result']); + } + else { + bot_tell_save($data->nick, $recipient, time(), $content); + } + $acknowledge = $from_query ? "!recipient will be sent the message." : "!nick: !recipient will be sent the message."; + bot_message($to, t("!nick: !recipient will be sent the message.", array('!nick' => $data->nick, '!recipient' => $recipient))); + } + + // Check messages + $messages = bot_tell_load($data->nick); + if (!empty($messages)) { + // Display all the messages to the user + foreach ($messages as $message) { + bot_message($data->nick, t("!from said: !contents (!time)", array( + '!to' => $data->nick, + '!from' => $message->author, + '!contents' => $message->contents, + '!time' => format_date($message->sent), + ))); + } + + // Remove the messages + bot_tell_delete($data->nick); + } +} + +/** + * All responses are available via a query. + */ +function bot_tell_irc_msg_query($data) { + bot_tell_irc_msg_channel($data, TRUE); +} + +/** + * Delete factoids for the given user. + * + * @param $recipient + * The recipient of the message. + */ +function bot_tell_delete($recipient) { + return db_query("DELETE FROM {bot_tell} WHERE recipient LIKE '%s'", $recipient); +} + +/** + * Retrieve factoids for the given user. + * + * @return + * An array of all messages for the recipient. + */ +function bot_tell_load($recipient) { + $results = db_query("SELECT * FROM {bot_tell} WHERE recipient = '%s'", $recipient); + + // Construct the messages + $messages = array(); + while ($result = db_fetch_object($results)) { + $messages[] = $result; + } + return $messages; +} + +/** + * Creates a factoid. + * + * We expect a raw string right from the IRC user - we'll handle all the + * checks for prefacing and "no," and "also", etc. Learning factoids + * will only happen if the bot name has been used. + * + * @param $author + * The author of the message. + * @param $recipient + * The recipient of the message. + * @param $sent + * The timestamp of the message. + * @param $contents + * The contents of the message. + * @param $mid + * The message ID, if we are updating a message instead of inserting a new one. + */ +function bot_tell_save($author, $recipient, $sent, $contents, $mid = NULL) { + if ($mid) { + return db_query("UPDATE {bot_tell} SET author = '%s', recipient = '%s', sent = %d, contents = '%s' WHERE mid = %d", $author, $recipient, $sent, $contents, $mid); + } + return db_query("INSERT INTO {bot_tell} SET author = '%s', recipient = '%s', sent = %d, contents = '%s'", $author, $recipient, $sent, $contents); +} Index: bot_tell/bot_tell.install =================================================================== RCS file: bot_tell/bot_tell.install diff -N bot_tell/bot_tell.install --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ bot_tell/bot_tell.install 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,61 @@ + t('The single table necessary for message storage.'), + 'fields' => array( + 'mid' => array( + 'description' => t('Primary Key: The message ID.'), + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + ), + 'author' => array( + 'default' => '', + 'description' => t('The author, or who wrote the message.'), + 'length' => 255, + 'not null' => TRUE, + 'type' => 'varchar', + ), + 'recipient' => array( + 'default' => '', + 'description' => t('The user who is to be delivered the message.'), + 'length' => 255, + 'not null' => TRUE, + 'type' => 'varchar', + ), + 'contents' => array( + 'default' => '', + 'description' => t('The contents, or what to be delivered.'), + 'not null' => TRUE, + 'type' => 'text', + ), + 'sent' => array( + 'type' => 'int', + 'default' => 0, + 'description' => t('Timestamp for when the message was sent.'), + ), + ), + 'primary key' => array('mid'), + ); + + return $schema; +} + +/** + * Implementation of hook_install(). + */ +function bot_tell_install() { + drupal_install_schema('bot_tell'); +} + +/** + * Implementation of hook_uninstall(). + */ +function bot_tell_uninstall() { + drupal_uninstall_schema('bot_tell'); +}