gnu-social/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php

179 lines
5.1 KiB
PHP
Raw Normal View History

2010-07-07 16:42:35 +01:00
<?php
2010-07-18 14:28:15 +01:00
/**
* Phergie
*
* PHP version 5
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.
* It is also available through the world-wide-web at this URL:
* http://phergie.org/license
*
* @category Phergie
* @package Phergie_Plugin_NickServ
* @author Phergie Development Team <team@phergie.org>
* @copyright 2008-2010 Phergie Development Team (http://phergie.org)
* @license http://phergie.org/license New BSD License
* @link http://pear.phergie.org/package/Phergie_Plugin_NickServ
*/
2010-07-07 16:42:35 +01:00
/**
* Intercepts and responds to messages from the NickServ agent requesting that
* the bot authenticate its identify.
*
* The password configuration setting should contain the password registered
* with NickServ for the nick used by the bot.
2010-07-18 14:28:15 +01:00
*
* @category Phergie
* @package Phergie_Plugin_NickServ
* @author Phergie Development Team <team@phergie.org>
* @license http://phergie.org/license New BSD License
* @link http://pear.phergie.org/package/Phergie_Plugin_NickServ
* @uses Phergie_Plugin_Command pear.phergie.org
2010-07-07 16:42:35 +01:00
*/
2010-07-18 14:28:15 +01:00
class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract
{
2010-07-07 16:42:35 +01:00
/**
2010-07-18 14:28:15 +01:00
* Nick of the NickServ bot
2010-07-07 16:42:35 +01:00
*
* @var string
*/
protected $botNick;
/**
* Identify message
*/
protected $identifyMessage;
/**
2010-07-18 14:28:15 +01:00
* Checks for dependencies and required configuration settings.
2010-07-07 16:42:35 +01:00
*
* @return void
*/
2010-07-18 14:28:15 +01:00
public function onLoad()
{
2010-07-07 16:42:35 +01:00
$this->getPluginHandler()->getPlugin('Command');
// Get the name of the NickServ bot, defaults to NickServ
2010-07-26 00:04:12 +01:00
$this->botNick = $this->getConfig('nickserv.botnick', 'NickServ');
2010-07-07 16:42:35 +01:00
// Get the identify message
2010-07-26 00:04:12 +01:00
$this->identifyMessage = $this->getConfig(
'nickserv.identify_message',
'/This nickname is registered./'
);
2010-07-07 16:42:35 +01:00
}
/**
* 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
*/
2010-07-18 14:28:15 +01:00
public function onNotice()
{
2010-07-07 16:42:35 +01:00
$event = $this->event;
if (strtolower($event->getNick()) == strtolower($this->botNick)) {
$message = $event->getArgument(1);
$nick = $this->connection->getNick();
if (preg_match($this->identifyMessage, $message)) {
2010-07-07 16:42:35 +01:00
$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);
}
}
}
/**
2010-07-18 14:28:15 +01:00
* Checks to see if the original nick has quit; if so, take the name back.
2010-07-07 16:42:35 +01:00
*
* @return void
*/
2010-07-18 14:28:15 +01:00
public function onQuit()
{
$eventNick = $this->event->getNick();
2010-07-07 16:42:35 +01:00
$nick = $this->connection->getNick();
2010-07-18 14:28:15 +01:00
if ($eventNick == $nick) {
2010-07-07 16:42:35 +01:00
$this->doNick($nick);
}
}
/**
* Changes the in-memory configuration setting for the bot nick if it is
* successfully changed.
*
* @return void
*/
2010-07-18 14:28:15 +01:00
public function onNick()
{
2010-07-07 16:42:35 +01:00
$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
*/
2010-07-18 14:28:15 +01:00
public function onCommandGhostbust()
{
2010-07-07 16:42:35 +01:00
$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)) {
2010-07-18 14:28:15 +01:00
$this->doPrivmsg(
$this->event->getSource(),
$user . ': Attempting to ghost ' . $nick .'.'
);
2010-07-07 16:42:35 +01:00
$this->doPrivmsg(
$this->botNick,
'GHOST ' . $nick . ' ' . $password,
true
);
}
}
}
/**
2010-07-18 14:28:15 +01:00
* Automatically send the GHOST command if the bot's nick is in use.
2010-07-07 16:42:35 +01:00
*
* @return void
*/
2010-07-18 14:28:15 +01:00
public function onResponse()
{
2010-07-07 16:42:35 +01:00
if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) {
$password = $this->config['nickserv.password'];
if (!empty($password)) {
$this->doPrivmsg(
$this->botNick,
2010-07-18 14:28:15 +01:00
'GHOST ' . $this->connection->getNick() . ' ' . $password
2010-07-07 16:42:35 +01:00
);
}
}
}
/**
2010-07-18 14:28:15 +01:00
* Handle the server sending a KILL request.
2010-07-07 16:42:35 +01:00
*
* @return void
*/
2010-07-18 14:28:15 +01:00
public function onKill()
{
2010-07-07 16:42:35 +01:00
$this->doQuit($this->event->getArgument(1));
}
}