]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Ported 1.x.x NickServ plugin to 2.x.x
authorLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Wed, 7 Jul 2010 15:42:35 +0000 (08:42 -0700)
committerLuke Fitzgerald <lw.fitzgerald@googlemail.com>
Wed, 7 Jul 2010 15:42:35 +0000 (08:42 -0700)
plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php [new file with mode: 0644]

diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php
new file mode 100644 (file)
index 0000000..c3af4ed
--- /dev/null
@@ -0,0 +1,143 @@
+<?php\r
+\r
+/**\r
+ * Intercepts and responds to messages from the NickServ agent requesting that\r
+ * the bot authenticate its identify.\r
+ *\r
+ * The password configuration setting should contain the password registered\r
+ * with NickServ for the nick used by the bot.\r
+ */\r
+class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract {\r
+    /**\r
+     * The name of the nickserv bot\r
+     *\r
+     * @var string\r
+     */\r
+    protected $botNick;\r
+\r
+    /**\r
+    * Identify message\r
+    */\r
+    protected $identifyMessage;\r
+\r
+    /**\r
+     * Initializes instance variables.\r
+     *\r
+     * @return void\r
+     */\r
+    public function onLoad() {\r
+        $this->getPluginHandler()->getPlugin('Command');\r
+\r
+        // Get the name of the NickServ bot, defaults to NickServ\r
+        $this->botNick = $this->config['nickserv.botnick'];\r
+        if (!$this->botNick) $this->botNick = 'NickServ';\r
+\r
+        // Get the identify message\r
+        $this->identifyMessage = $this->config['nickserv.identify_message'];\r
+        if (!$this->identifyMessage) $this->identifyMessage = 'This nickname is registered.';\r
+    }\r
+\r
+    /**\r
+     * Checks for a notice from NickServ and responds accordingly if it is an\r
+     * authentication request or a notice that a ghost connection has been\r
+     * killed.\r
+     *\r
+     * @return void\r
+     */\r
+    public function onNotice() {\r
+        $event = $this->event;\r
+        if (strtolower($event->getNick()) == strtolower($this->botNick)) {\r
+            $message = $event->getArgument(1);\r
+            $nick = $this->connection->getNick();\r
+            if (strpos($message, $this->identifyMessage) !== false) {\r
+                $password = $this->config['nickserv.password'];\r
+                if (!empty($password)) {\r
+                    $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);\r
+                }\r
+                unset($password);\r
+            } elseif (preg_match('/^.*' . $nick . '.* has been killed/', $message)) {\r
+                $this->doNick($nick);\r
+            }\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Checks to see if the original Nick has quit, if so, take the name back\r
+     *\r
+     * @return void\r
+     */\r
+    public function onQuit() {\r
+        $eventnick = $this->event->getNick();\r
+        $nick = $this->connection->getNick();\r
+        if ($eventnick == $nick) {\r
+            $this->doNick($nick);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Changes the in-memory configuration setting for the bot nick if it is\r
+     * successfully changed.\r
+     *\r
+     * @return void\r
+     */\r
+    public function onNick() {\r
+        $event = $this->event;\r
+        $connection = $this->connection;\r
+        if ($event->getNick() == $connection->getNick()) {\r
+            $connection->setNick($event->getArgument(0));\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Provides a command to terminate ghost connections.\r
+     *\r
+     * @return void\r
+     */\r
+    public function onDoGhostbust() {\r
+        $event = $this->event;\r
+        $user = $event->getNick();\r
+        $conn = $this->connection;\r
+        $nick = $conn->getNick();\r
+\r
+        if ($nick != $this->config['connections'][$conn->getHost()]['nick']) {\r
+            $password = $this->config['nickserv.password'];\r
+            if (!empty($password)) {\r
+                $this->doPrivmsg($this->event->getSource(), $user . ': Attempting to ghost ' . $nick .'.');\r
+                $this->doPrivmsg(\r
+                    $this->botNick,\r
+                    'GHOST ' . $nick . ' ' . $password,\r
+                    true\r
+                );\r
+            }\r
+            unset($password);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * Automatically send the GHOST command if the Nickname is in use\r
+     *\r
+     * @return void\r
+     */\r
+    public function onResponse() {\r
+        if ($this->event->getCode() == Phergie_Event_Response::ERR_NICKNAMEINUSE) {\r
+            $password = $this->config['nickserv.password'];\r
+            if (!empty($password)) {\r
+                $this->doPrivmsg(\r
+                    $this->botNick,\r
+                    'GHOST ' . $this->connection->getNick() . ' ' . $password,\r
+                    true\r
+                );\r
+            }\r
+            unset($password);\r
+        }\r
+    }\r
+\r
+    /**\r
+     * The server sent a KILL request, so quit the server\r
+     *\r
+     * @return void\r
+     */\r
+    public function onKill() {\r
+        $this->doQuit($this->event->getArgument(1));\r
+    }\r
+}\r