diff options
author | Luke Fitzgerald <lw.fitzgerald@googlemail.com> | 2010-07-23 13:33:41 -0700 |
---|---|---|
committer | Luke Fitzgerald <lw.fitzgerald@googlemail.com> | 2010-07-23 13:33:41 -0700 |
commit | c4640c50d38c6f05cd6c076a5cb17656fb72240e (patch) | |
tree | f951cf5b3d14afdb3bc4d73f15ee4c66e0de746e /plugins/Irc/extlib/phergie | |
parent | f818182a373f10abac49cb476a0f16dbaf051965 (diff) |
Lots more work - Implemented nickname checking
Diffstat (limited to 'plugins/Irc/extlib/phergie')
6 files changed, 156 insertions, 65 deletions
diff --git a/plugins/Irc/extlib/phergie/Phergie/Driver/Statusnet.php b/plugins/Irc/extlib/phergie/Phergie/Driver/Statusnet.php index 48540069c..6a0cbb8d1 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Driver/Statusnet.php +++ b/plugins/Irc/extlib/phergie/Phergie/Driver/Statusnet.php @@ -42,6 +42,19 @@ class Phergie_Driver_Statusnet extends Phergie_Driver_Streams { return parent::send($command, $args);
}
+ public function forceQuit() {
+ try {
+ // Send a QUIT command to the server
+ $this->send('QUIT', 'Reconnecting');
+ } catch (Phergie_Driver_Exception $e){}
+
+ // Terminate the socket connection
+ fclose($this->socket);
+
+ // Remove the socket from the internal socket list
+ unset($this->sockets[(string) $this->getConnection()->getHostmask()]);
+ }
+
/**
* Returns the array of sockets
*
diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php index ff181d94e..f873c753b 100644 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php @@ -65,7 +65,7 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract // Get the identify message
$this->identifyMessage = $this->config['nickserv.identify_message'];
if (!$this->identifyMessage) {
- $this->identifyMessage = 'This nickname is registered.';
+ $this->identifyMessage = '/This nickname is registered./';
}
}
@@ -82,7 +82,7 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract if (strtolower($event->getNick()) == strtolower($this->botNick)) {
$message = $event->getArgument(1);
$nick = $this->connection->getNick();
- if (strpos($message, $this->identifyMessage) !== false) {
+ if (preg_match($this->identifyMessage, $message)) {
$password = $this->config['nickserv.password'];
if (!empty($password)) {
$this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);
diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/Statusnet.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/Statusnet.php new file mode 100644 index 000000000..71b7b06bc --- /dev/null +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/Statusnet.php @@ -0,0 +1,98 @@ +<?php
+/**
+ * StatusNet - the distributed open-source microblogging tool
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Calls the given Statusnet IM architecture enqueuing method to enqueue
+ * a new incoming message
+ *
+ * @category Phergie
+ * @package Phergie_Plugin_Statusnet
+ * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>
+ * @copyright 2010 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
+ * @link http://status.net/
+ */
+
+class Phergie_Plugin_Statusnet extends Phergie_Plugin_Abstract {
+ /**
+ * Message callback details
+ *
+ * @var array
+ */
+ protected $messageCallback;
+
+ protected $regCallback;
+
+ protected $tocheck = array();
+
+ /**
+ * Load callback from config
+ */
+ public function onLoad() {
+ $messageCallback = $this->config['statusnet.messagecallback'];
+ if (is_callable($messageCallback)) {
+ $this->messageCallback = $messageCallback;
+ } else {
+ $this->messageCallback = NULL;
+ }
+
+ $regCallback = $this->config['statusnet.regcallback'];
+ if (is_callable($regCallback)) {
+ $this->regCallback = $regCallback;
+ } else {
+ $this->regCallback = NULL;
+ }
+
+ $this->unregRegexp = $this->config['statusnet.unregregexp'];
+ if (!$this->unregRegexp) {
+ $this->unregRegexp = '/\x02(.*?)\x02 (?:isn\'t|is not) registered/i';
+ }
+
+ $this->regRegexp = $this->config['statusnet.regregexp'];
+ if (!$this->regRegexp) {
+ $this->regRegexp = '/(?:\A|\x02)(\w+?)\x02? (?:\(account|is \w+?\z)/i';
+ }
+ }
+
+ /**
+ * Passes incoming messages to StatusNet
+ *
+ * @return void
+ */
+ public function onPrivmsg() {
+ if ($this->messageCallback !== NULL) {
+ $event = $this->getEvent();
+ $source = $event->getSource();
+ $message = trim($event->getText());
+
+ call_user_func($this->messageCallback, array('sender' => $source, 'message' => $message));
+ }
+ }
+
+ public function onNotice() {
+ $event = $this->getEvent();
+ if ($event->getNick() == 'NickServ') {
+ $message = $event->getArgument(1);
+ if (preg_match($this->unregRegexp, $message, $groups)) {
+ $nick = $groups[1];
+ call_user_func($this->regCallback, array('nick' => $nick, 'registered' => false));
+ } elseif (preg_match($this->regRegexp, $message, $groups)) {
+ $nick = $groups[1];
+ call_user_func($this->regCallback, array('nick' => $nick, 'registered' => true));
+ }
+ }
+ }
+}
diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/StatusnetCallback.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/StatusnetCallback.php deleted file mode 100644 index 545ee343b..000000000 --- a/plugins/Irc/extlib/phergie/Phergie/Plugin/StatusnetCallback.php +++ /dev/null @@ -1,63 +0,0 @@ -<?php
-/**
- * StatusNet - the distributed open-source microblogging tool
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- * Calls the given Statusnet IM architecture enqueuing method to enqueue
- * a new incoming message
- *
- * @category Phergie
- * @package Phergie_Plugin_StatusnetCallback
- * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>
- * @copyright 2010 StatusNet, Inc.
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
- * @link http://status.net/
- */
-
-class Phergie_Plugin_StatusnetCallback extends Phergie_Plugin_Abstract {
- /**
- * Callback details
- *
- * @var array
- */
- protected $callback;
-
- /**
- * Load callback from config
- */
- public function onLoad() {
- $callback = $this->config['statusnetcallback.callback'];
- if (is_callable($callback)) {
- $this->callback = $callback;
- } else {
- $this->callback = NULL;
- }
- }
-
- /**
- * Passes incoming messages to StatusNet
- *
- * @return void
- */
- public function onPrivmsg() {
- if ($this->callback !== NULL) {
- $event = $this->getEvent();
- $source = $event->getSource();
- $message = trim($event->getText());
-
- call_user_func($this->callback, array('sender' => $source, 'message' => $message));
- }
- }
-}
diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/patch.diff b/plugins/Irc/extlib/phergie/Phergie/Plugin/patch.diff new file mode 100644 index 000000000..9cfa3c2b8 --- /dev/null +++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/patch.diff @@ -0,0 +1,22 @@ +diff --git a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php +index ff181d9..f873c75 100644 +--- a/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php ++++ b/plugins/Irc/extlib/phergie/Phergie/Plugin/NickServ.php +@@ -65,7 +65,7 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract + // Get the identify message
+ $this->identifyMessage = $this->config['nickserv.identify_message'];
+ if (!$this->identifyMessage) {
+- $this->identifyMessage = 'This nickname is registered.';
++ $this->identifyMessage = '/This nickname is registered./';
+ }
+ }
+
+@@ -82,7 +82,7 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract + if (strtolower($event->getNick()) == strtolower($this->botNick)) {
+ $message = $event->getArgument(1);
+ $nick = $this->connection->getNick();
+- if (strpos($message, $this->identifyMessage) !== false) {
++ if (preg_match($this->identifyMessage, $message)) {
+ $password = $this->config['nickserv.password'];
+ if (!empty($password)) {
+ $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);
diff --git a/plugins/Irc/extlib/phergie/Phergie/StatusnetBot.php b/plugins/Irc/extlib/phergie/Phergie/StatusnetBot.php index ba41f26db..5fe65444b 100644 --- a/plugins/Irc/extlib/phergie/Phergie/StatusnetBot.php +++ b/plugins/Irc/extlib/phergie/Phergie/StatusnetBot.php @@ -67,6 +67,27 @@ class Phergie_StatusnetBot extends Phergie_Bot { }
/**
+ * Close the current connection and reconnect to the server
+ *
+ * @return void
+ */
+ public function reconnect() {
+ $driver = $this->getDriver();
+ $sockets = $driver->getSockets();
+
+ // Close any existing connections
+ try {
+ $driver->forceQuit();
+ } catch (Phergie_Driver_Exception $e){}
+ try {
+ $driver->doConnect();
+ } catch (Phergie_Driver_Exception $e){
+ $driver->forceQuit();
+ throw $e;
+ }
+ }
+
+ /**
* Get the sockets used by the bot
*
* @return array Array of socket resources
|