9 * This source file is subject to the new BSD license that is bundled
\r
10 * with this package in the file LICENSE.
\r
11 * It is also available through the world-wide-web at this URL:
\r
12 * http://phergie.org/license
\r
15 * @package Phergie_Plugin_NickServ
\r
16 * @author Phergie Development Team <team@phergie.org>
\r
17 * @copyright 2008-2010 Phergie Development Team (http://phergie.org)
\r
18 * @license http://phergie.org/license New BSD License
\r
19 * @link http://pear.phergie.org/package/Phergie_Plugin_NickServ
\r
23 * Intercepts and responds to messages from the NickServ agent requesting that
\r
24 * the bot authenticate its identify.
\r
26 * The password configuration setting should contain the password registered
\r
27 * with NickServ for the nick used by the bot.
\r
30 * @package Phergie_Plugin_NickServ
\r
31 * @author Phergie Development Team <team@phergie.org>
\r
32 * @license http://phergie.org/license New BSD License
\r
33 * @link http://pear.phergie.org/package/Phergie_Plugin_NickServ
\r
34 * @uses Phergie_Plugin_Command pear.phergie.org
\r
36 class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract
\r
39 * Nick of the NickServ bot
\r
48 protected $identifyMessage;
\r
51 * Checks for dependencies and required configuration settings.
\r
55 public function onLoad()
\r
57 $this->getPluginHandler()->getPlugin('Command');
\r
59 // Get the name of the NickServ bot, defaults to NickServ
\r
60 $this->botNick = $this->getConfig('nickserv.botnick', 'NickServ');
\r
62 // Get the identify message
\r
63 $this->identifyMessage = $this->getConfig(
\r
64 'nickserv.identify_message',
\r
65 '/This nickname is registered./'
\r
70 * Checks for a notice from NickServ and responds accordingly if it is an
\r
71 * authentication request or a notice that a ghost connection has been
\r
76 public function onNotice()
\r
78 $event = $this->event;
\r
79 if (strtolower($event->getNick()) == strtolower($this->botNick)) {
\r
80 $message = $event->getArgument(1);
\r
81 $nick = $this->connection->getNick();
\r
82 if (preg_match($this->identifyMessage, $message)) {
\r
83 $password = $this->config['nickserv.password'];
\r
84 if (!empty($password)) {
\r
85 $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);
\r
88 } elseif (preg_match('/^.*' . $nick . '.* has been killed/', $message)) {
\r
89 $this->doNick($nick);
\r
95 * Checks to see if the original nick has quit; if so, take the name back.
\r
99 public function onQuit()
\r
101 $eventNick = $this->event->getNick();
\r
102 $nick = $this->connection->getNick();
\r
103 if ($eventNick == $nick) {
\r
104 $this->doNick($nick);
\r
109 * Changes the in-memory configuration setting for the bot nick if it is
\r
110 * successfully changed.
\r
114 public function onNick()
\r
116 $event = $this->event;
\r
117 $connection = $this->connection;
\r
118 if ($event->getNick() == $connection->getNick()) {
\r
119 $connection->setNick($event->getArgument(0));
\r
124 * Provides a command to terminate ghost connections.
\r
128 public function onCommandGhostbust()
\r
130 $event = $this->event;
\r
131 $user = $event->getNick();
\r
132 $conn = $this->connection;
\r
133 $nick = $conn->getNick();
\r
135 if ($nick != $this->config['connections'][$conn->getHost()]['nick']) {
\r
136 $password = $this->config['nickserv.password'];
\r
137 if (!empty($password)) {
\r
139 $this->event->getSource(),
\r
140 $user . ': Attempting to ghost ' . $nick .'.'
\r
144 'GHOST ' . $nick . ' ' . $password,
\r
152 * Automatically send the GHOST command if the bot's nick is in use.
\r
156 public function onResponse()
\r
158 if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) {
\r
159 $password = $this->config['nickserv.password'];
\r
160 if (!empty($password)) {
\r
163 'GHOST ' . $this->connection->getNick() . ' ' . $password
\r
170 * Handle the server sending a KILL request.
\r
174 public function onKill()
\r
176 $this->doQuit($this->event->getArgument(1));
\r