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	10 Feb 2009 09:43:54 -0000
@@ -56,6 +56,69 @@
   // 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', 'GHOST @bot_nickname @bot_password'), $trans);
+        bot_message(variable_get('bot_nickserv', 'NickServ'), $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', 'IDENTIFY @bot_password'), $trans);
+    bot_message(variable_get('bot_nickserv', 'NickServ'), $message);
+  }
 }
 
 /**
@@ -193,6 +256,25 @@
     '#title'         => t('Enable debugging'),
     '#type'          => 'checkbox',
   );
+  $form['bot_nickserv'] = array(
+    '#default_value' => variable_get('bot_nickserv', 'NickServ'),
+    '#description'   => t('Enter the nickname service used on this network'),
+    '#title'         => t('Nickname Service'),
+    '#type'          => 'textfield',
+  );
+	$form['bot_ghost'] = array(
+    '#default_value' => variable_get('bot_ghost', '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. \"GHOST @bot_nickname @bot_password\"'),
+		'#title'         => t('Ghost format'),
+		'#type'          => 'textfield',
+	);
+	$form['bot_identify'] = array(
+    '#default_value' => variable_get('bot_identify', 'IDENTIFY @bot_password'),
+    '#description'   => t('Format to authenticate with the nickname service @bot_password token (ie. \"IDENTIFY @bot_password\"'),
+		'#title'         => t('Identify format'),
+		'#type'          => 'textfield',
+	);
+	
 
   return system_settings_form($form);
 }

