mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 12:40:22 +03:00
Update interactive_telegram_client.py
Updated as per review
This commit is contained in:
parent
b5f273c753
commit
3cc5bef700
|
@ -5,7 +5,9 @@ from telethon.utils import get_display_name
|
||||||
|
|
||||||
from telethon import ConnectionMode, TelegramClient
|
from telethon import ConnectionMode, TelegramClient
|
||||||
from telethon.errors import SessionPasswordNeededError
|
from telethon.errors import SessionPasswordNeededError
|
||||||
from telethon.tl.types import (PeerChat, UpdateShortChatMessage, UpdateShortMessage)
|
from telethon.tl.types import (
|
||||||
|
PeerChat, UpdateShortChatMessage, UpdateShortMessage
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def sprint(string, *args, **kwargs):
|
def sprint(string, *args, **kwargs):
|
||||||
|
@ -13,8 +15,8 @@ def sprint(string, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
print(string, *args, **kwargs)
|
print(string, *args, **kwargs)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
string = string.encode('utf-8', errors='ignore') \
|
string = string.encode('utf-8', errors='ignore')\
|
||||||
.decode('ascii', errors='ignore')
|
.decode('ascii', errors='ignore')
|
||||||
print(string, *args, **kwargs)
|
print(string, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -182,15 +184,15 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
# Show some information
|
# Show some information
|
||||||
print_title('Chat with "{}"'.format(get_display_name(entity)))
|
print_title('Chat with "{}"'.format(get_display_name(entity)))
|
||||||
print('Available commands:')
|
print('Available commands:')
|
||||||
print(' !q: Quits the current chat.')
|
print(' !q: Quits the current chat.')
|
||||||
print(' !Q: Quits the current chat and exits.')
|
print(' !Q: Quits the current chat and exits.')
|
||||||
print(' !h: prints the latest messages (message History).')
|
print(' !h: prints the latest messages (message History).')
|
||||||
print(' !up <path>: Uploads and sends the Photo from path.')
|
print(' !up <path>: Uploads and sends the Photo from path.')
|
||||||
print(' !uf <path>: Uploads and sends the File from path.')
|
print(' !uf <path>: Uploads and sends the File from path.')
|
||||||
print(' !d <msg-id>: Deletes a message by its id')
|
print(' !d <msg-id>: Deletes a message by its id')
|
||||||
print(' !dm <msg-id>: Downloads the given message Media (if any).')
|
print(' !dm <msg-id>: Downloads the given message Media (if any).')
|
||||||
print(' !dp: Downloads the current dialog Profile picture.')
|
print(' !dp: Downloads the current dialog Profile picture.')
|
||||||
print(' !i: prints information about this chat..')
|
print(' !i: Prints information about this chat..')
|
||||||
print()
|
print()
|
||||||
|
|
||||||
# And start a while loop to chat
|
# And start a while loop to chat
|
||||||
|
@ -235,8 +237,7 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
|
|
||||||
# And print it to the user
|
# And print it to the user
|
||||||
sprint('[{}:{}] (ID={}) {}: {}'.format(
|
sprint('[{}:{}] (ID={}) {}: {}'.format(
|
||||||
msg.date.hour, msg.date.minute, msg.id, name,
|
msg.date.hour, msg.date.minute, msg.id, name, content))
|
||||||
content))
|
|
||||||
|
|
||||||
# Send photo
|
# Send photo
|
||||||
elif msg.startswith('!up '):
|
elif msg.startswith('!up '):
|
||||||
|
@ -286,7 +287,8 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
print("{:<{width}} : {}".format(
|
print("{:<{width}} : {}".format(
|
||||||
attr,
|
attr,
|
||||||
getattr(entity, attr, ''),
|
getattr(entity, attr, ''),
|
||||||
width=longest_attr))
|
width=longest_attr)
|
||||||
|
)
|
||||||
|
|
||||||
# Send chat message (if any)
|
# Send chat message (if any)
|
||||||
elif msg:
|
elif msg:
|
||||||
|
@ -374,6 +376,5 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
else:
|
else:
|
||||||
who = self.get_entity(update.from_id)
|
who = self.get_entity(update.from_id)
|
||||||
sprint('<< {} @ {} sent "{}"'.format(
|
sprint('<< {} @ {} sent "{}"'.format(
|
||||||
get_display_name(which), get_display_name(who),
|
get_display_name(which), get_display_name(who), update.message
|
||||||
update.message
|
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user