# # 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 . ini_set('memory_limit', '256M'); require 'XMPPHP/XMPP.php'; require './lib.php'; require './time.php'; require '../config.php'; /* require '../includes/gettext.php'; require '../includes/streams.php'; if (file_exists(PATH.'locale/'.deflang(DEFAULT_LANG).'/LC_MESSAGES/messages.mo')) { $gettext_tables = new gettext_reader( new CachedFileReader(PATH.'locale/'.deflang(DEFAULT_LANG).'/LC_MESSAGES/messages.mo') ); $gettext_tables->load_tables(); } */ $conn = new XMPPHP_XMPP(JABBER_HOST, JABBER_PORT, JABBER_USER, JABBER_PASSWORD, JABBER_RESOURCE, JABBER_DOMAIN, 3); $conn->autoSubscribe(); try { $conn->connect(); $bot = new JiskoBot; while(!$conn->isDisconnected()) { $payloads = $conn->processUntil(array('message', 'presence', 'session_start'), JABBER_INTERVAL); if($payloads) { foreach($payloads as $event) { $pl = $event[1]; $from = $bot->get_jid($pl['from']); if($event[0] == 'message' or $event[0] == 'presence') { $userinfo = $bot->get_profile($from); if(!$userinfo) { if($event[0] == 'message') { //$conn->message($from, 'Tu GTalk/Jabber no está asociado a ningún usuario.'); } continue; } /* if (file_exists(PATH.'locale/'.deflang($userinfo['language']).'/LC_MESSAGES/messages.mo')) { $gettext_tables = new gettext_reader( new CachedFileReader(PATH.'locale/'.deflang($userinfo['language']).'/LC_MESSAGES/messages.mo') ); $gettext_tables->load_tables(); } */ } switch($event[0]) { case 'message': if(empty($pl['body'])) break; if($pl['type'] == 'error') break; $message = trim($pl['body']); if($message == '!off') { $reply = '» '; $reply .= 'OFF!'; $bot->set_off($from); } elseif($message == '!on') { $reply = '» '; $reply .= 'ON!'; $bot->set_on($from); } elseif(ereg('^\!get', $message)) { $user = trim(ereg_replace('^\!get', '', $message)); $note = $bot->note_of($user); if($note) { $ago = showTimeAgo($note['timestamp']); $reply = $user.' '.$ago.' ('.$note['from'].'): '.stripslashes($note['note']); } else { $reply = '» '; $reply .= 'Who are you?'; } } elseif($message == '!help') { $reply = '!help - this help'; $reply .= "\n"; $reply .= '!on - turn on notifications'; $reply .= "\n"; $reply .= '!off - turn off notifications'; $reply .= "\n"; $reply .= '!whoami - who are you'; $reply .= "\n"; $reply .= '!get - latest note from that user'; } elseif($message == '!whoami') { $reply = '» '; $reply .= 'User: '; $reply .= $userinfo['username']; } else { if (!defined('ENABLE_MBSTRING') || (ENABLE_MBSTRING == false)) { $length = strlen($message); } else { $length = mb_strlen(utf8_decode($message)); } if ($length >= 3 and $length <= 140) { $bot->send_update($userinfo['username'], $userinfo['api'], $message); } else { $reply = '» '; $reply .= 'Between 3 and 140 characters, please!'; } } break; case 'presence': if($pl['type'] == 'unavailable') { $bot->unregister_jid($from); } elseif($pl['type'] == 'available') { $bot->register_jid($from); } // if available or not break; case 'session_start': $conn->getRoster(); $conn->presence(JABBER_RESOURCE); break; } // switch if($reply) { $conn->message($from, $reply); } // if reply unset($from); unset($pl); unset($message); unset($reply); unset($userinfo); } // foreach /* if (file_exists(PATH.'locale/'.deflang(DEFAULT_LANG).'/LC_MESSAGES/messages.mo')) { $gettext_tables = new gettext_reader( new CachedFileReader(PATH.'locale/'.deflang(DEFAULT_LANG).'/LC_MESSAGES/messages.mo') ); $gettext_tables->load_tables(); } */ } else { //if $queue = $bot->get_queue(); foreach ($queue as $note) { $message = $note['username'].' ('.$note['from'].'): '.stripslashes($note['note']); if(!empty($note['attached_file'])) $message .= ' (' . BASE . 'download/' . $note['ID'] . '/' . $note['attached_file'] . ')'; $dests = $bot->get_dests($note['user_id']); foreach ($dests as $user) { if($user['jabber_notifications'] == '0') continue; if($user['both'] == '0' && $note['type'] == 'personal') continue; if(!$bot->allowable($user['jabber'])) continue; if(in_array($note['reply_user'], $user['ignored'])) continue; $conn->message($user['jabber'], $message); } // dests } // queue => note } // end else (close) } // while } catch(XMPPHP_Exception $e) { die($e->getMessage()); }