help description fully filled.
external shell cmd support added.
This commit is contained in:
parent
31313ceabf
commit
51c9fc4301
380
telepy.py
380
telepy.py
@ -1,6 +1,6 @@
|
|||||||
#CLI like interface
|
#CLI like interface
|
||||||
|
|
||||||
import argparse, getopt, cmd
|
import argparse, getopt, cmd, os
|
||||||
|
|
||||||
parser = argparse.ArgumentParser('telepy',description='Python implementation of telegram API.')
|
parser = argparse.ArgumentParser('telepy',description='Python implementation of telegram API.')
|
||||||
parser.add_argument('command', nargs='?', choices=['cmd', 'dialog_list', 'contact_list'] + ['chat_' + sub for sub in ['info', 'add_user', 'add_user_to_chat', 'del_user', 'set_photo', 'rename']])
|
parser.add_argument('command', nargs='?', choices=['cmd', 'dialog_list', 'contact_list'] + ['chat_' + sub for sub in ['info', 'add_user', 'add_user_to_chat', 'del_user', 'set_photo', 'rename']])
|
||||||
@ -16,114 +16,332 @@ print(args)
|
|||||||
class telepyShell(cmd.Cmd):
|
class telepyShell(cmd.Cmd):
|
||||||
intro='Welcome to telepy interactive shell. Type help or ? for help.\n'
|
intro='Welcome to telepy interactive shell. Type help or ? for help.\n'
|
||||||
prompt='>'
|
prompt='>'
|
||||||
|
|
||||||
def precmd(self, line):
|
def precmd(self, line):
|
||||||
# if len(line) < 1 : return None
|
# if len(line) < 1 : return None
|
||||||
# lines = line.split()
|
# lines = line.split()
|
||||||
# cmd_name = lines[0].lower()
|
# cmd_name = lines[0].lower()
|
||||||
return line
|
return line
|
||||||
|
def completedefault(self, *ignored):
|
||||||
|
print(ignored)
|
||||||
|
def complete(self, text, state):
|
||||||
|
super().complete(text, state)
|
||||||
|
print('completing')
|
||||||
|
|
||||||
|
def do_shell(self, line):
|
||||||
|
'''
|
||||||
|
shell <command-line>
|
||||||
|
lets you use external shell. !<command-line> for short-hand.
|
||||||
|
'''
|
||||||
|
print(os.popen(line).read())
|
||||||
#detailed commands
|
#detailed commands
|
||||||
def do_msg(self, arg): pass
|
def do_msg(self, arg):
|
||||||
def do_fwd(self, arg): pass
|
'''
|
||||||
def do_chat_with_peer(self, arg): pass
|
msg <peer>
|
||||||
def do_add_contact(self, arg): pass
|
sends message to this peer
|
||||||
def do_rename_contact(self, arg): pass
|
'''
|
||||||
def do_mark_read(self, arg): pass
|
pass
|
||||||
def do_delete_msg(self, arg): pass
|
def do_fwd(self, arg):
|
||||||
def do_restore_msg(self, arg): pass
|
'''
|
||||||
|
fwd <user> <msg-no>
|
||||||
|
forward message to user. You can see message numbers starting client with -N
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_chat_with_peer(self, arg):
|
||||||
|
'''
|
||||||
|
chat_with_peer <peer>
|
||||||
|
starts one on one chat session with this peer. /exit or /quit to end this mode.
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_add_contact(self, arg):
|
||||||
|
'''
|
||||||
|
add_contact <phone-number> <first-name> <last-name>
|
||||||
|
tries to add contact to contact-list by phone
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_rename_contact(self, arg):
|
||||||
|
'''
|
||||||
|
rename_contact <user> <first-name> <last-name>
|
||||||
|
tries to rename contact. If you have another device it will be a fight
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_mark_read(self, arg):
|
||||||
|
'''
|
||||||
|
mark_read <peer>
|
||||||
|
mark read all received messages with peer
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_delete_msg(self, arg):
|
||||||
|
'''
|
||||||
|
delete_msg <msg-no>
|
||||||
|
deletes message (not completly, though)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_restore_msg(self, arg):
|
||||||
|
'''
|
||||||
|
restore_msg <msg-no>
|
||||||
|
restores delete message. Impossible for secret chats. Only possible short time (one hour, I think) after deletion
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_send_photo(self, arg): pass
|
def do_send_photo(self, arg):
|
||||||
def do_send_video(self, arg): pass
|
'''
|
||||||
def do_send_text(self, arg): pass
|
send_photo <peer> <photo-file-name>
|
||||||
|
sends photo to peer
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_load_photo(self, arg): pass
|
def do_send_video(self, arg):
|
||||||
def do_load_video(self, arg): pass
|
'''
|
||||||
def do_load_video_thumb(self, arg): pass
|
send_video <peer> <video-file-name>
|
||||||
def do_load_audio(self, arg): pass
|
sends video to peer
|
||||||
def do_load_document(self, arg): pass
|
'''
|
||||||
def do_load_document_thumb(self, arg): pass
|
pass
|
||||||
|
def do_send_text(self, arg):
|
||||||
|
'''
|
||||||
|
send_text <peer> <text-file-name>
|
||||||
|
sends text file as plain messages
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_view_photo(self, arg): pass
|
def do_load_photo(self, arg):
|
||||||
def do_view_video(self, arg): pass
|
'''
|
||||||
def do_view_video_thumb(self, arg): pass
|
load_photo <msg-no>
|
||||||
def do_view_audio(self, arg): pass
|
loads photo to download dir
|
||||||
def do_view_document(self, arg): pass
|
'''
|
||||||
def do_view_document_thumb(self, arg): pass
|
pass
|
||||||
|
|
||||||
def do_fwd_media(self, arg): pass
|
def do_load_video(self, arg):
|
||||||
def do_set_profile_photo(self, arg): pass
|
'''
|
||||||
|
load_video <msg-no>
|
||||||
|
loads video to download dir
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_load_video_thumb(self, arg):
|
||||||
|
'''
|
||||||
|
load_video_thumb <msg-no>
|
||||||
|
loads video thumbnail to download dir
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_load_audio(self, arg):
|
||||||
|
'''
|
||||||
|
load_audio <msg-no>
|
||||||
|
loads audio to download dir
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_load_document(self, arg):
|
||||||
|
'''
|
||||||
|
load_document <msg-no>
|
||||||
|
loads document to download dir
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_load_document_thumb(self, arg):
|
||||||
|
'''
|
||||||
|
load_document_thumb <msg-no>
|
||||||
|
loads document thumbnail to download dir
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_view_photo(self, arg):
|
||||||
|
'''
|
||||||
|
view_photo <msg-no>
|
||||||
|
loads photo/video to download dir and starts system default viewer
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_view_video(self, arg):
|
||||||
|
'''
|
||||||
|
view_video <msg-no>
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_view_video_thumb(self, arg):
|
||||||
|
'''
|
||||||
|
view_video_thumb <msg-no>
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_view_audio(self, arg):
|
||||||
|
'''
|
||||||
|
view_audio <msg-no>
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_view_document(self, arg):
|
||||||
|
'''
|
||||||
|
view_document <msg-no>
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_view_document_thumb(self, arg):
|
||||||
|
'''
|
||||||
|
view_document_thumb <msg-no>
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_fwd_media(self, arg):
|
||||||
|
'''
|
||||||
|
fwd_media <msg-no>
|
||||||
|
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)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_set_profile_photo(self, arg):
|
||||||
|
'''
|
||||||
|
set_profile_photo <photo-file-name>
|
||||||
|
sets userpic. Photo should be square, or server will cut biggest central square part
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_chat_info(self, arg):
|
def do_chat_info(self, arg):
|
||||||
|
'''
|
||||||
|
chat_info <chat>
|
||||||
|
prints info about chat
|
||||||
|
'''
|
||||||
arg=arg.split()
|
arg=arg.split()
|
||||||
if len(arg) is 1:
|
if len(arg) is 1:
|
||||||
print ('chat_info called with ', arg[0])
|
print ('chat_info called with ', arg[0])
|
||||||
def do_chat_add_user(self,arg):
|
def do_chat_add_user(self,arg):
|
||||||
|
'''
|
||||||
|
chat_add_user <chat> <user>
|
||||||
|
add user to chat
|
||||||
|
'''
|
||||||
print(arg)
|
print(arg)
|
||||||
def do_chat_del_user(self,arg): pass
|
def do_chat_del_user(self,arg):
|
||||||
|
'''
|
||||||
|
chat_del_user <chat> <user>
|
||||||
|
remove user from chat
|
||||||
|
'''
|
||||||
|
pass
|
||||||
def do_chat_rename(self,arg):
|
def do_chat_rename(self,arg):
|
||||||
|
'''
|
||||||
|
chat_rename <chat> <new-name>
|
||||||
|
rename chat room
|
||||||
|
'''
|
||||||
arg=arg.split()
|
arg=arg.split()
|
||||||
|
|
||||||
def do_create_group_chat(self,arg): pass
|
def do_create_group_chat(self, chat_topic, user1, user2, user3):
|
||||||
def do_chat_set_photo(self,arg): pass
|
'''
|
||||||
|
create_group_chat <chat topic> <user1> <user2> <user3> ...
|
||||||
|
creates a groupchat with users, use chat_add_user to add more users
|
||||||
|
'''
|
||||||
|
print(chat_topic)
|
||||||
|
print(user1,user2,user3)
|
||||||
|
|
||||||
def do_search(self,arg): pass
|
pass
|
||||||
def do_global_search(self,arg): pass
|
def do_chat_set_photo(self, chat, photo):
|
||||||
|
'''
|
||||||
|
chat_set_photo <chat> <photo-file-name>
|
||||||
|
sets group chat photo. Same limits as for profile photos.
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_create_secret_chat(self,arg): pass
|
def do_search(self, pattern):
|
||||||
def do_visualize_key(self,arg): pass
|
'''
|
||||||
def do_set_ttl(self,arg): pass
|
search <peer> <pattern>
|
||||||
def do_accept_secret_chat(self,arg): pass
|
searches pattern in messages with peer
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_global_search(self, pattern):
|
||||||
|
'''
|
||||||
|
global_search <pattern>
|
||||||
|
searches pattern in all messages
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_user_info(self,arg): pass
|
def do_create_secret_chat(self, user):
|
||||||
def do_history(self,arg): pass
|
'''
|
||||||
def do_dialog_list(self,arg): pass
|
create_secret_chat <user>
|
||||||
def do_contact_list(self,arg): pass
|
creates secret chat with this user
|
||||||
def do_suggested_contacts(self,arg): pass
|
'''
|
||||||
def do_stats(self,arg): pass
|
pass
|
||||||
|
def do_visualize_key(self, secret_chat):
|
||||||
|
'''
|
||||||
|
visualize_key <secret_chat>
|
||||||
|
prints visualization of encryption key. You should compare it to your partner's one
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_set_ttl(self, secret_chat, ttl):
|
||||||
|
'''
|
||||||
|
set_ttl <secret_chat> <ttl>
|
||||||
|
sets ttl to secret chat. Though client does ignore it, client on other end can make use of it
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_accept_secret_chat(self, secret_chat):
|
||||||
|
'''
|
||||||
|
accept_secret_chat <secret_chat>
|
||||||
|
manually accept secret chat (only useful when starting with -E key)
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_export_card(self,arg): pass
|
def do_user_info(self, user):
|
||||||
def do_import_card(self,arg): pass
|
'''
|
||||||
|
user_info <user>
|
||||||
|
prints info about user
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_history(self, peer, limit=40):
|
||||||
|
'''
|
||||||
|
history <peer> [limit]
|
||||||
|
prints history (and marks it as read). Default limit = 40
|
||||||
|
'''
|
||||||
|
if peer is '':
|
||||||
|
print('no peer have specified')
|
||||||
|
return
|
||||||
|
args = peer.split()
|
||||||
|
if len(args) not in (1,2) :
|
||||||
|
print('not appropriate number of arguments : ', peer)
|
||||||
|
return
|
||||||
|
if len(args) is 2:
|
||||||
|
if not args[1].isdecimal() or int(args[1]) < 1:
|
||||||
|
print('not a valid limit:', args[1])
|
||||||
|
limit = int(args[1])
|
||||||
|
print(peer)
|
||||||
|
print(limit)
|
||||||
|
def do_dialog_list(self, ignored):
|
||||||
|
'''
|
||||||
|
dialog_list
|
||||||
|
prints info about your dialogs
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_contact_list(self, ignored):
|
||||||
|
'''
|
||||||
|
contact_list
|
||||||
|
prints info about users in your contact list
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_suggested_contacts(self, ignored):
|
||||||
|
'''
|
||||||
|
suggested_contacts
|
||||||
|
print info about contacts, you have max common friends
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_stats(self, ignored):
|
||||||
|
'''
|
||||||
|
stats
|
||||||
|
just for debugging
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
def do_quit_force(self,arg):
|
def do_export_card(self, card):
|
||||||
|
'''
|
||||||
|
export_card
|
||||||
|
print your 'card' that anyone can later use to import your contact
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
def do_import_card(self, card):
|
||||||
|
'''
|
||||||
|
import_card <card>
|
||||||
|
gets user by card. You can write messages to him after that.
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def do_quit_force(self, ignored):
|
||||||
|
'''
|
||||||
|
quit_force
|
||||||
|
quit without waiting for query ends
|
||||||
|
'''
|
||||||
return True
|
return True
|
||||||
def do_quit(self, arg):
|
def do_quit(self, ignored):
|
||||||
|
'''
|
||||||
|
quit
|
||||||
|
wait for all queries to end then quit
|
||||||
|
'''
|
||||||
#TODO:safely end queries
|
#TODO:safely end queries
|
||||||
return True
|
return True
|
||||||
if args.command is None:
|
if args.command is None:
|
||||||
telepyShell().cmdloop()
|
telepyShell().cmdloop()
|
||||||
|
|
||||||
# chat_info <chat> -
|
|
||||||
# chat_add_user <chat> <user> -
|
|
||||||
# chat_del_user <chat> <user> -
|
|
||||||
# chat_set_photo <chat> <photo-file-name> -
|
|
||||||
# rename_chat <chat> <new-name>
|
|
||||||
# create_group_chat <chat topic> <user1> <user2> <user3> ... - creates a groupchat with users, use chat_add_user to add more users
|
|
||||||
# Search
|
|
||||||
#
|
|
||||||
# search <peer> pattern - searches pattern in messages with peer
|
|
||||||
# global_search pattern - searches pattern in all messages
|
|
||||||
# Secret chat
|
|
||||||
#
|
|
||||||
# create_secret_chat <user> - creates secret chat with this user
|
|
||||||
# visualize_key <secret_chat> - prints visualization of encryption key. You should compare it to your partner's one
|
|
||||||
# set_ttl <secret_chat> <ttl> - sets ttl to secret chat. Though client does ignore it, client on other end can make use of it
|
|
||||||
# accept_secret_chat <secret_chat> - manually accept secret chat (only useful when starting with -E key)
|
|
||||||
# Stats and various info
|
|
||||||
#
|
|
||||||
# user_info <user> - prints info about user
|
|
||||||
# history <peer> [limit] - prints history (and marks it as read). Default limit = 40
|
|
||||||
# dialog_list - prints info about your dialogs
|
|
||||||
# contact_list - prints info about users in your contact list
|
|
||||||
# suggested_contacts - print info about contacts, you have max common friends
|
|
||||||
# stats - just for debugging
|
|
||||||
# show_license - prints contents of GPLv2
|
|
||||||
# help - prints this help
|
|
||||||
# Card
|
|
||||||
#
|
|
||||||
# export_card - print your 'card' that anyone can later use to import your contact
|
|
||||||
# import_card <card> - gets user by card. You can write messages to him after that.
|
|
||||||
# Other
|
|
||||||
#
|
|
||||||
# quit - quit
|
|
||||||
# safe_quit - wait for all queries to end then quit
|
|
Loading…
Reference in New Issue
Block a user