public $would_be_sent = null;
protected function send($command, $args = '') {
- $this->would_be_sent = array($command, $args);
+ $this->would_be_sent = array('command' => $command, 'args' => $args);
}
}
public $transporttype = null;
public $encoding = null;
+ public $regcheck = null;
+
public $transport = 'irc';
+ public $fake_irc;
/**
* Get the internationalized/translated display name of this IM service
*/
public function send_message($screenname, $body) {
$this->fake_irc->doPrivmsg($screenname, $body);
- $this->enqueue_outgoing_raw($this->fake_irc->would_be_sent);
+ $this->enqueue_outgoing_raw(array('type' => 'message', 'data' => $this->fake_irc->would_be_sent));
+ return true;
+ }
+
+ /**
+ * Only sends the confirmation message if the nick is
+ * registered
+ *
+ * @param string $screenname screenname sending to
+ * @param string $code the confirmation code
+ * @param User $user user sending to
+ * @return boolean success value
+ */
+ public function checked_send_confirmation_code($screenname, $code, $user) {
+ $this->fake_irc->doPrivmsg('NickServ', 'INFO '.$screenname);
+ $this->enqueue_outgoing_raw(
+ array(
+ 'type' => 'nickcheck',
+ 'data' => $this->fake_irc->would_be_sent,
+ 'nickdata' =>
+ array(
+ 'screenname' => $screenname,
+ 'code' => $code,
+ 'user' => $user
+ )
+ )
+ );
return true;
}
return true;
}
+ /**
+ * Send a confirmation code to a user
+ *
+ * @param string $screenname screenname sending to
+ * @param string $code the confirmation code
+ * @param User $user user sending to
+ * @return boolean success value
+ */
+ public function send_confirmation_code($screenname, $code, $user, $checked = false) {
+ $body = sprintf(_('User "%s" on %s has said that your %s screenname belongs to them. ' .
+ 'If that\'s true, you can confirm by clicking on this URL: ' .
+ '%s' .
+ ' . (If you cannot click it, copy-and-paste it into the ' .
+ 'address bar of your browser). If that user isn\'t you, ' .
+ 'or if you didn\'t request this confirmation, just ignore this message.'),
+ $user->nickname, common_config('site', 'name'), $this->getDisplayName(), common_local_url('confirmaddress', array('code' => $code)));
+
+ if ($this->regcheck && !$checked) {
+ return $this->checked_send_confirmation_code($screenname, $code, $user);
+ } else {
+ return $this->send_message($screenname, $body);
+ }
+ }
+
/**
* Initialize plugin
*
throw new Exception('must specify a nickname');
}
+ if (!isset($this->port)) {
+ $this->port = 6667;
+ }
+ if (!isset($this->password)) {
+ $this->password = '';
+ }
+ if (!isset($this->transporttype)) {
+ $this->transporttype = 'tcp';
+ }
+ if (!isset($this->encoding)) {
+ $this->encoding = 'UTF-8';
+ }
+ if (!isset($this->nickservpassword)) {
+ $this->nickservpassword = '';
+ }
+ if (!isset($this->channels)) {
+ $this->channels = array();
+ }
+
+ if (!isset($this->regcheck)) {
+ $this->regcheck = true;
+ }
+
$this->fake_irc = new Fake_Irc;
return true;
}
channels: Channels for bot to idle in
transporttype: Set to 'ssl' to enable SSL
encoding: Set to change encoding
+regcheck: Check user's nicknames are registered, enabled by default, set to false to disable
+regregexp: Override existing regexp matching response from NickServ if nick checked is registered.
+ Must contain a capturing group catching the nick
+unregregexp: Override existing regexp matching response from NickServ if nick checked is unregistered
+ Must contain a capturing group catching the nick
* required
return parent::send($command, $args);\r
}\r
\r
+ public function forceQuit() {\r
+ try {\r
+ // Send a QUIT command to the server\r
+ $this->send('QUIT', 'Reconnecting');\r
+ } catch (Phergie_Driver_Exception $e){}\r
+\r
+ // Terminate the socket connection\r
+ fclose($this->socket);\r
+\r
+ // Remove the socket from the internal socket list\r
+ unset($this->sockets[(string) $this->getConnection()->getHostmask()]);\r
+ }\r
+\r
/**\r
* Returns the array of sockets\r
*\r
// Get the identify message\r
$this->identifyMessage = $this->config['nickserv.identify_message'];\r
if (!$this->identifyMessage) {\r
- $this->identifyMessage = 'This nickname is registered.';\r
+ $this->identifyMessage = '/This nickname is registered./';\r
}\r
}\r
\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
+ if (preg_match($this->identifyMessage, $message)) {\r
$password = $this->config['nickserv.password'];\r
if (!empty($password)) {\r
$this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);\r
--- /dev/null
+<?php\r
+/**\r
+ * StatusNet - the distributed open-source microblogging tool\r
+ *\r
+ * This program is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU Affero General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU Affero General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU Affero General Public License\r
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ * Calls the given Statusnet IM architecture enqueuing method to enqueue\r
+ * a new incoming message\r
+ *\r
+ * @category Phergie\r
+ * @package Phergie_Plugin_Statusnet\r
+ * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>\r
+ * @copyright 2010 StatusNet, Inc.\r
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0\r
+ * @link http://status.net/\r
+ */\r
+\r
+class Phergie_Plugin_Statusnet extends Phergie_Plugin_Abstract {\r
+ /**\r
+ * Message callback details\r
+ *\r
+ * @var array\r
+ */\r
+ protected $messageCallback;\r
+\r
+ protected $regCallback;\r
+\r
+ protected $tocheck = array();\r
+\r
+ /**\r
+ * Load callback from config\r
+ */\r
+ public function onLoad() {\r
+ $messageCallback = $this->config['statusnet.messagecallback'];\r
+ if (is_callable($messageCallback)) {\r
+ $this->messageCallback = $messageCallback;\r
+ } else {\r
+ $this->messageCallback = NULL;\r
+ }\r
+\r
+ $regCallback = $this->config['statusnet.regcallback'];\r
+ if (is_callable($regCallback)) {\r
+ $this->regCallback = $regCallback;\r
+ } else {\r
+ $this->regCallback = NULL;\r
+ }\r
+\r
+ $this->unregRegexp = $this->config['statusnet.unregregexp'];\r
+ if (!$this->unregRegexp) {\r
+ $this->unregRegexp = '/\x02(.*?)\x02 (?:isn\'t|is not) registered/i';\r
+ }\r
+\r
+ $this->regRegexp = $this->config['statusnet.regregexp'];\r
+ if (!$this->regRegexp) {\r
+ $this->regRegexp = '/(?:\A|\x02)(\w+?)\x02? (?:\(account|is \w+?\z)/i';\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Passes incoming messages to StatusNet\r
+ *\r
+ * @return void\r
+ */\r
+ public function onPrivmsg() {\r
+ if ($this->messageCallback !== NULL) {\r
+ $event = $this->getEvent();\r
+ $source = $event->getSource();\r
+ $message = trim($event->getText());\r
+\r
+ call_user_func($this->messageCallback, array('sender' => $source, 'message' => $message));\r
+ }\r
+ }\r
+\r
+ public function onNotice() {\r
+ $event = $this->getEvent();\r
+ if ($event->getNick() == 'NickServ') {\r
+ $message = $event->getArgument(1);\r
+ if (preg_match($this->unregRegexp, $message, $groups)) {\r
+ $nick = $groups[1];\r
+ call_user_func($this->regCallback, array('nick' => $nick, 'registered' => false));\r
+ } elseif (preg_match($this->regRegexp, $message, $groups)) {\r
+ $nick = $groups[1];\r
+ call_user_func($this->regCallback, array('nick' => $nick, 'registered' => true));\r
+ }\r
+ }\r
+ }\r
+}\r
+++ /dev/null
-<?php\r
-/**\r
- * StatusNet - the distributed open-source microblogging tool\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Affero General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU Affero General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Affero General Public License\r
- * along with this program. If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- * Calls the given Statusnet IM architecture enqueuing method to enqueue\r
- * a new incoming message\r
- *\r
- * @category Phergie\r
- * @package Phergie_Plugin_StatusnetCallback\r
- * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>\r
- * @copyright 2010 StatusNet, Inc.\r
- * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0\r
- * @link http://status.net/\r
- */\r
-\r
-class Phergie_Plugin_StatusnetCallback extends Phergie_Plugin_Abstract {\r
- /**\r
- * Callback details\r
- *\r
- * @var array\r
- */\r
- protected $callback;\r
-\r
- /**\r
- * Load callback from config\r
- */\r
- public function onLoad() {\r
- $callback = $this->config['statusnetcallback.callback'];\r
- if (is_callable($callback)) {\r
- $this->callback = $callback;\r
- } else {\r
- $this->callback = NULL;\r
- }\r
- }\r
-\r
- /**\r
- * Passes incoming messages to StatusNet\r
- *\r
- * @return void\r
- */\r
- public function onPrivmsg() {\r
- if ($this->callback !== NULL) {\r
- $event = $this->getEvent();\r
- $source = $event->getSource();\r
- $message = trim($event->getText());\r
-\r
- call_user_func($this->callback, array('sender' => $source, 'message' => $message));\r
- }\r
- }\r
-}\r
--- /dev/null
+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\r
+ $this->identifyMessage = $this->config['nickserv.identify_message'];\r
+ if (!$this->identifyMessage) {\r
+- $this->identifyMessage = 'This nickname is registered.';\r
++ $this->identifyMessage = '/This nickname is registered./';\r
+ }\r
+ }\r
+ \r
+@@ -82,7 +82,7 @@ class Phergie_Plugin_NickServ extends Phergie_Plugin_Abstract
+ 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
++ if (preg_match($this->identifyMessage, $message)) {\r
+ $password = $this->config['nickserv.password'];\r
+ if (!empty($password)) {\r
+ $this->doPrivmsg($this->botNick, 'IDENTIFY ' . $password);\r
$this->getProcessor()->handleEvents();\r
}\r
\r
+ /**\r
+ * Close the current connection and reconnect to the server\r
+ *\r
+ * @return void\r
+ */\r
+ public function reconnect() {\r
+ $driver = $this->getDriver();\r
+ $sockets = $driver->getSockets();\r
+\r
+ // Close any existing connections\r
+ try {\r
+ $driver->forceQuit();\r
+ } catch (Phergie_Driver_Exception $e){}\r
+ try {\r
+ $driver->doConnect();\r
+ } catch (Phergie_Driver_Exception $e){\r
+ $driver->forceQuit();\r
+ throw $e;\r
+ }\r
+ }\r
+\r
/**\r
* Get the sockets used by the bot\r
*\r
class IrcManager extends ImManager {
public $conn = null;
+ public $regchecks = array();
+ public $regchecksLookup = array();
/**
* Initialize connection to server.
if (!$this->conn) {
$this->conn = new Phergie_StatusnetBot;
- $port = empty($this->plugin->port) ? 6667 : $this->plugin->port;
- $password = empty($this->plugin->password) ? '' : $this->plugin->password;
- $transport = empty($this->plugin->transporttype) ? 'tcp' : $this->plugin->transporttype;
- $encoding = empty($this->plugin->encoding) ? 'UTF-8' : $this->plugin->encoding;
- $nickservpassword = empty($this->plugin->nickservpassword) ? '' : $this->plugin->nickservpassword;
- $channels = empty($this->plugin->channels) ? array() : $this->plugin->channels;
-
$config = new Phergie_Config;
$config->readArray(
array(
'username' => $this->plugin->username,
'realname' => $this->plugin->realname,
'nick' => $this->plugin->nick,
- 'password' => $password,
- 'transport' => $transport,
- 'encoding' => $encoding
+ 'password' => $this->plugin->password,
+ 'transport' => $this->plugin->transporttype,
+ 'encoding' => $this->plugin->encoding
)
),
'Pong',
'NickServ',
'AutoJoin',
- 'StatusnetCallback',
+ 'Statusnet',
),
'plugins.autoload' => true,
'ui.enabled' => true,
- 'nickserv.password' => $nickservpassword,
- 'autojoin.channels' => $channels,
- 'statusnetcallback.callback' => array($this, 'handle_irc_message')
+ 'nickserv.password' => $this->plugin->nickservpassword,
+ 'autojoin.channels' => $this->plugin->channels,
+ 'statusnet.messagecallback' => array($this, 'handle_irc_message'),
+ 'statusnet.regcallback' => array($this, 'handle_reg_response')
)
);
return true;
}
+ /**
+ * Called via a callback when NickServ responds to
+ * the bots query asking if a nick is registered
+ *
+ * @param array $data Data
+ * @return void
+ */
+ public function handle_reg_response($data) {
+ // Retrieve data
+ $nickdata = $this->regchecks[$data['nick']];
+
+ if ($data['registered']) {
+ // Send message
+ $this->plugin->send_confirmation_code($nickdata['screenname'], $nickdata['code'], $nickdata['user'], true);
+ } else {
+ $this->plugin->send_message($nickdata['screenname'], _m('Your nickname is not registered so IRC connectivity cannot be enabled'));
+
+ $confirm = new Confirm_address();
+
+ $confirm->user_id = $user->id;
+ $confirm->address_type = $this->plugin->transport;
+
+ if ($confirm->find(true)) {
+ $result = $confirm->delete();
+
+ if (!$result) {
+ common_log_db_error($confirm, 'DELETE', __FILE__);
+ // TRANS: Server error thrown on database error canceling IM address confirmation.
+ $this->serverError(_('Couldn\'t delete confirmation.'));
+ return;
+ }
+ }
+ }
+
+ // Unset lookup value
+ unset($this->regchecksLookup[$nickdata['screenname']]);
+
+ // Unset data
+ unset($this->regchecks[$data['nick']]);
+ }
+
/**
* Send a message using the daemon
*
if (!$this->conn) {
return false;
}
- $this->conn->send($data[0], $data[1]);
+ if ($data['type'] != 'message') {
+ // Nick checking
+ $screenname = $data['nickdata']['screenname'];
+ if (isset($this->regchecksLookup[$user->nickname])) {
+
+ }
+ $this->regchecks[$screenname] = $data['nickdata'];
+ $this->regchecksLookup[$user->nickname] = $screenname;
+ }
+
+ try {
+ $this->conn->send($data['data']['command'], $data['data']['args']);
+ } catch (Phergie_Driver_Exception $e) {
+ $this->conn->reconnect();
+ return false;
+ }
return true;
}
}