Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.29 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Intercepts and responds to messages from the NickServ agent requesting that
  5.  * the bot authenticate its identify.
  6.  *
  7.  * The password configuration setting should contain the password registered
  8.  * with NickServ for the nick used by the bot.
  9.  */
  10. class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract {
  11.     /**
  12.      * The name of the nickserv bot
  13.      *
  14.      * @var string
  15.      */
  16.     protected $botNick;
  17.  
  18.     /**
  19.     * Identify message
  20.     */
  21.     protected $identifyMessage;
  22.  
  23.     /**
  24.      * Initializes instance variables.
  25.      *
  26.      * @return void
  27.      */
  28.     public function onLoad() {
  29.         $this->getPluginHandler()->getPlugin('Command');
  30.  
  31.         // Get the name of the NickServ bot, defaults to NickServ
  32.         $this->botNick = $this->config['nickserv.botnick'];
  33.         if (!$this->botNick) $this->botNick = 'NickServ';
  34.  
  35.         // Get the identify message
  36.         $this->identifyMessage = $this->config['nickserv.identify_message'];
  37.         if (!$this->identifyMessage) $this->identifyMessage = 'This nickname is registered.';
  38.     }
  39.  
  40.     /**
  41.      * Checks for a notice from NickServ and responds accordingly if it is an
  42.      * authentication request or a notice that a ghost connection has been
  43.      * killed.
  44.      *
  45.      * @return void
  46.      */
  47.     public function onNotice() {
  48.         $event = $this->event;
  49.         if (strtolower($event->getNick()) == strtolower($this->botNick)) {
  50.             $message = $event->getArgument(1);
  51.             $nick = $this->connection->getNick();
  52.             if (strpos($message, $this->identifyMessage) !== false) {
  53.                 $password = $this->config['nickserv.password'];
  54.                 if (!empty($password)) {
  55.                     $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);
  56.                 }
  57.                 unset($password);
  58.             } elseif (preg_match('/^.*' . $nick . '.* has been killed/', $message)) {
  59.                 $this->doNick($nick);
  60.             }
  61.         }
  62.     }
  63.  
  64.     /**
  65.      * Checks to see if the original Nick has quit, if so, take the name back
  66.      *
  67.      * @return void
  68.      */
  69.     public function onQuit() {
  70.         $eventnick = $this->event->getNick();
  71.         $nick = $this->connection->getNick();
  72.         if ($eventnick == $nick) {
  73.             $this->doNick($nick);
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Changes the in-memory configuration setting for the bot nick if it is
  79.      * successfully changed.
  80.      *
  81.      * @return void
  82.      */
  83.     public function onNick() {
  84.         $event = $this->event;
  85.         $connection = $this->connection;
  86.         if ($event->getNick() == $connection->getNick()) {
  87.             $connection->setNick($event->getArgument(0));
  88.         }
  89.     }
  90.  
  91.     /**
  92.      * Provides a command to terminate ghost connections.
  93.      *
  94.      * @return void
  95.      */
  96.     public function onDoGhostbust() {
  97.         $event = $this->event;
  98.         $user = $event->getNick();
  99.         $conn = $this->connection;
  100.         $nick = $conn->getNick();
  101.  
  102.         if ($nick == $this->config['connections'][$conn->getHost()]['nick']) {
  103.             $password = $this->config['nickserv.password'];
  104.             if (!empty($password)) {
  105.                 $this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $nick .'.');
  106.                 $this->doPrivmsg(
  107.                     $this->botNick,
  108.                     'GHOST ' . $nick . ' ' . $password,
  109.                     true
  110.                 );
  111.             }
  112.             unset($password);
  113.         }
  114.     }
  115.  
  116.     /**
  117.      * Automatically send the GHOST command if the Nickname is in use
  118.      *
  119.      * @return void
  120.      */
  121.     public function onResponse() {
  122.         if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) {
  123.             $password = $this->config['nickserv.password'];
  124.             if (!empty($password)) {
  125.                 $this->doPrivmsg(
  126.                     $this->botNick,
  127.                     'GHOST ' . $this->connection->getNick() . ' ' . $password,
  128.                     true
  129.                 );
  130.             }
  131.             unset($password);
  132.         }
  133.     }
  134.  
  135.     /**
  136.      * The server sent a KILL request, so quit the server
  137.      *
  138.      * @return void
  139.      */
  140.     public function onKill() {
  141.         $this->doQuit($this->event->getArgument(1));
  142.     }
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement