MadelineProto/classes/shell.php

449 lines
9.3 KiB
PHP
Raw Normal View History

2016-06-23 23:51:08 +02:00
<?php
2016-07-14 15:15:50 +02:00
set_include_path(get_include_path().PATH_SEPARATOR.dirname(__FILE__).DIRECTORY_SEPARATOR.'libpy2php');
require_once 'libpy2php.php';
require_once 'os.php';
class TelepyShell
{
2016-06-23 23:51:08 +02:00
public $intro = 'Welcome to telepy interactive shell. Type help or ? for help.
';
public $prompt = '>';
2016-07-14 15:15:50 +02:00
public function preloop()
{
require_once 'classes/telepy.php';
2016-06-23 23:51:08 +02:00
$this->_telepy = new Telepy();
}
2016-07-14 15:15:50 +02:00
public function precmd($line)
{
2016-06-23 23:51:08 +02:00
$line = $line->lstrip();
$blank_pos = $line->find(' ');
if (($blank_pos < 0)) {
return $line->lower();
}
2016-07-14 15:15:50 +02:00
return array_slice($line, null, $blank_pos)->lower().' '.array_slice($line, ($blank_pos + 1), null);
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
public function completedefault(...$ignored)
{
2016-06-23 23:51:08 +02:00
pyjslib_printnl($ignored);
}
2016-07-14 15:15:50 +02:00
public function complete($text, $state)
{
2016-06-23 23:51:08 +02:00
$this->super()->complete($text, $state);
pyjslib_printnl('completing');
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* shell <command-line>
* lets you use external shell. !<command-line> for short-hand.
*/
2016-07-14 15:15:50 +02:00
public function do_shell($line)
{
2016-06-23 23:51:08 +02:00
pyjslib_printnl(os::popen($line)->read());
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* msg <peer>
2016-07-14 15:15:50 +02:00
* sends message to this peer.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_msg($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* fwd <user> <msg-no>
2016-07-14 15:15:50 +02:00
* forward message to user. You can see message numbers starting client with -N.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_fwd($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* chat_with_peer <peer>
* starts one on one chat session with this peer. /exit or /quit to end this mode.
*/
2016-07-14 15:15:50 +02:00
public function do_chat_with_peer($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* add_contact <phone-number> <first-name> <last-name>
2016-07-14 15:15:50 +02:00
* tries to add contact to contact-list by phone.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_add_contact($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* rename_contact <user> <first-name> <last-name>
2016-07-14 15:15:50 +02:00
* tries to rename contact. If you have another device it will be a fight.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_rename_contact($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* mark_read <peer>
2016-07-14 15:15:50 +02:00
* mark read all received messages with peer.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_mark_read($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* delete_msg <msg-no>
2016-07-14 15:15:50 +02:00
* deletes message (not completly, though).
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_delete_msg($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* restore_msg <msg-no>
2016-07-14 15:15:50 +02:00
* restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_restore_msg($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* send_photo <peer> <photo-file-name>
2016-07-14 15:15:50 +02:00
* sends photo to peer.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_send_photo($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* send_video <peer> <video-file-name>
2016-07-14 15:15:50 +02:00
* sends video to peer.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_send_video($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* send_text <peer> <text-file-name>
2016-07-14 15:15:50 +02:00
* sends text file as plain messages.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_send_text($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* load_photo <msg-no>
2016-07-14 15:15:50 +02:00
* loads photo to download dir.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_load_photo($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* load_video <msg-no>
2016-07-14 15:15:50 +02:00
* loads video to download dir.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_load_video($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* load_video_thumb <msg-no>
2016-07-14 15:15:50 +02:00
* loads video thumbnail to download dir.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_load_video_thumb($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* load_audio <msg-no>
2016-07-14 15:15:50 +02:00
* loads audio to download dir.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_load_audio($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* load_document <msg-no>
2016-07-14 15:15:50 +02:00
* loads document to download dir.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_load_document($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* load_document_thumb <msg-no>
2016-07-14 15:15:50 +02:00
* loads document thumbnail to download dir.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_load_document_thumb($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* view_photo <msg-no>
2016-07-14 15:15:50 +02:00
* loads photo/video to download dir and starts system default viewer.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_view_photo($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
2016-07-14 15:15:50 +02:00
* view_video <msg-no>.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_view_video($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
2016-07-14 15:15:50 +02:00
* view_video_thumb <msg-no>.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_view_video_thumb($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
2016-07-14 15:15:50 +02:00
* view_audio <msg-no>.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_view_audio($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
2016-07-14 15:15:50 +02:00
* view_document <msg-no>.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_view_document($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
2016-07-14 15:15:50 +02:00
* view_document_thumb <msg-no>.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_view_document_thumb($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* fwd_media <msg-no>
2016-07-14 15:15:50 +02:00
* send media in your message. Use this to prevent sharing info about author of media (though, it is possible to determine user_id from media itself, it is not possible get access_hash of this user).
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_fwd_media($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* set_profile_photo <photo-file-name>
2016-07-14 15:15:50 +02:00
* sets userpic. Photo should be square, or server will cut biggest central square part.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_set_profile_photo($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* chat_info <chat>
2016-07-14 15:15:50 +02:00
* prints info about chat.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_chat_info($arg)
{
2016-06-23 23:51:08 +02:00
$arg = $arg->split();
if ((count($arg) == 1)) {
pyjslib_printnl(['chat_info called with ', $arg[0]]);
}
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* chat_add_user <chat> <user>
2016-07-14 15:15:50 +02:00
* add user to chat.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_chat_add_user($arg)
{
2016-06-23 23:51:08 +02:00
pyjslib_printnl($arg);
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* chat_del_user <chat> <user>
2016-07-14 15:15:50 +02:00
* remove user from chat.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_chat_del_user($arg)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* chat_rename <chat> <new-name>
2016-07-14 15:15:50 +02:00
* rename chat room.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_chat_rename($arg)
{
2016-06-23 23:51:08 +02:00
$arg = $arg->split();
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* create_group_chat <chat topic> <user1> <user2> <user3> ...
2016-07-14 15:15:50 +02:00
* creates a groupchat with users, use chat_add_user to add more users.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_create_group_chat($chat_topic, $user1, $user2, $user3)
{
2016-06-23 23:51:08 +02:00
pyjslib_printnl($chat_topic);
pyjslib_printnl([$user1, $user2, $user3]);
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* chat_set_photo <chat> <photo-file-name>
* sets group chat photo. Same limits as for profile photos.
*/
2016-07-14 15:15:50 +02:00
public function do_chat_set_photo($chat, $photo)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* search <peer> <pattern>
2016-07-14 15:15:50 +02:00
* searches pattern in messages with peer.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_search($pattern)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* global_search <pattern>
2016-07-14 15:15:50 +02:00
* searches pattern in all messages.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_global_search($pattern)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* create_secret_chat <user>
2016-07-14 15:15:50 +02:00
* creates secret chat with this user.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_create_secret_chat($user)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* visualize_key <secret_chat>
2016-07-14 15:15:50 +02:00
* prints visualization of encryption key. You should compare it to your partner's one.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_visualize_key($secret_chat)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* set_ttl <secret_chat> <ttl>
2016-07-14 15:15:50 +02:00
* sets ttl to secret chat. Though client does ignore it, client on other end can make use of it.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_set_ttl($secret_chat, $ttl)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* accept_secret_chat <secret_chat>
2016-07-14 15:15:50 +02:00
* manually accept secret chat (only useful when starting with -E key).
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_accept_secret_chat($secret_chat)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* user_info <user>
2016-07-14 15:15:50 +02:00
* prints info about user.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_user_info($user)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* history <peer> [limit]
2016-07-14 15:15:50 +02:00
* prints history (and marks it as read). Default limit = 40.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_history($peer, $limit = 40)
{
2016-06-23 23:51:08 +02:00
if (($peer == '')) {
pyjslib_printnl('no peer have specified');
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
return;
}
$args = $peer->split();
if (!in_array(count($args), [1, 2])) {
pyjslib_printnl(['not appropriate number of arguments : ', $peer]);
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
return;
}
if ((count($args) == 2)) {
if (!($args[1]->isdecimal()) || (pyjslib_int($args[1]) < 1)) {
pyjslib_printnl(['not a valid limit:', $args[1]]);
}
$limit = pyjslib_int($args[1]);
}
pyjslib_printnl($peer);
pyjslib_printnl($limit);
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* dialog_list
2016-07-14 15:15:50 +02:00
* prints info about your dialogs.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_dialog_list($ignored)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* contact_list
2016-07-14 15:15:50 +02:00
* prints info about users in your contact list.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_contact_list($ignored)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* suggested_contacts
2016-07-14 15:15:50 +02:00
* print info about contacts, you have max common friends.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_suggested_contacts($ignored)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* stats
2016-07-14 15:15:50 +02:00
* just for debugging.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_stats($ignored)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* export_card
2016-07-14 15:15:50 +02:00
* print your 'card' that anyone can later use to import your contact.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_export_card($card)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* import_card <card>
* gets user by card. You can write messages to him after that.
*/
2016-07-14 15:15:50 +02:00
public function do_import_card($card)
{
2016-06-23 23:51:08 +02:00
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* quit_force
2016-07-14 15:15:50 +02:00
* quit without waiting for query ends.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_quit_force($ignored)
{
2016-06-23 23:51:08 +02:00
return true;
}
2016-07-14 15:15:50 +02:00
2016-06-23 23:51:08 +02:00
/**
* quit
2016-07-14 15:15:50 +02:00
* wait for all queries to end then quit.
2016-06-23 23:51:08 +02:00
*/
2016-07-14 15:15:50 +02:00
public function do_quit($ignored)
{
2016-06-23 23:51:08 +02:00
return true;
}
}