mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-05 20:50:22 +03:00
Added !i for information to interactive telegram client
This commit is contained in:
parent
3c6f34fe6a
commit
b5f273c753
|
@ -1,20 +1,19 @@
|
||||||
import os
|
import os
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
|
||||||
from telethon import TelegramClient, ConnectionMode
|
|
||||||
from telethon.errors import SessionPasswordNeededError
|
|
||||||
from telethon.tl.types import (
|
|
||||||
UpdateShortChatMessage, UpdateShortMessage, PeerChat
|
|
||||||
)
|
|
||||||
from telethon.utils import get_display_name
|
from telethon.utils import get_display_name
|
||||||
|
|
||||||
|
from telethon import ConnectionMode, TelegramClient
|
||||||
|
from telethon.errors import SessionPasswordNeededError
|
||||||
|
from telethon.tl.types import (PeerChat, UpdateShortChatMessage, UpdateShortMessage)
|
||||||
|
|
||||||
|
|
||||||
def sprint(string, *args, **kwargs):
|
def sprint(string, *args, **kwargs):
|
||||||
"""Safe Print (handle UnicodeEncodeErrors on some terminals)"""
|
"""Safe Print (handle UnicodeEncodeErrors on some terminals)"""
|
||||||
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)
|
||||||
|
|
||||||
|
@ -47,6 +46,7 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
Telegram through Telethon, such as listing dialogs (open chats),
|
Telegram through Telethon, such as listing dialogs (open chats),
|
||||||
talking to people, downloading media, and receiving updates.
|
talking to people, downloading media, and receiving updates.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, session_user_id, user_phone, api_id, api_hash,
|
def __init__(self, session_user_id, user_phone, api_id, api_hash,
|
||||||
proxy=None):
|
proxy=None):
|
||||||
"""
|
"""
|
||||||
|
@ -190,6 +190,7 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
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()
|
print()
|
||||||
|
|
||||||
# And start a while loop to chat
|
# And start a while loop to chat
|
||||||
|
@ -270,6 +271,23 @@ class InteractiveTelegramClient(TelegramClient):
|
||||||
else:
|
else:
|
||||||
print('No profile picture found for this user!')
|
print('No profile picture found for this user!')
|
||||||
|
|
||||||
|
elif msg == '!i':
|
||||||
|
blacklist_attrs = ['from_reader', 'on_response', 'pretty_format', 'resolve', 'rpc_error',
|
||||||
|
'serialize_bytes', 'serialize_datetime', 'stringify', 'to_dict',
|
||||||
|
'constructor_id', 'subclass_of_id', 'confirm_received', 'result']
|
||||||
|
interesting_attributes = [
|
||||||
|
x for x in dir(entity)
|
||||||
|
if x.lower() not in blacklist_attrs and not (x.startswith('_') or x.startswith('__'))
|
||||||
|
]
|
||||||
|
|
||||||
|
longest_attr = max(len(x) for x in interesting_attributes)
|
||||||
|
|
||||||
|
for attr in interesting_attributes:
|
||||||
|
print("{:<{width}} : {}".format(
|
||||||
|
attr,
|
||||||
|
getattr(entity, attr, ''),
|
||||||
|
width=longest_attr))
|
||||||
|
|
||||||
# Send chat message (if any)
|
# Send chat message (if any)
|
||||||
elif msg:
|
elif msg:
|
||||||
self.send_message(entity, msg, link_preview=False)
|
self.send_message(entity, msg, link_preview=False)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user