new auto-reply regexp (thanks @lilyhill!)

darcs-hash:20081204174754-5ed1f-dcce210332c55a544c35d535c3f3008aa8c165d3.gz
This commit is contained in:
Evan Prodromou 2008-12-04 12:47:54 -05:00
parent 5eb729b5d5
commit 0a4905035a
1 changed files with 12 additions and 12 deletions

View File

@ -67,9 +67,9 @@ class XMPPDaemon extends Daemon {
if (!$this->conn) { if (!$this->conn) {
return false; return false;
} }
$this->conn->setReconnectTimeout(600); $this->conn->setReconnectTimeout(600);
jabber_send_presence("Send me a message to post a notice", 'available', jabber_send_presence("Send me a message to post a notice", 'available',
NULL, 'available', 100); NULL, 'available', 100);
return !$this->conn->isDisconnected(); return !$this->conn->isDisconnected();
@ -78,14 +78,14 @@ class XMPPDaemon extends Daemon {
function name() { function name() {
return strtolower('xmppdaemon.'.$this->resource); return strtolower('xmppdaemon.'.$this->resource);
} }
function run() { function run() {
if ($this->connect()) { if ($this->connect()) {
$this->conn->addEventHandler('message', 'handle_message', $this); $this->conn->addEventHandler('message', 'handle_message', $this);
$this->conn->addEventHandler('presence', 'handle_presence', $this); $this->conn->addEventHandler('presence', 'handle_presence', $this);
$this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this);
$this->conn->process(); $this->conn->process();
} }
} }
@ -94,7 +94,7 @@ class XMPPDaemon extends Daemon {
$this->conn->processUntil('session_start'); $this->conn->processUntil('session_start');
$this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100); $this->conn->presence('Send me a message to post a notice', 'available', NULL, 'available', 100);
} }
function get_user($from) { function get_user($from) {
$user = User::staticGet('jabber', jabber_normalize_jid($from)); $user = User::staticGet('jabber', jabber_normalize_jid($from));
return $user; return $user;
@ -139,7 +139,7 @@ class XMPPDaemon extends Daemon {
return; return;
} else if ($this->is_direct($pl['body'])) { } else if ($this->is_direct($pl['body'])) {
preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to); preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to);
$to = preg_replace('/^d([\ ])*/', '', $to[0][0]); $to = preg_replace('/^d([\ ])*/', '', $to[0][0]);
$body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']); $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
$this->add_direct($user, $body, $to, $from); $this->add_direct($user, $body, $to, $from);
@ -151,7 +151,7 @@ class XMPPDaemon extends Daemon {
} }
$this->add_notice($user, $pl); $this->add_notice($user, $pl);
} }
$user->free(); $user->free();
unset($user); unset($user);
} }
@ -159,7 +159,7 @@ class XMPPDaemon extends Daemon {
function is_self($from) { function is_self($from) {
return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from)); return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from));
} }
function get_ofrom($pl) { function get_ofrom($pl) {
$xml = $pl['raw']; $xml = $pl['raw'];
$addresses = $xml->sub('addresses'); $addresses = $xml->sub('addresses');
@ -195,7 +195,7 @@ class XMPPDaemon extends Daemon {
} }
function is_autoreply($txt) { function is_autoreply($txt) {
if (preg_match('/[\[\(]?[Aa]uto-?[Rr]eply[\]\)]/', $txt)) { if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) {
return true; return true;
} else { } else {
return false; return false;
@ -209,7 +209,7 @@ class XMPPDaemon extends Daemon {
return false; return false;
} }
} }
function is_direct($txt) { function is_direct($txt) {
if (strtolower(substr($txt, 0, 2))=='d ') { if (strtolower(substr($txt, 0, 2))=='d ') {
return true; return true;
@ -247,7 +247,7 @@ class XMPPDaemon extends Daemon {
$notice->free(); $notice->free();
unset($notice); unset($notice);
} }
function handle_presence(&$pl) { function handle_presence(&$pl) {
$from = jabber_normalize_jid($pl['from']); $from = jabber_normalize_jid($pl['from']);
switch ($pl['type']) { switch ($pl['type']) {