From 4601fddad310e5830c6ed9cbf76124a5bfa1bc5e Mon Sep 17 00:00:00 2001 From: Luke Fitzgerald Date: Wed, 7 Jul 2010 08:42:35 -0700 Subject: [PATCH] Ported 1.x.x NickServ plugin to 2.x.x --- .../phergie/Phergie/Plugin/NickServ.php | 143 ++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php new file mode 100644 index 0000000000..c3af4ed42d --- /dev/null +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php @@ -0,0 +1,143 @@ +getPluginHandler()->getPlugin('Command'); + + // Get the name of the NickServ bot, defaults to NickServ + $this->botNick = $this->config['nickserv.botnick']; + if (!$this->botNick) $this->botNick = 'NickServ'; + + // Get the identify message + $this->identifyMessage = $this->config['nickserv.identify_message']; + if (!$this->identifyMessage) $this->identifyMessage = 'This nickname is registered.'; + } + + /** + * Checks for a notice from NickServ and responds accordingly if it is an + * authentication request or a notice that a ghost connection has been + * killed. + * + * @return void + */ + public function onNotice() { + $event = $this->event; + if (strtolower($event->getNick()) == strtolower($this->botNick)) { + $message = $event->getArgument(1); + $nick = $this->connection->getNick(); + if (strpos($message, $this->identifyMessage) !== false) { + $password = $this->config['nickserv.password']; + if (!empty($password)) { + $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password); + } + unset($password); + } elseif (preg_match('/^.*' . $nick . '.* has been killed/', $message)) { + $this->doNick($nick); + } + } + } + + /** + * Checks to see if the original Nick has quit, if so, take the name back + * + * @return void + */ + public function onQuit() { + $eventnick = $this->event->getNick(); + $nick = $this->connection->getNick(); + if ($eventnick == $nick) { + $this->doNick($nick); + } + } + + /** + * Changes the in-memory configuration setting for the bot nick if it is + * successfully changed. + * + * @return void + */ + public function onNick() { + $event = $this->event; + $connection = $this->connection; + if ($event->getNick() == $connection->getNick()) { + $connection->setNick($event->getArgument(0)); + } + } + + /** + * Provides a command to terminate ghost connections. + * + * @return void + */ + public function onDoGhostbust() { + $event = $this->event; + $user = $event->getNick(); + $conn = $this->connection; + $nick = $conn->getNick(); + + if ($nick != $this->config['connections'][$conn->getHost()]['nick']) { + $password = $this->config['nickserv.password']; + if (!empty($password)) { + $this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $nick .'.'); + $this->doPrivmsg( + $this->botNick, + 'GHOST ' . $nick . ' ' . $password, + true + ); + } + unset($password); + } + } + + /** + * Automatically send the GHOST command if the Nickname is in use + * + * @return void + */ + public function onResponse() { + if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) { + $password = $this->config['nickserv.password']; + if (!empty($password)) { + $this->doPrivmsg( + $this->botNick, + 'GHOST ' . $this->connection->getNick() . ' ' . $password, + true + ); + } + unset($password); + } + } + + /** + * The server sent a KILL request, so quit the server + * + * @return void + */ + public function onKill() { + $this->doQuit($this->event->getArgument(1)); + } +} -- 2.39.5