3 * StatusNet - the distributed open-source microblogging tool
\r
5 * This program is free software: you can redistribute it and/or modify
\r
6 * it under the terms of the GNU Affero General Public License as published by
\r
7 * the Free Software Foundation, either version 3 of the License, or
\r
8 * (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU Affero General Public License for more details.
\r
15 * You should have received a copy of the GNU Affero General Public License
\r
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
18 * Calls the given Statusnet IM architecture enqueuing method to enqueue
\r
19 * a new incoming message
\r
22 * @package Phergie_Plugin_Statusnet
\r
23 * @author Luke Fitzgerald <lw.fitzgerald@googlemail.com>
\r
24 * @copyright 2010 StatusNet, Inc.
\r
25 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
\r
26 * @link http://status.net/
\r
29 class Phergie_Plugin_Statusnet extends Phergie_Plugin_Abstract {
\r
31 * Message callback details
\r
35 protected $messageCallback;
\r
38 * Registration check callback details
\r
42 protected $regCallback;
\r
45 * Load callback from config
\r
47 public function onLoad() {
\r
48 $messageCallback = $this->config['statusnet.messagecallback'];
\r
49 if (is_callable($messageCallback)) {
\r
50 $this->messageCallback = $messageCallback;
\r
52 $this->messageCallback = NULL;
\r
55 $regCallback = $this->config['statusnet.regcallback'];
\r
56 if (is_callable($regCallback)) {
\r
57 $this->regCallback = $regCallback;
\r
59 $this->regCallback = NULL;
\r
62 $this->unregRegexp = $this->config['statusnet.unregregexp'];
\r
63 if (!$this->unregRegexp) {
\r
64 $this->unregRegexp = '/\x02(.*?)\x02 (?:isn\'t|is not) registered/i';
\r
67 $this->regRegexp = $this->config['statusnet.regregexp'];
\r
68 if (!$this->regRegexp) {
\r
69 $this->regRegexp = '/(?:\A|\x02)(\w+?)\x02? (?:\(account|is \w+?\z)/i';
\r
74 * Passes incoming messages to StatusNet
\r
78 public function onPrivmsg() {
\r
79 if ($this->messageCallback !== NULL) {
\r
80 $event = $this->getEvent();
\r
81 $source = $event->getSource();
\r
82 $message = trim($event->getText());
\r
84 call_user_func($this->messageCallback, array('sender' => $source, 'message' => $message));
\r
89 * Catches the response from NickServ
\r
93 public function onNotice() {
\r
94 $event = $this->getEvent();
\r
95 if ($event->getNick() == 'NickServ') {
\r
96 $message = $event->getArgument(1);
\r
97 if (preg_match($this->unregRegexp, $message, $groups)) {
\r
99 call_user_func($this->regCallback, array('nick' => $nick, 'registered' => false));
\r
100 } elseif (preg_match($this->regRegexp, $message, $groups)) {
\r
101 $nick = $groups[1];
\r
102 call_user_func($this->regCallback, array('nick' => $nick, 'registered' => true));
\r