root/trunk/Phergie/Plugin/Nickserv.php @ 66

Revision 66, 2.1 KB (checked in by tobias382, 5 years ago)

* Added missing onKick handler method to the base plugin class
* Reverted Pong plugin to return hostname specified by the server
* Moved alternate nick functionality from the Nickserv plugin into its own plugin, Altnick

Line 
1<?php
2
3/**
4* @see Phergie_Plugin_Abstract_AdminCommand
5*/
6require_once 'Phergie/Plugin/Abstract/Command.php';
7
8/**
9* Intercepts and responds to messages from the NickServ agent requesting that
10* the bot authenticate its identify.
11*
12* The password configuration setting should contain the password registered
13* with NickServ for the nick used by the bot.
14*/
15class Phergie_Plugin_Nickserv extends Phergie_Plugin_Abstract_Command
16{
17    /**
18    * Primary nick for the bot
19    *
20    * @var string
21    */
22    protected $nick;
23
24    /**
25    * Initializes instance variables.
26    *
27    * @return void
28    */
29    public function init()
30    {
31        $this->nick = $this->getIni('nick');
32    }
33
34    /**
35    * Checks for a notice from NickServ and responds accordingly if it is an
36    * authentication request or a notice that a ghost connection has been
37    * killed.
38    *
39    * @return void
40    */
41    public function onNotice()
42    {
43        if ($this->event->getNick() == 'NickServ') {
44            $message = $this->event->getArgument(1);
45            if ($message == 'This nickname is owned by someone else') {
46                $password = $this->getIni('password');
47                if (! empty($password)) {
48                    $this->doPrivmsg('NickServ', 'IDENTIFY ' . $password);
49                }
50            } elseif (preg_match('/^.*' . $this->nick . '.* has been killed/', $message)) {
51                $this->doNick($this->nick);
52            }
53        }
54    }
55
56    /**
57    * Changes the in-memory configuration setting for the bot nick if it is
58    * successfully changed.
59    *
60    * @return void
61    */
62    public function onNick()
63    {
64        if ($this->event->getSource() == $this->getIni('nick')) {
65            $this->setIni('nick', $this->event->getArgument(0));
66        }
67    }
68
69    /**
70    * Provides a command to terminate ghost connections.
71    *
72    * @return void
73    */
74    public function onDoGhostbust()
75    {
76        $password = $this->getIni('password');
77
78        if (!empty ($password) && $this->index != -1) {
79            $this->doPrivmsg(
80                'NickServ',
81                'GHOST ' . $this->nick . ' ' . $password
82            );
83        }
84    }
85}
Note: See TracBrowser for help on using the browser.