mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-02-03 13:14:31 +03:00
Fix file uploads and references to full_name
This commit is contained in:
parent
0727c1d1f1
commit
34dffe978e
|
@ -402,7 +402,7 @@ In Telethon:
|
|||
|
||||
@client.on(events.NewMessage, Command("/start"))
|
||||
async def command_start_handler(message: Message) -> None:
|
||||
await message.respond(html=f"Hello, <b>{html.escape(message.sender.full_name)}</b>!")
|
||||
await message.respond(html=f"Hello, <b>{html.escape(message.sender.name)}</b>!")
|
||||
|
||||
@dp.message()
|
||||
async def echo_handler(message: types.Message) -> None:
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
async def main():
|
||||
async with Client('name', api_id, api_hash) as client:
|
||||
me = await client.interactive_login()
|
||||
await client.send_message(me, f'Hello, {me.full_name}!')
|
||||
await client.send_message(me, f'Hello, {me.name}!')
|
||||
|
||||
@client.on(events.NewMessage, filters.Text(r'(?i)hello'))
|
||||
async def handler(event):
|
||||
|
|
|
@ -147,7 +147,7 @@ async def interactive_login(
|
|||
if re.match(r"\d+:", phone_or_token):
|
||||
user = await self.bot_sign_in(phone_or_token)
|
||||
try:
|
||||
print("Signed in as bot:", user.full_name)
|
||||
print("Signed in as bot:", user.name)
|
||||
except UnicodeEncodeError:
|
||||
print("Signed in as bot")
|
||||
|
||||
|
@ -188,7 +188,7 @@ async def interactive_login(
|
|||
user = user_or_token
|
||||
|
||||
try:
|
||||
print("Signed in as user:", user.full_name)
|
||||
print("Signed in as user:", user.name)
|
||||
except UnicodeEncodeError:
|
||||
print("Signed in as user")
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ class Client:
|
|||
.. code-block:: python
|
||||
|
||||
async def my_print_handler(event):
|
||||
print(event.chat.full_name, event.text)
|
||||
print(event.chat.name, event.text)
|
||||
|
||||
# Register a handler to be called on new messages
|
||||
client.add_event_handler(my_print_handler, events.NewMessage)
|
||||
|
@ -395,7 +395,7 @@ class Client:
|
|||
.. code-block:: python
|
||||
|
||||
async for dialog in client.iter_dialogs():
|
||||
if 'dog pictures' in dialog.chat.full_name:
|
||||
if 'dog pictures' in dialog.chat.name:
|
||||
# You've realized you're more of a cat person
|
||||
await client.delete_dialog(dialog.chat)
|
||||
"""
|
||||
|
@ -609,7 +609,7 @@ class Client:
|
|||
.. code-block:: python
|
||||
|
||||
async for user in client.get_contacts():
|
||||
print(user.full_name, user.id)
|
||||
print(user.name, user.id)
|
||||
"""
|
||||
return get_contacts(self)
|
||||
|
||||
|
@ -629,7 +629,7 @@ class Client:
|
|||
|
||||
async for dialog in client.get_dialogs():
|
||||
print(
|
||||
dialog.chat.full_name,
|
||||
dialog.chat.name,
|
||||
dialog.last_message.text if dialog.last_message else ''
|
||||
)
|
||||
"""
|
||||
|
@ -719,7 +719,7 @@ class Client:
|
|||
if me.bot:
|
||||
print('I am a bot')
|
||||
|
||||
print('My name is', me.full_name)
|
||||
print('My name is', me.name)
|
||||
|
||||
if me.phone:
|
||||
print('My phone number is', me.phone)
|
||||
|
@ -764,7 +764,7 @@ class Client:
|
|||
from datetime import datetime
|
||||
|
||||
async for message in client.get_messages(chat, offset_date=datetime(2023, 1, 1)):
|
||||
print(message.sender.full_name, ':', message.html_text)
|
||||
print(message.sender.name, ':', message.html_text)
|
||||
"""
|
||||
return get_messages(
|
||||
self, chat, limit, offset_id=offset_id, offset_date=offset_date
|
||||
|
@ -814,7 +814,7 @@ class Client:
|
|||
.. code-block:: python
|
||||
|
||||
async for participant in client.get_participants(chat):
|
||||
print(participant.user.full_name)
|
||||
print(participant.user.name)
|
||||
"""
|
||||
return get_participants(self, chat)
|
||||
|
||||
|
@ -897,7 +897,7 @@ class Client:
|
|||
.. code-block:: python
|
||||
|
||||
me = await client.interactive_login()
|
||||
print('Logged in as:', me.full_name)
|
||||
print('Logged in as:', me.name)
|
||||
|
||||
# or, to make sure you're logged-in as a bot
|
||||
await client.interactive_login('1234:ab56cd78ef90)
|
||||
|
@ -950,14 +950,14 @@ class Client:
|
|||
# Register a handler to be called on new messages
|
||||
@client.on(events.NewMessage)
|
||||
async def my_print_handler(event):
|
||||
print(event.chat.full_name, event.text)
|
||||
print(event.chat.name, event.text)
|
||||
|
||||
# Register a handler to be called on new messages if they contain "hello" or "/start"
|
||||
from telethon.events.filters import Any, Text, Command
|
||||
|
||||
@client.on(events.NewMessage, Any(Text(r'hello'), Command('/start')))
|
||||
async def my_other_print_handler(event):
|
||||
print(event.chat.full_name, event.text)
|
||||
print(event.chat.name, event.text)
|
||||
|
||||
.. seealso::
|
||||
|
||||
|
|
|
@ -311,7 +311,7 @@ async def upload(
|
|||
) -> abcs.InputFile:
|
||||
file_id = generate_random_id()
|
||||
|
||||
uploaded = 0
|
||||
offset = 0
|
||||
part = 0
|
||||
total_parts = (size + MAX_CHUNK_SIZE - 1) // MAX_CHUNK_SIZE
|
||||
buffer = bytearray()
|
||||
|
@ -319,18 +319,19 @@ async def upload(
|
|||
hash_md5 = hashlib.md5()
|
||||
is_big = size > BIG_FILE_SIZE
|
||||
|
||||
while uploaded != size:
|
||||
while offset != size:
|
||||
ret = fd.read(MAX_CHUNK_SIZE - len(buffer))
|
||||
chunk = await ret if isawaitable(ret) else ret
|
||||
assert isinstance(chunk, bytes)
|
||||
if not chunk:
|
||||
raise ValueError("unexpected end-of-file")
|
||||
|
||||
if len(chunk) == MAX_CHUNK_SIZE or uploaded + len(chunk) == size:
|
||||
offset += len(chunk)
|
||||
if not buffer and (offset == size or len(chunk) == MAX_CHUNK_SIZE):
|
||||
to_store = chunk
|
||||
else:
|
||||
buffer += chunk
|
||||
if len(buffer) == MAX_CHUNK_SIZE:
|
||||
if offset == size or len(buffer) == MAX_CHUNK_SIZE:
|
||||
to_store = buffer
|
||||
else:
|
||||
continue
|
||||
|
@ -340,14 +341,14 @@ async def upload(
|
|||
functions.upload.save_big_file_part(
|
||||
file_id=file_id,
|
||||
file_part=part,
|
||||
file_total_parts=part,
|
||||
file_total_parts=total_parts,
|
||||
bytes=to_store,
|
||||
)
|
||||
)
|
||||
else:
|
||||
await client(
|
||||
functions.upload.save_file_part(
|
||||
file_id=file_id, file_part=total_parts, bytes=to_store
|
||||
file_id=file_id, file_part=part, bytes=to_store
|
||||
)
|
||||
)
|
||||
hash_md5.update(to_store)
|
||||
|
|
|
@ -196,7 +196,6 @@ class Encrypted(Mtp):
|
|||
self._msg_count,
|
||||
)
|
||||
|
||||
print("packed", self._msg_count)
|
||||
self._msg_count = 0
|
||||
result = bytes(self._buffer)
|
||||
self._buffer.clear()
|
||||
|
|
Loading…
Reference in New Issue
Block a user