4 * Intercepts and responds to messages from the NickServ agent requesting that
\r
5 * the bot authenticate its identify.
\r
7 * The password configuration setting should contain the password registered
\r
8 * with NickServ for the nick used by the bot.
\r
10 class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract {
\r
12 * The name of the nickserv bot
\r
21 protected $identifyMessage;
\r
24 * Initializes instance variables.
\r
28 public function onLoad() {
\r
29 $this->getPluginHandler()->getPlugin('Command');
\r
31 // Get the name of the NickServ bot, defaults to NickServ
\r
32 $this->botNick = $this->config['nickserv.botnick'];
\r
33 if (!$this->botNick) $this->botNick = 'NickServ';
\r
35 // Get the identify message
\r
36 $this->identifyMessage = $this->config['nickserv.identify_message'];
\r
37 if (!$this->identifyMessage) $this->identifyMessage = 'This nickname is registered.';
\r
41 * Checks for a notice from NickServ and responds accordingly if it is an
\r
42 * authentication request or a notice that a ghost connection has been
\r
47 public function onNotice() {
\r
48 $event = $this->event;
\r
49 if (strtolower($event->getNick()) == strtolower($this->botNick)) {
\r
50 $message = $event->getArgument(1);
\r
51 $nick = $this->connection->getNick();
\r
52 if (strpos($message, $this->identifyMessage) !== false) {
\r
53 $password = $this->config['nickserv.password'];
\r
54 if (!empty($password)) {
\r
55 $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);
\r
58 } elseif (preg_match('/^.*' . $nick . '.* has been killed/', $message)) {
\r
59 $this->doNick($nick);
\r
65 * Checks to see if the original Nick has quit, if so, take the name back
\r
69 public function onQuit() {
\r
70 $eventnick = $this->event->getNick();
\r
71 $nick = $this->connection->getNick();
\r
72 if ($eventnick == $nick) {
\r
73 $this->doNick($nick);
\r
78 * Changes the in-memory configuration setting for the bot nick if it is
\r
79 * successfully changed.
\r
83 public function onNick() {
\r
84 $event = $this->event;
\r
85 $connection = $this->connection;
\r
86 if ($event->getNick() == $connection->getNick()) {
\r
87 $connection->setNick($event->getArgument(0));
\r
92 * Provides a command to terminate ghost connections.
\r
96 public function onDoGhostbust() {
\r
97 $event = $this->event;
\r
98 $user = $event->getNick();
\r
99 $conn = $this->connection;
\r
100 $nick = $conn->getNick();
\r
102 if ($nick != $this->config['connections'][$conn->getHost()]['nick']) {
\r
103 $password = $this->config['nickserv.password'];
\r
104 if (!empty($password)) {
\r
105 $this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $nick .'.');
\r
108 'GHOST ' . $nick . ' ' . $password,
\r
117 * Automatically send the GHOST command if the Nickname is in use
\r
121 public function onResponse() {
\r
122 if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) {
\r
123 $password = $this->config['nickserv.password'];
\r
124 if (!empty($password)) {
\r
127 'GHOST ' . $this->connection->getNick() . ' ' . $password,
\r
136 * The server sent a KILL request, so quit the server
\r
140 public function onKill() {
\r
141 $this->doQuit($this->event->getArgument(1));
\r