Fixed revert by hand (I hope)

This commit is contained in:
Lonami
2016-09-26 13:13:11 +02:00
parent 4d5e11f4af
commit 36b8a9026f
4 changed files with 28 additions and 65 deletions

View File

@@ -192,6 +192,16 @@ class MtProtoSender:
if code == 0xa7eff811: # bad_msg_notification
return self.handle_bad_msg_notification(msg_id, sequence, reader)
if code == 0x62d6b459: # msgs_ack, it may handle the request we wanted
ack = reader.tgread_object()
for message_id in ack.msg_ids:
if message_id in self.need_confirmation:
self.need_confirmation.remove(message_id)
if request and request.msg_id in ack.msg_ids:
request.confirm_received = True
return False
# If the code is not parsed manually, then it was parsed by the code generator!
# In this case, we will simply treat the incoming TLObject as an Update,
# if we can first find a matching TLObject

View File

@@ -1,7 +1,7 @@
import platform
from datetime import datetime
from hashlib import md5
from os import path
from os import path, listdir
from mimetypes import guess_extension, guess_type
# For sending and receiving requests
@@ -35,7 +35,7 @@ from telethon.tl.all_tlobjects import layer
class TelegramClient:
# Current TelegramClient version
__version__ = '0.5'
__version__ = '0.6'
# region Initialization
@@ -182,8 +182,7 @@ class TelegramClient:
def log_out(self):
"""Logs out and deletes the current session. Returns True if everything went OK"""
try:
# This request is a bit special. Nothing is received after
self.sender.send(LogOutRequest())
self.invoke(LogOutRequest())
if not self.session.delete():
return False
@@ -191,6 +190,13 @@ class TelegramClient:
except:
return False
@staticmethod
def list_sessions():
"""Lists all the sessions of the users who have ever connected
using this client and never logged out"""
return [path.splitext(path.basename(f))[0] # splitext = split ext (not spli text!)
for f in listdir('.') if f.endswith('.session')]
# endregion
# region Dialogs ("chats") requests

View File

@@ -117,8 +117,14 @@ class BinaryReader:
# If there was still no luck, give up
raise TypeNotFoundError(constructor_id)
# Create an empty instance of the class, and read its values
result = clazz.empty()
# Now we need to determine the number of parameters of the class, so we can
# instantiate it with all of them set to None, and still, no need to write
# the default =None in all the classes, thus forcing the user to provide a real value
sig = inspect.signature(clazz.__init__)
params = [None] * (len(sig.parameters) - 1) # Subtract 1 (self)
result = clazz(*params) # https://docs.python.org/3/tutorial/controlflow.html#unpacking-argument-lists
# Finally, read the object and return the result
result.on_response(self)
return result