Index: bot.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/bot/bot.module,v
retrieving revision 1.9.2.9.2.5
diff -u -r1.9.2.9.2.5 bot.module
--- bot.module	26 Apr 2008 01:32:30 -0000	1.9.2.9.2.5
+++ bot.module	11 Feb 2009 13:09:07 -0000
@@ -56,6 +56,77 @@
   // recreates the variable cache.
   variable_set('bot_cache_cleared', time());
   $GLOBALS['conf'] = variable_init();
+  // checks current nickname with the one in the settings
+  bot_irc_check_name();
+}
+
+/**
+ * Check if current nickname matches the one in the settings
+ * if not, attempt to change nickname to the correct one
+ * bot_irc_msg_error() will catch a failed attempt to change nickname
+ */
+function bot_irc_check_name() {
+  global $irc;
+  if ($irc->_nick !== variable_get('bot_nickname', 'bot_module')) {
+    $irc->changeNick(variable_get('bot_nickname', 'bot_module'));
+  }
+}
+
+/**
+ * Implementation of hook_irc_msg_error()
+ */
+function bot_irc_msg_error($data) {
+  // error code 1048576 is "nickname in use"
+  switch ($data->type) {
+    case 1048576:
+      // check if a password is set in the settings
+      if (variable_get('bot_password', '') !== '') {
+        // replacing tokens
+        $trans = array(
+          '@bot_password' => variable_get('bot_password', ''),
+          '@bot_nickname' => variable_get('bot_nickname', 'bot_module'),
+        );
+        $message = strtr(variable_get('bot_ghost', '/msg NickServ GHOST @bot_nickname @bot_password'), $trans);
+        $message = explode(' ', $message);
+        array_shift($message);
+        $to = array_shift($message);
+        $message = implode(" ", $message);
+        bot_message($to, $message);
+      }
+    break;
+  }
+}
+
+/**
+ * Implementation of hook_irc_msg_notice()
+ */
+function bot_irc_msg_notice($data) {
+  global $irc;
+  // Must be a better way to do this, right now it just checks if the notice contains the bot's nickname and the word "ghosted"
+  if ((strpos($data->message, variable_get('bot_nickname', 'bot_module')) !== false) && (strpos($data->message, 'ghosted') !== false) && ($irc->_nick !== variable_get('bot_nickname', 'bot_module'))) {
+    $irc->changeNick(variable_get('bot_nickname', 'bot_module'));
+  }
+}
+
+/**
+ * Implementation of hook_irc_msg_nickchange()
+ */
+function bot_irc_msg_nickchange($data) {
+  global $irc;
+  // checks if a password is set and if the current nickname reflects the one in the settings
+  if (variable_get('bot_password', '') !== '' && $irc->_nick === variable_get('bot_nickname', 'bot_module')) {
+    // replacing the tokens
+    $trans = array(
+      '@bot_password' => variable_get('bot_password', ''),
+      '@bot_nickname' => variable_get('bot_nickname', 'bot_module'),
+    );
+    $message = strtr(variable_get('bot_identify', '/msg NickServ IDENTIFY @bot_password'), $trans);
+    $message = explode(' ', $message);
+    array_shift($message);
+    $to = array_shift($message);
+    $message = implode(" ", $message);
+    bot_message($to, $message);
+  }
 }
 
 /**
@@ -186,6 +257,18 @@
     '#title'         => t('Bot channels'),
     '#type'          => 'textarea',
   );
+  $form['bot_ghost'] = array(
+    '#default_value' => variable_get('bot_ghost', '/msg NickServ GHOST @bot_nickname @bot_password'),
+    '#description'   => t('Format to force a connected user to relinquish the bot\'s name, optionally using @bot_nickname and @bot_password token (ie. "/msg NickServ GHOST @bot_nickname @bot_password")<br />Only supports a "/msg" format.'),
+    '#title'         => t('Ghost format'),
+    '#type'          => 'textfield',
+  );
+  $form['bot_identify'] = array(
+    '#default_value' => variable_get('bot_identify', '/msg NickServ IDENTIFY @bot_password'),
+    '#description'   => t('Format to authenticate with the nickname service @bot_password token (ie. "/msg NickServ IDENTIFY @bot_password")<br />Only supports a "/msg" format.'),
+    '#title'         => t('Identify format'),
+    '#type'          => 'textfield',
+  );
   $form['bot_debugging'] = array(
     '#default_value' => variable_get('bot_debugging', 0), // spits out a TON of (useful) stuff.
     '#description'   => t('If checked, send Net_SmartIRC\'s SMARTIRC_DEBUG_ALL to the shell.'),

