| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
class Phergie_Plugin_Nickserv extends Phergie_Plugin_Abstract_Command |
|---|
| 11 |
{ |
|---|
| 12 |
|
|---|
| 13 |
* Flag indicating whether or not the plugin is an admin plugin or not |
|---|
| 14 |
* |
|---|
| 15 |
* @var bool |
|---|
| 16 |
*/ |
|---|
| 17 |
public $needsAdmin = true; |
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
* Determines if the plugin is a passive plugin or not |
|---|
| 21 |
* |
|---|
| 22 |
* @var bool |
|---|
| 23 |
*/ |
|---|
| 24 |
public $passive = true; |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
* Primary nick for the bot |
|---|
| 28 |
* |
|---|
| 29 |
* @var string |
|---|
| 30 |
*/ |
|---|
| 31 |
protected $nick; |
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
* The name of the nickserv bot |
|---|
| 35 |
* |
|---|
| 36 |
* @var string |
|---|
| 37 |
*/ |
|---|
| 38 |
protected $botNick; |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
* Initializes instance variables. |
|---|
| 42 |
* |
|---|
| 43 |
* @return void |
|---|
| 44 |
*/ |
|---|
| 45 |
public function onInit() |
|---|
| 46 |
{ |
|---|
| 47 |
parent::onInit(); |
|---|
| 48 |
|
|---|
| 49 |
$this->nick = $this->getIni('nick'); |
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
$this->botNick = $this->getIni('bot_nick'); |
|---|
| 53 |
if (!$this->botNick) $this->botNick = 'NickServ'; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
* Checks for a notice from NickServ and responds accordingly if it is an |
|---|
| 58 |
* authentication request or a notice that a ghost connection has been |
|---|
| 59 |
* killed. |
|---|
| 60 |
* |
|---|
| 61 |
* @return void |
|---|
| 62 |
*/ |
|---|
| 63 |
public function onNotice() |
|---|
| 64 |
{ |
|---|
| 65 |
if (strtolower($this->event->getNick()) == strtolower($this->botNick)) { |
|---|
| 66 |
$message = $this->event->getArgument(1); |
|---|
| 67 |
if ($message == 'This nickname is owned by someone else') { |
|---|
| 68 |
$password = $this->getPluginIni('password'); |
|---|
| 69 |
if (!empty($password)) { |
|---|
| 70 |
$this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password); |
|---|
| 71 |
} |
|---|
| 72 |
} elseif (preg_match('/^.*' . $this->nick . '.* has been killed/', $message)) { |
|---|
| 73 |
$this->doNick($this->nick); |
|---|
| 74 |
} |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
* Checks to see if the original Nick has quit, if so, take the name back |
|---|
| 80 |
* |
|---|
| 81 |
* @return void |
|---|
| 82 |
*/ |
|---|
| 83 |
public function onQuit() |
|---|
| 84 |
{ |
|---|
| 85 |
$nick = $this->event->getNick(); |
|---|
| 86 |
if ($this->event->getNick() == $this->nick) { |
|---|
| 87 |
$this->doNick($this->nick); |
|---|
| 88 |
} |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
* Changes the in-memory configuration setting for the bot nick if it is |
|---|
| 93 |
* successfully changed. |
|---|
| 94 |
* |
|---|
| 95 |
* @return void |
|---|
| 96 |
*/ |
|---|
| 97 |
public function onNick() |
|---|
| 98 |
{ |
|---|
| 99 |
if ($this->event->getSource() == $this->getIni('nick')) { |
|---|
| 100 |
$this->setIni('nick', $this->event->getArgument(0)); |
|---|
| 101 |
} |
|---|
| 102 |
} |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
* Provides a command to terminate ghost connections. |
|---|
| 106 |
* |
|---|
| 107 |
* @return void |
|---|
| 108 |
*/ |
|---|
| 109 |
public function onDoGhostbust() |
|---|
| 110 |
{ |
|---|
| 111 |
$user = $this->event->getNick(); |
|---|
| 112 |
if ($this->fromAdmin(true)) { |
|---|
| 113 |
if ($this->nick != $this->getIni('nick')) { |
|---|
| 114 |
$password = $this->getPluginIni('password'); |
|---|
| 115 |
if (!empty($password)) { |
|---|
| 116 |
$this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $this->nick .'.'); |
|---|
| 117 |
$this->doPrivmsg( |
|---|
| 118 |
$this->botNick, |
|---|
| 119 |
'GHOST ' . $this->nick . ' ' . $password, |
|---|
| 120 |
true |
|---|
| 121 |
); |
|---|
| 122 |
} |
|---|
| 123 |
} |
|---|
| 124 |
} else { |
|---|
| 125 |
$this->doNotice($user, 'You do not have permission to use Ghostbust.'); |
|---|
| 126 |
} |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
|
|---|
| 130 |
* Automatically send the GHOST command if the Nickname is in use |
|---|
| 131 |
* |
|---|
| 132 |
* @return void |
|---|
| 133 |
*/ |
|---|
| 134 |
public function onResponse() |
|---|
| 135 |
{ |
|---|
| 136 |
if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) { |
|---|
| 137 |
$password = $this->getPluginIni('password'); |
|---|
| 138 |
if (!empty($password)) { |
|---|
| 139 |
$this->doPrivmsg( |
|---|
| 140 |
$this->botNick, |
|---|
| 141 |
'GHOST ' . $this->nick . ' ' . $password, |
|---|
| 142 |
true |
|---|
| 143 |
); |
|---|
| 144 |
} |
|---|
| 145 |
unset($password); |
|---|
| 146 |
} |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
* The server sent a KILL request, so quit the server |
|---|
| 151 |
* |
|---|
| 152 |
* @return void |
|---|
| 153 |
*/ |
|---|
| 154 |
public function onKill() |
|---|
| 155 |
{ |
|---|
| 156 |
$this->doQuit($this->event->getArgument(1)); |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|