├── Skype.php ├── Skype ├── Bot.php ├── Bot │ ├── Plugin.php │ └── Plugin │ │ └── Log.php ├── Call.php ├── Chat.php ├── Chatmessage.php ├── Exception.php ├── Filetransfer.php ├── Group.php ├── Object.php ├── Profile.php └── User.php └── example └── skype_bot.php /Skype.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | require_once 'Skype/Exception.php'; 18 | require_once 'Skype/Object.php'; 19 | require_once 'Skype/Call.php'; 20 | require_once 'Skype/Chat.php'; 21 | require_once 'Skype/Chatmessage.php'; 22 | require_once 'Skype/Filetransfer.php'; 23 | require_once 'Skype/Group.php'; 24 | require_once 'Skype/User.php'; 25 | require_once 'Skype/Profile.php'; 26 | 27 | class Skype { 28 | const dbus_destination = "com.Skype.API"; 29 | const dbus_path_invoke = "/com/Skype"; 30 | const dbus_path_notify = "/com/Skype/Client"; 31 | const dbus_interface = "com.Skype.API"; 32 | 33 | // TODO: support enum, datetime, etc... 34 | const property_type_string = "string"; 35 | const property_type_int = "int"; 36 | const property_type_bool = "bool"; 37 | 38 | const default_protocol = 7; 39 | const default_timeout = 60; 40 | 41 | protected $dbus_connection = null; 42 | protected $timeout = self::default_timeout; 43 | protected $debug; 44 | 45 | protected $callback = array( 46 | 'call' => array(), 47 | 'chat' => array(), 48 | 'chatmessage' => array(), 49 | 'chats' => array(), 50 | 'connstatus' => array(), 51 | 'contacts' => array(), 52 | 'currentuserhandle' => array(), 53 | 'filetransfer' => array(), 54 | 'group' => array(), 55 | 'user' => array(), 56 | 'userstatus' => array(), 57 | 'profile' => array(), 58 | ); 59 | 60 | protected $id; 61 | protected $protocol; 62 | protected $connection_status = null; 63 | protected $current_user_handle = null; 64 | protected $user_status = null; 65 | 66 | protected $call_list = array(); 67 | protected $chat_list = array(); 68 | protected $chatmessage_cache = array(); 69 | protected $chatmessage_cache_size = 16; 70 | protected $contact_focus = null; 71 | protected $filetransfer_cache = array(); 72 | protected $filetransfer_cache_size = 16; 73 | protected $group_list = array(); 74 | protected $user_list = array(); 75 | protected $profile = null; 76 | 77 | public function __construct($id, $protocol = self::default_protocol, $debug = false) { 78 | $this->id = $id; 79 | $this->protocol = intval($protocol); 80 | $this->debug = $debug; 81 | } 82 | 83 | public function connect() { 84 | $this->dbus_connection = dbus_bus_get(DBUS_BUS_SESSION); 85 | if (!$this->dbus_connection) { 86 | throw new Exception("dbus_bus_get() failed"); 87 | } 88 | 89 | $this->dbus_connection->registerObjectPath(self::dbus_path_notify, array($this, 'callback')); 90 | 91 | list($r, $s) = $this->invoke("NAME " . $this->id, -1); 92 | if ($r == "CONNSTATUS") { 93 | $this->handleConnstatus($s); 94 | return true; 95 | } 96 | 97 | $this->invokeProtocol(self::default_protocol); 98 | 99 | return true; 100 | } 101 | 102 | public function invoke($s) { 103 | $m = new DBusMessage(DBUS_MESSAGE_TYPE_METHOD_CALL); 104 | $m->setDestination(self::dbus_destination); 105 | $m->setPath(self::dbus_path_invoke); 106 | $m->setInterface(self::dbus_interface); 107 | $m->setMember("Invoke"); 108 | $m->setAutoStart(true); 109 | $m->appendArgs($s); 110 | 111 | $this->_debug("invoke: %s\n", $s); 112 | $r = $this->dbus_connection->sendWithReplyAndBlock($m, $this->timeout); 113 | if (!$r) { 114 | throw new Exception("dbus_connection_send_with_reply_and_block() failed"); 115 | } 116 | $tmp = $r->getArgs(); 117 | $this->_debug("reply: %s\n", $tmp[0]); 118 | if ($tmp[0] == "" || $tmp[0] == "OK") { 119 | return array($tmp[0], null); 120 | } 121 | 122 | list($r, $s) = explode(" ", $tmp[0], 2); 123 | if ($r == "ERROR") { 124 | throw new Skype_Exception(null, intval($s)); 125 | } 126 | 127 | return array($r, $s); 128 | } 129 | 130 | public function poll($timeout = self::default_timeout) { 131 | // $this->_debug("poll: timeout=%d\n", $timeout); 132 | return $this->dbus_connection->poll($timeout); 133 | } 134 | 135 | public function callback($m) { 136 | $tmp = $m->getArgs(); 137 | $this->_debug("notify: %s\n", $tmp[0]); 138 | list($r, $s) = explode(" ", $tmp[0], 2); 139 | if ($r == "ERROR") { 140 | throw new Skype_Exception(null, intval($s)); 141 | } 142 | 143 | $method = sprintf("handle%s", ucfirst(strtolower($r))); 144 | if (method_exists($this, $method)) { 145 | $this->$method($s); 146 | } else { 147 | throw new Exception(sprintf("handler not found [%s]", $method)); 148 | } 149 | } 150 | 151 | public function addCallback($type, $callback) { 152 | if (isset($this->callback[$type]) == false) { 153 | throw new Exception(sprintf("unsupported callback type [%s]", $type)); 154 | } 155 | if (is_callable($callback, true) == false) { 156 | throw new Exception(sprintf("[%s] is not callable", var_export($callback, true))); 157 | } 158 | 159 | $this->callback[$type][] = $callback; 160 | 161 | return true; 162 | } 163 | 164 | public function parseProperty($type, $value) { 165 | // util 166 | if ($type == self::property_type_int) { 167 | return intval($value); 168 | } else if ($type == self::property_type_string) { 169 | return $value; 170 | } else if ($type == self::property_type_bool) { 171 | return $value == "TRUE" ? true : false; 172 | } else if (is_array($type)) { 173 | if ($type[0] == self::property_type_int) { 174 | return preg_split('/,\s+/', $value); 175 | } else if ($type[0] == self::property_type_string) { 176 | return preg_split('/,\s+/', $value); 177 | } 178 | } 179 | 180 | throw new Exception(sprintf("unsupported propety type [%s] [%s]", var_export($type, true), var_export($value, true))); 181 | } 182 | 183 | /* {{{ Skype API (client -> Skype) */ 184 | public function invokeCall($target) { 185 | list($r, $s) = $this->invoke("CALL $target"); 186 | list($call_id, $key, $value) = preg_split('/\s+/', $s, 3); 187 | 188 | $this->call_list[$call_id] = new Skype_Call($this, $call_id); 189 | 190 | return $call_id; 191 | } 192 | 193 | public function invokeCallStatusFinish($call_id) { 194 | list($r, $s) = $this->invoke("SET CALL $call_id STATUS FINISHED"); 195 | 196 | return true; 197 | } 198 | 199 | public function invokeChatmessage($chat_id, $message) { 200 | list($r, $s) = $this->invoke("CHATMESSAGE $chat_id $message"); 201 | $this->handleChatmessage($s); 202 | 203 | $tmp = explode(" ", $s, 3); 204 | return $tmp[0]; // chatmessage_id 205 | } 206 | 207 | public function invokeAlterChatSettopic($chat_id, $topic) { 208 | list($r, $s) = $this->invoke("ALTER CHAT $chat_id SETTOPIC $topic"); 209 | 210 | return true; 211 | } 212 | 213 | public function invokeProtocol($protocol) { 214 | list($r, $s) = $this->invoke("PROTOCOL $protocol"); 215 | if ($s < $protocol) { 216 | $this->_debug("requested protocol [$protocol] is not supported -> falling back to $s"); 217 | } 218 | 219 | $this->protocol = $s; 220 | 221 | return $s; 222 | } 223 | 224 | public function invokeSearchChats() { 225 | // SEARCH CHATS does not return any response (we can get results via NOTIFY method) ...why? 226 | $this->invoke("SEARCH CHATS"); 227 | } 228 | 229 | public function invokeSearchFriends() { 230 | list($r, $s) = $this->invoke("SEARCH FRIENDS"); 231 | return $this->parseProperty(array(self::property_type_string), $s); 232 | } 233 | 234 | public function invokeSearchGroups($type) { 235 | list($r, $s) = $this->invoke("SEARCH GROUPS $type"); 236 | return $this->parseProperty(array(self::property_type_int), $s); 237 | } 238 | /* }}} */ 239 | 240 | /* {{{ Skype API (Skype -> Client) */ 241 | public function handleCall($s) { 242 | list($call_id, $property, $value) = explode(" ", $s, 3); 243 | 244 | if (isset($this->call_list[$call_id]) == false) { 245 | $this->call_list[$call_id] = new Skype_Call($this, $call_id); 246 | } 247 | $call = $this->call_list[$call_id]; 248 | 249 | $call->set($property, $value); 250 | 251 | $this->_requestCallback($this->callback['call'], $call, $call_id, $property, $value); 252 | } 253 | 254 | public function handleChat($s) { 255 | list($chat_id, $property, $value) = explode(" ", $s, 3); 256 | 257 | if (isset($this->chat_list[$chat_id]) == false) { 258 | $this->chat_list[$chat_id] = new Skype_Chat($this, $chat_id); 259 | } 260 | $chat = $this->chat_list[$chat_id]; 261 | 262 | $chat->set($property, $value); 263 | 264 | $this->_requestCallback($this->callback['chat'], $chat, $chat_id, $property, $value); 265 | } 266 | 267 | public function handleChats($s) { 268 | $chat_id_list = $this->parseProperty(array(self::property_type_string), $s); 269 | foreach ($chat_id_list as $chat_id) { 270 | $this->chat_list[$chat_id] = new Skype_Chat($this, $chat_id); 271 | } 272 | 273 | $this->_requestCallback($this->callback['chats'], $chat_id_list); 274 | } 275 | 276 | public function handleChatmember($s) { 277 | // not yet implemented 278 | } 279 | 280 | public function handleChatmessage($s) { 281 | list($chatmessage_id, $property, $value) = explode(" ", $s, 3); 282 | 283 | if (isset($this->chatmessage_cache[$chatmessage_id]) == false) { 284 | if (count($this->chatmessage_cache) >= $this->chatmessage_cache_size) { 285 | array_shift($this->chatmessage_cache); 286 | } 287 | $this->chatmessage_cache[$chatmessage_id] = new Skype_Chatmessage($this, $chatmessage_id); 288 | } 289 | $chatmessage = $this->chatmessage_cache[$chatmessage_id]; 290 | 291 | $chatmessage->set($property, $value); 292 | 293 | $this->_requestCallback($this->callback['chatmessage'], $chatmessage, $chatmessage_id, $property, $value); 294 | } 295 | 296 | public function handleConnstatus($status) { 297 | $this->connection_status = $status; 298 | $this->_requestCallback($this->callback['connstatus'], $status); 299 | } 300 | 301 | public function handleContacts($s) { 302 | $tmp = explode(" ", $s, 2); 303 | if (count($tmp) <= 1) { 304 | // lost focus 305 | $this->contact_focus = null; 306 | } else { 307 | $this->contact_focus = $tmp[1]; 308 | } 309 | 310 | $this->_requestCallback($this->callback['contacts'], $this->contact_focus); 311 | } 312 | 313 | public function handleCurrentuserhandle($current_user_handle) { 314 | $this->current_user_handle = $current_user_handle; 315 | $this->_requestCallback($this->callback['currentuserhandle'], $current_user_handle); 316 | } 317 | 318 | public function handleFiletransfer($s) { 319 | list($filetransfer_id, $property, $value) = explode(" ", $s, 3); 320 | 321 | if (isset($this->filetransfer_cache[$filetransfer_id]) == false) { 322 | if (count($this->filetransfer_cache) >= $this->filetransfer_cache_size) { 323 | array_shift($this->filetransfer_cache); 324 | } 325 | $this->filetransfer_cache[$filetransfer_id] = new Skype_Filetransfer($this, $filetransfer_id); 326 | } 327 | $filetransfer = $this->filetransfer_cache[$filetransfer_id]; 328 | 329 | $filetransfer->set($property, $value); 330 | 331 | $this->_requestCallback($this->callback['filetransfer'], $filetransfer, $filetransfer_id, $property, $value); 332 | } 333 | 334 | public function handleGroup($s) { 335 | list($group_id, $property, $value) = explode(" ", $s, 3); 336 | 337 | if (isset($this->group_list[$group_id]) == false) { 338 | $this->group_list[$group_id] = new Skype_Group($this, $group_id); 339 | } 340 | $group = $this->group_list[$group_id]; 341 | 342 | $group->set($property, $value); 343 | 344 | $this->_requestCallback($this->callback['group'], $group, $group_id, $property, $value); 345 | } 346 | 347 | public function handleUser($s) { 348 | list($user_id, $property, $value) = explode(" ", $s, 3); 349 | 350 | if (isset($this->user_list[$user_id]) == false) { 351 | $this->user_list[$user_id] = new Skype_User($this, $user_id); 352 | } 353 | $user = $this->user_list[$user_id]; 354 | 355 | $user->set($property, $value); 356 | 357 | $this->_requestCallback($this->callback['user'], $user, $user_id, $property, $value); 358 | } 359 | 360 | public function handleUserStatus($user_status) { 361 | $this->user_status = $user_status; 362 | 363 | $this->_requestCallback($this->callback['userstatus'], $user_status); 364 | } 365 | 366 | public function handleProfile($s) { 367 | list($property, $value) = explode(" ", $s, 2); 368 | 369 | if (is_null($this->profile)) { 370 | $this->profile = new Skype_Profile($this, null); 371 | } 372 | $profile->set($property, $value); 373 | 374 | $this->_requestCallback($this->callback['profile'], $this->profile, null, $property, $value); 375 | } 376 | /* }}} */ 377 | 378 | /* {{{ accessor */ 379 | public function isDebug() { 380 | return $this->debug; 381 | } 382 | 383 | public function getCallbackTypeList() { 384 | return array_keys($this->callback); 385 | } 386 | 387 | public function getId() { 388 | return $this->id; 389 | } 390 | 391 | public function getProtocol() { 392 | return $this->protocol; 393 | } 394 | 395 | public function getTiemout() { 396 | return $this->timeout; 397 | } 398 | 399 | public function setTimeout($timeout) { 400 | $this->timeout = $timeout; 401 | } 402 | 403 | public function getCall($call_id) { 404 | if (isset($this->call_list[$call_id]) == false) { 405 | return null; 406 | } 407 | 408 | return $this->call_list[$call_id]; 409 | } 410 | 411 | public function getChat($chat_id) { 412 | if (isset($this->chat_list[$chat_id]) == false) { 413 | $chat = new Skype_Chat($this, $chat_id); 414 | $this->chat_list[$chat_id] = $chat; 415 | } 416 | 417 | return $this->chat_list[$chat_id]; 418 | } 419 | 420 | public function getChatmessage($chatmessage_id) { 421 | if (isset($this->chatmessage_cache[$chatmessage_id]) == false) { 422 | $chatmessage = new Skype_Chatmessage($this, $chatmessage_id); 423 | $this->chatmessage_cache[$chatmessage_id] = $chatmessage; 424 | if (count($this->chatmessage_cache) > $this->chatmessage_cache_size) { 425 | array_shift($this->chatmessage_cache); 426 | } 427 | } 428 | 429 | return $this->chatmessage_cache[$chatmessage_id]; 430 | } 431 | 432 | public function getConnectionStatus() { 433 | return $this->connection_status; 434 | } 435 | 436 | public function getContactFocus() { 437 | return $this->contact_focus; 438 | } 439 | 440 | public function getCurrentUserHandle() { 441 | return $this->current_user_handle; 442 | } 443 | 444 | public function getFiletransfer($filetransfer_id) { 445 | if (isset($this->filetransfer_cache[$filetransfer_id]) == false) { 446 | $filetransfer = new Skype_Filetransfer($this, $filetransfer_id); 447 | $this->filetransfer_cache[$filetransfer_id] = $filetransfer; 448 | if (count($this->filetransfer_cache) > $this->filetransfer_cache_size) { 449 | array_shift($this->filetransfer_cache); 450 | } 451 | } 452 | 453 | return $this->filetransfer_cache[$filetransfer_id]; 454 | } 455 | 456 | public function getGroup($group_id) { 457 | if (isset($this->group_list[$group_id]) == false) { 458 | $group = new Skype_Group($this, $group_id); 459 | $this->group_list[$group_id] = $group; 460 | } 461 | 462 | return $this->group_list[$group_id]; 463 | } 464 | 465 | public function getUser($user_id) { 466 | if (isset($this->user_list[$user_id]) == false) { 467 | $user = new Skype_User($this, $user_id); 468 | $this->user_list[$user_id] = $user; 469 | } 470 | 471 | return $this->user_list[$user_id]; 472 | } 473 | 474 | public function getUserStatus() { 475 | return $this->user_status; 476 | } 477 | 478 | public function getProfile() { 479 | if (is_null($this->profile)) { 480 | $this->profile = new Skype_Profile($this, null); 481 | } 482 | 483 | return $this->profile; 484 | } 485 | 486 | public function getChatList() { 487 | return $this->chat_list; 488 | } 489 | /* }}} */ 490 | 491 | protected function _requestCallback($callback_list, $args) { 492 | $args = func_get_args(); 493 | array_shift($args); 494 | 495 | foreach ($callback_list as $callback) { 496 | call_user_func_array($callback, $args); 497 | } 498 | } 499 | 500 | protected function _debug($format) { 501 | if ($this->debug == false) { 502 | return; 503 | } 504 | $args = func_get_args(); 505 | array_shift($args); 506 | vprintf($format, $args); 507 | } 508 | } 509 | 510 | /* 511 | * Local variables: 512 | * tab-width: 4 513 | * c-basic-offset: 4 514 | * End: 515 | * vim600: noet sw=4 ts=4 fdm=marker 516 | * vim<600: noet sw=4 ts=4 517 | */ 518 | ?> 519 | -------------------------------------------------------------------------------- /Skype/Bot.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | require_once 'Skype.php'; 19 | require_once 'Skype/Bot/Plugin.php'; 20 | 21 | class Skype_Bot { 22 | protected $debug; 23 | private $skype; 24 | protected $plugin_list = array(); 25 | protected $poll_list = array(); 26 | 27 | public function __construct($id, $debug = false) { 28 | $this->debug = $debug; 29 | $this->skype = new Skype($id, Skype::default_protocol, $debug); 30 | } 31 | 32 | public function run() { 33 | $this->_startup(); 34 | 35 | for (;;) { 36 | try { 37 | $this->skype->poll(1); 38 | foreach ($this->poll_list as $plugin_id => $tmp) { 39 | $ts = time(); 40 | $tmp['plugin']->poll($ts, $tmp['ts']); 41 | $this->poll_list[$plugin_id]['ts'] = $ts; 42 | } 43 | } catch (Skype_Exception $e) { 44 | print $e; 45 | } catch (Exception $e) { 46 | print $e; 47 | } 48 | } 49 | } 50 | 51 | public function loadPlugin($plugin_id, $parameter) { 52 | if (isset($this->plugin_list[$plugin_id])) { 53 | return true; 54 | } 55 | 56 | $klass = sprintf("Skype_Bot_Plugin_%s", ucfirst(strtolower($plugin_id))); 57 | if (class_exists($klass) == false) { 58 | $path = sprintf("Skype/Bot/Plugin/%s.php", ucfirst(strtolower($plugin_id))); 59 | include_once($path); 60 | } 61 | if (class_exists($klass) == false) { 62 | throw new Exception(sprintf("plugin class not found [%s]", $klass)); 63 | } 64 | 65 | $plugin = new $klass($this, $parameter); 66 | if (is_subclass_of($klass, "Skype_Bot_Plugin") == false) { 67 | throw new Exception(sprintf("plugin class [%s] does not have Skype_Bot_Plugin class as a parent", $klass)); 68 | } 69 | 70 | $this->plugin_list[$plugin_id] = $plugin; 71 | if ($plugin->isPoll()) { 72 | $this->poll_list[$plugin_id] = array('ts' => null, 'plugin' => $plugin); 73 | } 74 | 75 | // add callbacks (...) 76 | $callback_type_list = $this->skype->getCallbackTypeList(); 77 | foreach ($callback_type_list as $type) { 78 | $this->skype->addCallback($type, array($plugin, sprintf("handle%s", ucfirst($type)))); 79 | } 80 | 81 | return true; 82 | } 83 | 84 | /* {{{ accessor */ 85 | public function isDebug() { 86 | return $this->debug; 87 | } 88 | 89 | public function getSkype() { 90 | return $this->skype; 91 | } 92 | /* }}} */ 93 | 94 | private function _startup() { 95 | $this->skype->connect(); 96 | 97 | // search friends, group, chats in advance 98 | $user_id_list = $this->skype->invokeSearchFriends(); 99 | foreach ($user_id_list as $user_id) { 100 | if ($user_id != '') { 101 | $this->skype->getUser($user_id); // dummy 102 | } 103 | } 104 | 105 | $group_id_list = $this->skype->invokeSearchGroups(Skype_Group::search_type_all); 106 | foreach ($group_id_list as $group_id) { 107 | $this->skype->getGroup($group_id); // dummy 108 | } 109 | 110 | $this->skype->invokeSearchChats(); // invokeSearchChats does not return chat ids... 111 | 112 | return true; 113 | } 114 | } 115 | 116 | /* 117 | * Local variables: 118 | * tab-width: 4 119 | * c-basic-offset: 4 120 | * End: 121 | * vim600: noet sw=4 ts=4 fdm=marker 122 | * vim<600: noet sw=4 ts=4 123 | */ 124 | ?> 125 | -------------------------------------------------------------------------------- /Skype/Bot/Plugin.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Bot_Plugin { 19 | protected $skype_bot = null; 20 | protected $skype = null; 21 | protected $chat_topic_filter = null; 22 | protected $chat_id_filter = null; 23 | protected $poll = false; 24 | 25 | public function __construct($skype_bot, $parameter) { 26 | $this->skype_bot = $skype_bot; 27 | $this->skype = $skype_bot->getSkype(); 28 | 29 | if (isset($parameter['chat_topic_filter'])) { 30 | $this->chat_topic_filter = $parameter['chat_topic_filter']; 31 | } 32 | if (isset($parameter['chat_id_filter'])) { 33 | $this->chat_id_filter = $parameter['chat_id_filter']; 34 | } 35 | } 36 | 37 | public function isPoll() { 38 | return $this->poll; 39 | } 40 | 41 | public function handleCall() { 42 | } 43 | 44 | public function handleChat($chat, $chat_id, $property, $value) { 45 | } 46 | 47 | public function handleChats($chat_id_list) { 48 | } 49 | 50 | public function handleChatmember() { 51 | } 52 | 53 | public function handleChatmessage($chatmessage, $chatmessage_id, $property, $value) { 54 | } 55 | 56 | public function handleConnstatus($status) { 57 | } 58 | 59 | public function handleContacts($contact_focus) { 60 | } 61 | 62 | public function handleCurrentuserhandle($current_user_handle) { 63 | } 64 | 65 | public function handleFiletransfer($filetransfer, $filetransfer_id, $property, $value) { 66 | } 67 | 68 | public function handleGroup($group, $group_id, $property, $value) { 69 | } 70 | 71 | public function handleUser($user, $user_id, $property, $value) { 72 | } 73 | 74 | public function handleUserstatus($user_status) { 75 | } 76 | 77 | public function poll($ts, $ts_prev) { 78 | } 79 | 80 | protected function _chatFilter($chat) { 81 | if (is_null($this->chat_topic_filter) == false) { 82 | if (preg_match($this->chat_topic_filter, $chat->get('TOPIC')) == 0) { 83 | return false; 84 | } 85 | } 86 | if (is_null($this->chat_id_filter) == false) { 87 | if (preg_match($this->chat_id_filter, $chat->getId()) == 0) { 88 | return false; 89 | } 90 | } 91 | 92 | return true; 93 | } 94 | } 95 | 96 | /* 97 | * Local variables: 98 | * tab-width: 4 99 | * c-basic-offset: 4 100 | * End: 101 | * vim600: noet sw=4 ts=4 fdm=marker 102 | * vim<600: noet sw=4 ts=4 103 | */ 104 | ?> 105 | -------------------------------------------------------------------------------- /Skype/Bot/Plugin/Log.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Bot_Plugin_Log extends Skype_Bot_Plugin { 19 | private $dir; 20 | private $format = "{TIMESTAMP}\t[{TYPE}]\t{FROM_DISPNAME}({FROM_HANDLE})\t{BODY}{EDITED}\n"; 21 | 22 | public function __construct($skype_bot, $parameter) { 23 | parent::__construct($skype_bot, $parameter); 24 | 25 | if (isset($parameter['dir']) == false || is_dir($parameter['dir']) == false) { 26 | throw new Exception(sprintf("parameter [dir] seems to be invalid or not set")); 27 | } 28 | $this->dir = $parameter['dir']; 29 | 30 | if (isset($parameter['format'])) { 31 | $this->format = $parameter['format']; 32 | } 33 | } 34 | 35 | public function handleChatmessage($chatmessage, $chatmessage_id, $property, $value) { 36 | if ($property != 'BODY' && $property != 'STATUS') { 37 | return; 38 | } 39 | if ($property == 'STATUS' && ($value == Skype_Chatmessage::status_read || $value == Skype_Chatmessage::status_sending)) { 40 | return; 41 | } 42 | $property_list = $chatmessage->toArray(); 43 | 44 | // beautify 45 | $tmp = $property_list; 46 | $tmp['TIMESTAMP'] = strftime('%Y/%m/%d %H:%M:%S', $tmp['TIMESTAMP']); 47 | if ($tmp['EDITED_BY']) { 48 | $tmp['EDITED'] = sprintf(" (%s: %s edited)", strftime('%Y/%m/%d %H:%M:%S', $tmp['EDITED_TIMESTAMP']), $tmp['EDITED_BY']); 49 | } else { 50 | $tmp['EDITED'] = ''; 51 | } 52 | 53 | $this->_append($this->skype->getChat($chatmessage->get('CHATNAME')), $this->format, $tmp); 54 | } 55 | 56 | private function _append($chat, $format, $parameter) { 57 | if ($this->_chatFilter($chat) == false) { 58 | return false; 59 | } 60 | 61 | // TODO: pluggable log file format 62 | $r = array('#' => '', '/' => '-', '$' => '', ';' => '-'); 63 | $chat_id = preg_replace('/([#$;\/])/e', "\$r['\$1']", $chat->getId()); 64 | $path = sprintf("%s/%s.%s.log", $this->dir, $chat_id, strftime('%Y%m%d')); 65 | $fp = fopen($path, "a"); 66 | if (!$fp) { 67 | return false; 68 | } 69 | fwrite($fp, $this->_format($format, $parameter)); 70 | fclose($fp); 71 | 72 | return true; 73 | } 74 | 75 | private function _format($format, $parameter) { 76 | // :( 77 | foreach ($parameter as $key => $value) { 78 | if (is_array($value)) { 79 | // anyway 80 | continue; 81 | } 82 | $format = str_replace("{{$key}}", $value, $format); 83 | } 84 | 85 | return $format; 86 | } 87 | } 88 | ?> 89 | -------------------------------------------------------------------------------- /Skype/Call.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Call extends Skype_Object { 19 | protected $property_def_list = array( 20 | 'TIMESTAMP' => array( 21 | 'default' => false, 22 | 'type' => Skype::property_type_int, 23 | ), 24 | 'PARTNER_HANDLE' => array( 25 | 'default' => false, 26 | 'type' => Skype::property_type_string, 27 | ), 28 | 'PARTNER_DISPNAME' => array( 29 | 'default' => false, 30 | 'type' => Skype::property_type_string, 31 | ), 32 | 'TARGET_IDENTITY' => array( 33 | 'default' => false, 34 | 'type' => Skype::property_type_string, 35 | ), 36 | 'CONF_ID' => array( 37 | 'default' => false, 38 | 'type' => Skype::property_type_int, 39 | ), 40 | 'TYPE' => array( 41 | 'default' => false, 42 | 'type' => Skype::property_type_string, 43 | ), 44 | 'STATUS' => array( 45 | 'default' => true, 46 | 'type' => Skype::property_type_string, 47 | ), 48 | 'VIDEO_STATUS' => array( 49 | 'default' => false, 50 | 'type' => Skype::property_type_string, 51 | ), 52 | 'VIDEO_SEND_STATUS' => array( 53 | 'default' => false, 54 | 'type' => Skype::property_type_string, 55 | ), 56 | 'VIDEO_RECEIVE_STATUS' => array( 57 | 'default' => false, 58 | 'type' => Skype::property_type_string, 59 | ), 60 | 'FAILUREREASON' => array( 61 | 'default' => false, 62 | 'type' => Skype::property_type_int, 63 | ), 64 | 'SUBJECT' => array( 65 | 'default' => false, 66 | 'type' => Skype::property_type_string, 67 | ), 68 | 'PSTN_NUMBER' => array( 69 | 'default' => false, 70 | 'type' => Skype::property_type_string, 71 | ), 72 | 'DURATION' => array( 73 | 'default' => false, 74 | 'type' => Skype::property_type_int, 75 | ), 76 | 'PSTN_STATUS' => array( 77 | 'default' => false, 78 | 'type' => Skype::property_type_string, 79 | ), 80 | 'CONF_PARTICIPANTS_COUNT' => array( 81 | 'default' => false, 82 | 'type' => Skype::property_type_int, 83 | ), 84 | 85 | // protocol 6 86 | 'RATE' => array( 87 | 'default' => false, 88 | 'type' => Skype::property_type_string, 89 | ), 90 | 'RATE_CURRENCY' => array( 91 | 'default' => false, 92 | 'type' => Skype::property_type_string, 93 | ), 94 | 'RATE_PRECISION' => array( 95 | 'default' => false, 96 | 'type' => Skype::property_type_string, 97 | ), 98 | 'VAA_INPUT_STATUS' => array( 99 | 'default' => false, 100 | 'type' => Skype::property_type_bool, 101 | ), 102 | 103 | // and more... 104 | ); 105 | 106 | protected $ident = "CALL"; 107 | 108 | public function invokeCallStatusFinish() { 109 | return $this->skype->invokeCallStatusFinish($this->getId()); 110 | } 111 | } 112 | 113 | /* 114 | * Local variables: 115 | * tab-width: 4 116 | * c-basic-offset: 4 117 | * End: 118 | * vim600: noet sw=4 ts=4 fdm=marker 119 | * vim<600: noet sw=4 ts=4 120 | */ 121 | ?> 122 | -------------------------------------------------------------------------------- /Skype/Chat.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Chat extends Skype_Object { 19 | protected $property_def_list = array( 20 | // Protocol 3 21 | 'NAME' => array( 22 | 'default' => true, 23 | 'type' => Skype::property_type_string 24 | ), 25 | 'TIMESTAMP' => array( 26 | 'default' => true, 27 | 'type' => Skype::property_type_int, 28 | ), 29 | 'ADDER' => array( 30 | 'default' => true, 31 | 'type' => Skype::property_type_string, 32 | ), 33 | 'STATUS' => array( 34 | 'default' => true, 35 | 'type' => Skype::property_type_string, 36 | ), 37 | 'POSTERS' => array( 38 | 'default' => true, 39 | 'type' => array(Skype::property_type_string), 40 | ), 41 | 'MEMBERS' => array( 42 | 'default' => true, 43 | 'type' => array(Skype::property_type_string), 44 | ), 45 | 'TOPIC' => array( 46 | 'default' => true, 47 | 'type' => Skype::property_type_string, 48 | ), 49 | 'TOPICXML' => array( 50 | 'default' => false, 51 | 'type' => Skype::property_type_string, 52 | ), 53 | 'CHATMESSAGES' => array( 54 | 'default' => false, 55 | 'type' => array(Skype::property_type_int), 56 | ), 57 | 'ACTIVEMEMBERS' => array( 58 | 'default' => true, 59 | 'type' => array(Skype::property_type_string), 60 | ), 61 | 'FRIENDLYNAME' => array( 62 | 'default' => true, 63 | 'type' => Skype::property_type_string, 64 | ), 65 | 'RECENTCHATMESSAGES' => array( 66 | 'default' => true, 67 | 'type' => array(Skype::property_type_int), 68 | ), 69 | 70 | // Protocol 6 71 | 'BOOKMARKED' => array( 72 | 'default' => true, 73 | 'type' => Skype::property_type_bool, 74 | ), 75 | 76 | // Protocol 7 77 | 'PASSWORDHINT' => array( 78 | 'default' => false, 79 | 'type' => Skype::property_type_string, 80 | ), 81 | 'GUIDELINES' => array( 82 | 'default' => false, 83 | 'type' => Skype::property_type_string, 84 | ), 85 | 'OPTIONS' => array( 86 | 'default' => false, 87 | 'type' => Skype::property_type_int, 88 | ), 89 | 'DESCRIPTION' => array( 90 | 'default' => false, 91 | 'type' => Skype::property_type_string, 92 | ), 93 | 'DIALOG_PARTNER' => array( 94 | 'default' => false, 95 | 'type' => Skype::property_type_string, 96 | ), 97 | 'ACTIVITY_TIMESTAMP' => array( 98 | 'default' => true, 99 | 'type' => Skype::property_type_int, 100 | ), 101 | 'TYPE' => array( 102 | 'default' => true, 103 | 'type' => Skype::property_type_string, 104 | ), 105 | 'MYSTATUS' => array( 106 | 'default' => true, 107 | 'type' => Skype::property_type_string, 108 | ), 109 | 'MYROLE' => array( 110 | 'default' => true, 111 | 'type' => Skype::property_type_string, 112 | ), 113 | // and more... 114 | ); 115 | 116 | protected $ident = "CHAT"; 117 | 118 | public function invokeChatmessage($message) { 119 | return $this->skype->invokeChatmessage($this->getId(), $message); 120 | } 121 | 122 | public function invokeAlterChatSettopic($topic) { 123 | return $this->skype->invokeAlterChatSettopic($this->getId(), $topic); 124 | } 125 | } 126 | 127 | /* 128 | * Local variables: 129 | * tab-width: 4 130 | * c-basic-offset: 4 131 | * End: 132 | * vim600: noet sw=4 ts=4 fdm=marker 133 | * vim<600: noet sw=4 ts=4 134 | */ 135 | ?> 136 | -------------------------------------------------------------------------------- /Skype/Chatmessage.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Chatmessage extends Skype_Object { 19 | const status_sending = "SENDING"; 20 | const status_sent = "SENT"; 21 | const status_received = "RECEIVED"; 22 | const status_read = "READ"; 23 | 24 | protected $property_def_list = array( 25 | 'TIMESTAMP' => array( 26 | 'default' => true, 27 | 'type' => Skype::property_type_int, 28 | ), 29 | 'FROM_HANDLE' => array( 30 | 'default' => true, 31 | 'type' => Skype::property_type_string, 32 | ), 33 | 'FROM_DISPNAME' => array( 34 | 'default' => true, 35 | 'type' => Skype::property_type_string, 36 | ), 37 | 'TYPE' => array( 38 | 'default' => true, 39 | 'type' => Skype::property_type_string, 40 | ), 41 | 'STATUS' => array( 42 | 'default' => true, 43 | 'type' => Skype::property_type_string, 44 | ), 45 | 'LEAVEREASON' => array( 46 | 'default' => true, 47 | 'type' => Skype::property_type_string, 48 | ), 49 | 'CHATNAME' => array( 50 | 'default' => true, 51 | 'type' => Skype::property_type_string, 52 | ), 53 | 'USERS' => array( 54 | 'default' => true, 55 | 'type' => array(Skype::property_type_string), 56 | ), 57 | 'IS_EDITABLE' => array( 58 | 'default' => true, 59 | 'type' => Skype::property_type_bool, 60 | ), 61 | 'EDITED_BY' => array( 62 | 'default' => true, 63 | 'type' => Skype::property_type_string, 64 | ), 65 | 'EDITED_TIMESTAMP' => array( 66 | 'default' => true, 67 | 'type' => Skype::property_type_string, 68 | ), 69 | 'OPTIONS' => array( 70 | 'default' => true, 71 | 'type' => Skype::property_type_int, 72 | ), 73 | 'ROLE' => array( 74 | 'default' => true, 75 | 'type' => Skype::property_type_string, 76 | ), 77 | 'BODY' => array( 78 | 'default' => true, 79 | 'type' => Skype::property_type_string, 80 | ), 81 | ); 82 | 83 | protected $ident = "CHATMESSAGE"; 84 | } 85 | 86 | /* 87 | * Local variables: 88 | * tab-width: 4 89 | * c-basic-offset: 4 90 | * End: 91 | * vim600: noet sw=4 ts=4 fdm=marker 92 | * vim<600: noet sw=4 ts=4 93 | */ 94 | ?> 95 | -------------------------------------------------------------------------------- /Skype/Exception.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Exception extends Exception { 19 | // https://developer.skype.com/Docs/ApiDoc/Error_codes 20 | private $map = array ( 21 | 1 => 'General syntax error', 22 | 2 => 'Unknown command', 23 | 3 => 'Search: unknown WHAT', 24 | 4 => 'Empty target not allowed', 25 | 5 => 'Search CALLS: invalid target', 26 | 6 => 'SEARCH MISSEDCALLS: target not allowed', 27 | 7 => 'GET: invalid WHAT', 28 | 8 => 'Invalid user handle', 29 | 9 => 'Unknown user', 30 | 10 => 'Invalid PROP', 31 | 11 => 'Invalid call id', 32 | 12 => 'Unknown call', 33 | 13 => 'Invalid PROP', 34 | 14 => 'Invalid message id', 35 | 15 => 'Unknown message', 36 | 16 => 'Invalid PROP', 37 | 17 => '(Not in use)', 38 | 18 => 'SET: invalid WHAT', 39 | 19 => 'Invalid call id', 40 | 20 => 'Unknown call', 41 | 21 => 'Unknown/disallowed call prop', 42 | 22 => 'Cannot hold this call at the moment', 43 | 23 => 'Cannot resume this call at the moment', 44 | 24 => 'Cannot hangup inactive call', 45 | 25 => 'Unknown WHAT', 46 | 26 => 'Invalid user handle', 47 | 27 => 'Invalid version number', 48 | 28 => 'Unknown userstatus', 49 | 29 => 'SEARCH what: target not allowed', 50 | 30 => 'Invalid message id', 51 | 31 => 'Unknown message id', 52 | 32 => 'Invalid WHAT', 53 | 33 => 'invalid parameter', 54 | 34 => 'invalid user handle', 55 | 35 => 'Not connected', 56 | 36 => 'Not online', 57 | 37 => 'Not connected', 58 | 38 => 'Not online', 59 | 39 => 'user blocked', 60 | 40 => 'Unknown privilege', 61 | 41 => 'Call not active', 62 | 42 => 'Invalid DTMF code', 63 | 43 => 'cannot send empty message', 64 | 50 => 'cannot set device', 65 | 51 => 'invalid parameter', 66 | 52 => 'invalid parameter', 67 | 53 => 'invalid value', 68 | 66 => 'Not connected', 69 | 67 => 'Target not allowed with SEARCH FRIENDS', 70 | 68 => 'Access denied', 71 | 69 => 'Invalid open what', 72 | 70 => 'Invalid handle', 73 | 71 => 'Invalid conference participant NO', 74 | 72 => 'Cannot create conference', 75 | 73 => 'too many participants', 76 | 74 => 'Invalid key', 77 | 91 => 'call error', 78 | 92 => 'call error', 79 | 93 => 'call error', 80 | 94 => 'call error', 81 | 95 => 'Internal error', 82 | 96 => 'Internal error', 83 | 97 => 'Internal error', 84 | 98 => 'Internal error', 85 | 99 => 'Internal error', 86 | 100 => 'Internal error', 87 | 101 => 'Internal error', 88 | 103 => 'Cannot hold', 89 | 104 => 'Cannot resume', 90 | 105 => 'Invalid chat name', 91 | 106 => 'Invalid PROP', 92 | 107 => 'Target not allowed with CHATS', 93 | 108 => 'User not contact', 94 | 109 => 'directory doesn\'t exist', 95 | 110 => 'No voicemail capability', 96 | 111 => 'File not found', 97 | 112 => 'Too many targets', 98 | 113 => 'Close: invalid WHAT', 99 | 114 => 'Invalid avatar', 100 | 115 => 'Invalid ringtone', 101 | 500 => 'CHAT: Invalid chat name given', 102 | 501 => 'CHAT: No chat found for given chat', 103 | 502 => 'CHAT: No action name given', 104 | 503 => 'CHAT: Invalid or unknown action', 105 | 504 => 'CHAT: action failed', 106 | 505 => 'CHAT: LEAVE does not take arguments', 107 | 506 => 'CHAT: ADDMEMBERS: invalid/missing user handle(s) as arguments', 108 | 507 => 'CHAT: CREATE: invalid/missing user handle(s) as argument', 109 | 508 => 'CHAT: CREATE: opening a dialog to the given user failed', 110 | 509 => 'No chat name given', 111 | 510 => 'Invalid/uknown chat name given', 112 | 511 => 'Sending a message to chat failes', 113 | 512 => 'Invalid voicemail id', 114 | 513 => 'Invalid voicemail object', 115 | 514 => 'No voicemail property given', 116 | 515 => 'Assigning speeddial property failed', 117 | 516 => 'Invalid value given to ISAUTHORIZED/ISBLOCKED', 118 | 517 => 'Changing ISAUTHORIZED/ISBLOCKED failed', 119 | 518 => 'Invalid status given for BUDDYSTATUS', 120 | 519 => 'Updating BUDDYSTATUS failed', 121 | 520 => 'CLEAR needs a target', 122 | 521 => 'Invalid/unknown CLEAR target', 123 | 522 => 'CLEAR CHATHISTORY takes no arguments', 124 | 523 => 'CLEAR VOICEMAILHISTORY takes no arguments', 125 | 524 => 'CLEAR CALLHISTORY: missing target argument', 126 | 525 => 'CLEAR CALLHISTORY: invalid handle argument', 127 | 526 => 'ALTER: no object type given', 128 | 527 => 'ALTER: unknown object type given', 129 | 528 => 'VOICEMAIL: No proper voicemail ID given', 130 | 529 => 'VOICEMAIL: Invalid voicemail ID given', 131 | 530 => 'VOICEMAIL: No action given', 132 | 531 => 'VOICEMAIL: Action failed', 133 | 532 => 'VOICEMAIL: Unknown action', 134 | 534 => 'SEARCH GREETING: invalid handle', 135 | 535 => 'SEARCH GREETING: unable to get greeting', 136 | 536 => 'CREATE: no object type given', 137 | 537 => 'CREATE : Unknown object type given.', 138 | 538 => 'DELETE : no object type given.', 139 | 539 => 'DELETE : unknown object type given.', 140 | 540 => 'CREATE APPLICATION : missing of invalid name.', 141 | 541 => 'APPLICATION : Operation Failed.', 142 | 542 => 'DELETE APPLICATION : missing or invalid application name.', 143 | 543 => 'GET APPLICATION : missing or invalid application name.', 144 | 544 => 'GET APPLICATION : missing or invalid property name.', 145 | 545 => 'ALTER APPLICATION : missing or invalid action.', 146 | 546 => 'ALTER APPLICATION : Missing or invalid action', 147 | 547 => 'ALTER APPLICATION CONNECT: Invalid user handle', 148 | 548 => 'ALTER APPLICATION DISCONNECT: Invalid stream identifier', 149 | 549 => 'ALTER APPLICATION WRITE : Missing or invalid stream identifier', 150 | 550 => 'ALTER APPLICATION READ : Missing or invalid stream identifier', 151 | 551 => 'ALTER APPLICATION DATAGRAM : Missing or invalid stream identifier', 152 | 552 => 'SET PROFILE : invalid property profile given', 153 | 553 => 'SET PROFILE CALL_SEND_TO_VM : no voicemail privledge, can\'t forward to voicemail.', 154 | 555 => 'CALL: No proper call ID given', 155 | 556 => 'CALL: Invalid call ID given"', 156 | 557 => 'CALL: No action given', 157 | 558 => 'CALL: Missing or invalid arguments', 158 | 559 => 'CALL: Action failed', 159 | 560 => 'CALL: Unknown action', 160 | 561 => 'SEARCH GROUPS: invalid target"', 161 | 562 => 'SEARCH GROUPS: Invalid group id', 162 | 563 => 'SEARCH GROUPS: Invalid group object', 163 | 564 => 'SEARCH GROUPS: Invalid group property given', 164 | 569 => 'GET AEC: target not allowed"', 165 | 570 => 'SET AEC: invalid value"', 166 | 571 => 'GET AGC: target not allowed"', 167 | 572 => 'SET AGC: invalid value"', 168 | 9901 => 'Internal error', 169 | ); 170 | 171 | public function __construct($message, $code) { 172 | if (is_null($message) && isset($this->map[$code])) { 173 | $message = $this->map[$code]; 174 | } 175 | parent::__construct($message, $code); 176 | } 177 | } 178 | 179 | /* 180 | * Local variables: 181 | * tab-width: 4 182 | * c-basic-offset: 4 183 | * End: 184 | * vim600: noet sw=4 ts=4 fdm=marker 185 | * vim<600: noet sw=4 ts=4 186 | */ 187 | ?> 188 | -------------------------------------------------------------------------------- /Skype/Filetransfer.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Filetransfer extends Skype_Object { 19 | protected $property_def_list = array( 20 | 'TYPE' => array( 21 | 'default' => true, 22 | 'type' => Skype::property_type_string, 23 | ), 24 | 'STATUS' => array( 25 | 'default' => true, 26 | 'type' => Skype::property_type_string, 27 | ), 28 | 'FAILUREREASON' => array( 29 | 'default' => true, 30 | 'type' => Skype::property_type_string, 31 | ), 32 | 'PARTNER_HANDLE' => array( 33 | 'default' => true, 34 | 'type' => Skype::property_type_string, 35 | ), 36 | 'PARTNER_DISPNAME' => array( 37 | 'default' => true, 38 | 'type' => Skype::property_type_string, 39 | ), 40 | 'STARTTIME' => array( 41 | 'default' => true, 42 | 'type' => Skype::property_type_int, 43 | ), 44 | 'FINISHTIME' => array( 45 | 'default' => true, 46 | 'type' => Skype::property_type_int, 47 | ), 48 | 'FILEPATH' => array( 49 | 'default' => true, 50 | 'type' => Skype::property_type_string, 51 | ), 52 | 'FILENAME' => array( 53 | 'default' => true, 54 | 'type' => Skype::property_type_string, 55 | ), 56 | 'FILESIZE' => array( 57 | 'default' => true, 58 | 'type' => Skype::property_type_int, 59 | ), 60 | 'BYTESPERSECOND' => array( 61 | 'default' => true, 62 | 'type' => Skype::property_type_int, 63 | ), 64 | 'BYTESTRANSFERRED' => array( 65 | 'default' => true, 66 | 'type' => Skype::property_type_int, 67 | ), 68 | ); 69 | 70 | protected $ident = "FILETRANSFER"; 71 | } 72 | 73 | /* 74 | * Local variables: 75 | * tab-width: 4 76 | * c-basic-offset: 4 77 | * End: 78 | * vim600: noet sw=4 ts=4 fdm=marker 79 | * vim<600: noet sw=4 ts=4 80 | */ 81 | ?> 82 | -------------------------------------------------------------------------------- /Skype/Group.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Group extends Skype_Object { 19 | const search_type_all = "ALL"; 20 | const serach_type_custom = "CUSTOM"; 21 | const search_type_hardwired = "HARDWIRED"; 22 | 23 | protected $property_def_list = array( 24 | 'TYPE' => array( 25 | 'default' => true, 26 | 'type' => Skype::property_type_string 27 | ), 28 | 'CUSTOM_GROUP_ID' => array( 29 | 'default' => true, 30 | 'type' => Skype::property_type_string, 31 | ), 32 | 'DISPLAYNAME' => array( 33 | 'default' => true, 34 | 'type' => Skype::property_type_string, 35 | ), 36 | 'NROFUSERS' => array( 37 | 'default' => true, 38 | 'type' => Skype::property_type_string, 39 | ), 40 | 'NROFUSERS_ONLINE' => array( 41 | 'default' => true, 42 | 'type' => array(Skype::property_type_string), 43 | ), 44 | 'USERS' => array( 45 | 'default' => true, 46 | 'type' => array(Skype::property_type_string), 47 | ), 48 | 'VISIBLE' => array( 49 | 'default' => true, 50 | 'type' => Skype::property_type_bool, 51 | ), 52 | 'EXPANDED' => array( 53 | 'default' => true, 54 | 'type' => Skype::property_type_bool, 55 | ), 56 | ); 57 | 58 | protected $ident = "GROUP"; 59 | } 60 | 61 | /* 62 | * Local variables: 63 | * tab-width: 4 64 | * c-basic-offset: 4 65 | * End: 66 | * vim600: noet sw=4 ts=4 fdm=marker 67 | * vim<600: noet sw=4 ts=4 68 | */ 69 | ?> 70 | -------------------------------------------------------------------------------- /Skype/Object.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Object { 19 | protected $property_def_list = array( 20 | ); 21 | 22 | protected $ident = ""; 23 | protected $skype; 24 | protected $id; 25 | protected $property_list; 26 | 27 | public function __construct($skype, $id) { 28 | $this->skype = $skype; 29 | $this->id = $id; 30 | 31 | foreach ($this->property_def_list as $property => $attr) { 32 | $tmp = $this->fetch($property, true); 33 | if ($tmp !== false) { 34 | $this->property_list[$property] = $tmp; 35 | } 36 | } 37 | } 38 | 39 | public function toArray() { 40 | return $this->property_list; 41 | } 42 | 43 | /* {{{ accessor */ 44 | public function getId() { 45 | return $this->id; 46 | } 47 | 48 | public function get($property) { 49 | if (isset($this->property_list[$property])) { 50 | return $this->property_list[$property]; 51 | } 52 | if (isset($this->property_def_list[$property])) { 53 | $this->property_list[$property] = $this->fetch($property); 54 | return $this->property_list[$property]; 55 | } 56 | 57 | throw new Exception(sprintf("unsupported property [%s]", $property)); 58 | } 59 | 60 | /** 61 | * set arbitary property 62 | * 63 | * - does not invoke set methods 64 | * - expecting $value as "plain" text 65 | */ 66 | public function set($property, $value) { 67 | if (isset($this->property_def_list[$property]) == false) { 68 | throw new Exception(sprintf("unsupported property [%s]", $property)); 69 | } 70 | 71 | $this->property_list[$property] = $this->skype->parseProperty($this->property_def_list[$property]['type'], $value); 72 | } 73 | /* }}} */ 74 | 75 | protected function fetch($property, $default = false) { 76 | if (isset($this->property_def_list[$property]) == false) { 77 | throw new Exception(sprintf("unsupported property [%s]", $property)); 78 | } 79 | $def = $this->property_def_list[$property]; 80 | 81 | if ($default && !$def['default']) { 82 | return false; 83 | } 84 | 85 | list($r, $s) = $this->skype->invoke("GET {$this->ident} {$this->id} $property"); 86 | $tmp = explode(" ", $s, 3); 87 | if (isset($tmp[2])) { 88 | $tmp_arg = $tmp[2]; 89 | } else { 90 | $tmp_arg = null; 91 | } 92 | return $this->skype->parseProperty($def['type'], $tmp_arg); 93 | } 94 | } 95 | 96 | /* 97 | * Local variables: 98 | * tab-width: 4 99 | * c-basic-offset: 4 100 | * End: 101 | * vim600: noet sw=4 ts=4 fdm=marker 102 | * vim<600: noet sw=4 ts=4 103 | */ 104 | ?> 105 | -------------------------------------------------------------------------------- /Skype/Profile.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_Profile extends Skype_Object { 19 | protected $property_def_list = array( 20 | 'PSTN_BALANCE' => array( 21 | 'default' => true, 22 | 'type' => Skype::property_type_bool, 23 | ), 24 | 'PSTN_BALANCE_CURRENCY' => array( 25 | 'default' => true, 26 | 'type' => Skype::property_type_string, 27 | ), 28 | 'FULLNAME' => array( 29 | 'default' => true, 30 | 'type' => Skype::property_type_string, 31 | ), 32 | 'BIRTHDAY' => array( 33 | 'default' => true, 34 | 'type' => Skype::property_type_string, 35 | ), 36 | 'SEX' => array( 37 | 'default' => true, 38 | 'type' => Skype::property_type_string, 39 | ), 40 | 'LANGUAGE' => array( 41 | 'default' => true, 42 | 'type' => Skype::property_type_string, 43 | ), 44 | 'COUNTRY' => array( 45 | 'default' => true, 46 | 'type' => Skype::property_type_string, 47 | ), 48 | 'IPCOUNTRY' => array( 49 | 'default' => true, 50 | 'type' => Skype::property_type_string, 51 | ), 52 | 'PROVINCE' => array( 53 | 'default' => true, 54 | 'type' => Skype::property_type_string, 55 | ), 56 | 'CITY' => array( 57 | 'default' => true, 58 | 'type' => Skype::property_type_string, 59 | ), 60 | 'PHONE_HOME' => array( 61 | 'default' => true, 62 | 'type' => Skype::property_type_string, 63 | ), 64 | 'PHONE_OFFICE' => array( 65 | 'default' => true, 66 | 'type' => Skype::property_type_string, 67 | ), 68 | 'PHONE_MOBILE' => array( 69 | 'default' => true, 70 | 'type' => Skype::property_type_string, 71 | ), 72 | 'HOMEPAGE' => array( 73 | 'default' => true, 74 | 'type' => Skype::property_type_string, 75 | ), 76 | 'ABOUT' => array( 77 | 'default' => true, 78 | 'type' => Skype::property_type_string, 79 | ), 80 | 'MOOD_TEXT' => array( 81 | 'default' => true, 82 | 'type' => Skype::property_type_string, 83 | ), 84 | 'RICH_MOOD_TEXT' => array( 85 | 'default' => true, 86 | 'type' => Skype::property_type_string, 87 | ), 88 | 'TIMEZONE' => array( 89 | 'default' => true, 90 | 'type' => Skype::property_type_int, 91 | ), 92 | ); 93 | 94 | protected $ident = "PROFILE"; 95 | } 96 | 97 | /* 98 | * Local variables: 99 | * tab-width: 4 100 | * c-basic-offset: 4 101 | * End: 102 | * vim600: noet sw=4 ts=4 fdm=marker 103 | * vim<600: noet sw=4 ts=4 104 | */ 105 | ?> 106 | -------------------------------------------------------------------------------- /Skype/User.php: -------------------------------------------------------------------------------- 1 | 14 | * @license http://www.php.net/license/3_0.txt PHP License 3.0 15 | * @link http://labs.gree.jp/Top/OpenSource/Skype.html 16 | */ 17 | 18 | class Skype_User extends Skype_Object { 19 | const buddy_status_other = 0; 20 | const buddy_status_deleted = 1; 21 | const buddy_status_pending = 2; 22 | const buddy_status_added = 3; 23 | 24 | protected $property_def_list = array( 25 | 'HANDLE' => array( 26 | 'default' => true, 27 | 'type' => Skype::property_type_string, 28 | ), 29 | 'FULLNAME' => array( 30 | 'default' => true, 31 | 'type' => Skype::property_type_string, 32 | ), 33 | 'BIRTHDAY' => array( 34 | 'default' => true, 35 | 'type' => Skype::property_type_string, 36 | ), 37 | 'SEX' => array( 38 | 'default' => true, 39 | 'type' => Skype::property_type_string, 40 | ), 41 | 'LANGUAGE' => array( 42 | 'default' => true, 43 | 'type' => Skype::property_type_string, 44 | ), 45 | 'COUNTRY' => array( 46 | 'default' => true, 47 | 'type' => Skype::property_type_string, 48 | ), 49 | 'PROVINCE' => array( 50 | 'default' => true, 51 | 'type' => Skype::property_type_string, 52 | ), 53 | 'CITY' => array( 54 | 'default' => true, 55 | 'type' => Skype::property_type_string, 56 | ), 57 | 'PHONE_HOME' => array( 58 | 'default' => true, 59 | 'type' => Skype::property_type_string, 60 | ), 61 | 'PHONE_OFFICE' => array( 62 | 'default' => true, 63 | 'type' => Skype::property_type_string, 64 | ), 65 | 'PHONE_MOBILE' => array( 66 | 'default' => true, 67 | 'type' => Skype::property_type_string, 68 | ), 69 | 'HOMEPAGE' => array( 70 | 'default' => true, 71 | 'type' => Skype::property_type_string, 72 | ), 73 | 'ABOUT' => array( 74 | 'default' => true, 75 | 'type' => Skype::property_type_string, 76 | ), 77 | 'HASCALLEQUIPMENT' => array( 78 | 'default' => true, 79 | 'type' => Skype::property_type_bool, 80 | ), 81 | 'IS_VIDEO_CAPABLE' => array( 82 | 'default' => true, 83 | 'type' => Skype::property_type_bool, 84 | ), 85 | 'BUDDYSTATUS' => array( 86 | 'default' => true, 87 | 'type' => Skype::property_type_int, 88 | ), 89 | 'ISAUTHORIZED' => array( 90 | 'default' => true, 91 | 'type' => Skype::property_type_bool, 92 | ), 93 | 'ISBLOCKED' => array( 94 | 'default' => true, 95 | 'type' => Skype::property_type_bool, 96 | ), 97 | 'ONLINESTATUS' => array( 98 | 'default' => true, 99 | 'type' => Skype::property_type_string, 100 | ), 101 | 'LASTONLINETIMESTAMP' => array( 102 | 'default' => true, 103 | 'type' => Skype::property_type_int, 104 | ), 105 | 'CAN_LEAVE_VM' => array( 106 | 'default' => true, 107 | 'type' => Skype::property_type_bool, 108 | ), 109 | 'SPEEDDIAL' => array( 110 | 'default' => true, 111 | 'type' => Skype::property_type_string, 112 | ), 113 | 'RECEIVEDAUTHREQUEST' => array( 114 | 'default' => true, 115 | 'type' => Skype::property_type_string, 116 | ), 117 | 'MOOD_TEXT' => array( 118 | 'default' => true, 119 | 'type' => Skype::property_type_string, 120 | ), 121 | 'RICH_MOOD_TEXT' => array( 122 | 'default' => true, 123 | 'type' => Skype::property_type_string, 124 | ), 125 | 'ALIASES' => array( 126 | 'default' => true, 127 | 'type' => Skype::property_type_string, 128 | ), 129 | 'TIMEZONE' => array( 130 | 'default' => true, 131 | 'type' => Skype::property_type_int, 132 | ), 133 | 'IS_CF_ACTIVE' => array( 134 | 'default' => true, 135 | 'type' => Skype::property_type_bool, 136 | ), 137 | 'NROF_AUTHED_BUDDIES' => array( 138 | 'default' => true, 139 | 'type' => Skype::property_type_int, 140 | ), 141 | ); 142 | 143 | protected $ident = "USER"; 144 | } 145 | 146 | /* 147 | * Local variables: 148 | * tab-width: 4 149 | * c-basic-offset: 4 150 | * End: 151 | * vim600: noet sw=4 ts=4 fdm=marker 152 | * vim<600: noet sw=4 ts=4 153 | */ 154 | ?> 155 | -------------------------------------------------------------------------------- /example/skype_bot.php: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/php 2 | loadPlugin( 9 | "log", 10 | array( 11 | 'dir' => '/var/tmp', 12 | 'chat_topic_filter' => null, 13 | 'chat_id_filter' => null, 14 | )); 15 | 16 | $bot->run(); 17 | ?> 18 | --------------------------------------------------------------------------------