From cf65e5b1cf2c1a78b31b73d99ab1925d8876bfb3 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Thu, 8 Jun 2017 16:59:47 +0200 Subject: [PATCH] Get rid of signature warnings and use nicer *args instead --- telethon/telegram_client.py | 30 ++++++++++++---- telethon_examples/auto_replier.py | 60 ------------------------------- 2 files changed, 23 insertions(+), 67 deletions(-) delete mode 100644 telethon_examples/auto_replier.py diff --git a/telethon/telegram_client.py b/telethon/telegram_client.py index 18839553..55f69f33 100644 --- a/telethon/telegram_client.py +++ b/telethon/telegram_client.py @@ -125,13 +125,20 @@ class TelegramClient(TelegramBareClient): # region Connecting - def connect(self, a=None, b=None, c=None, d=None): - # TODO Use **kwargs instead 4 dummy parameters + def connect(self, *args): + """Connects to the Telegram servers, executing authentication if + required. Note that authenticating to the Telegram servers is + not the same as authenticating the desired user itself, which + may require a call (or several) to 'sign_in' for the first time. + + *args will be ignored. + """ return super(TelegramClient, self).connect( device_model=self.device_model, system_version=self.system_version, app_version=self.app_version, - lang_code=self.lang_code) + lang_code=self.lang_code + ) def disconnect(self): """Disconnects from the Telegram server @@ -146,14 +153,21 @@ class TelegramClient(TelegramBareClient): self._cached_senders.clear() self._cached_sessions.clear() - def reconnect(self, new_dc=None, a=None, b=None, c=None, d=None): - # TODO Use **kwargs instead 4 dummy parameters + def reconnect(self, new_dc=None, *args): + """Disconnects and connects again (effectively reconnecting). + + If 'new_dc' is not None, the current authorization key is + removed, the DC used is switched, and a new connection is made. + + *args will be ignored. + """ super(TelegramClient, self).reconnect( device_model=self.device_model, system_version=self.system_version, app_version=self.app_version, lang_code=self.lang_code, - new_dc=new_dc) + new_dc=new_dc + ) # endregion @@ -227,11 +241,13 @@ class TelegramClient(TelegramBareClient): # region Telegram requests functions - def invoke(self, request, timeout=timedelta(seconds=5)): + def invoke(self, request, timeout=timedelta(seconds=5), *args): """Invokes (sends) a MTProtoRequest and returns (receives) its result. An optional timeout can be specified to cancel the operation if no result is received within such time, or None to disable any timeout. + + *args will be ignored. """ if not issubclass(type(request), MTProtoRequest): raise ValueError('You can only invoke MtProtoRequests') diff --git a/telethon_examples/auto_replier.py b/telethon_examples/auto_replier.py deleted file mode 100644 index 7c1d24eb..00000000 --- a/telethon_examples/auto_replier.py +++ /dev/null @@ -1,60 +0,0 @@ -# Example demonstrating how to make an automatic replier -from telethon import TelegramClient -from telethon.tl.types import UpdateShortMessage, UpdateShortChatMessage - -from time import sleep - - -def get_config(): - """Returns (session_name, user_phone, api_id, api_hash)""" - result = {} - with open('../api/settings', 'r', encoding='utf-8') as file: - for line in file: - value_pair = line.split('=') - left = value_pair[0].strip() - right = value_pair[1].strip() - result[left] = right - - return ( - '../' + result.get('session_name', 'anonymous'), - result.get('user_phone'), - int(result.get('api_id')), - result.get('api_hash') - ) - - -# Connection -user_id, user_phone, api_id, api_hash = get_config() -client = TelegramClient('session_id', api_id, api_hash) -client.connect() - -if not client.is_user_authorized(): - client.send_code_request(user_phone) - client.sign_in('+34600000000', input('Enter code: ')) - -number_of_auto_replies = int(input('Auto-reply how many times?: ')) - - -# Real work here -def auto_reply_thread(update_object): - print(type(update_object), update_object) - return -''' -if isinstance(update_object, UpdateShortMessage): - if not update_object.out: - client.send_message() - - print('[User #{} sent {}]'.format( - update_object.user_id, update_object.message)) - -elif isinstance(update_object, UpdateShortChatMessage): - if not update_object.out: - print('[Chat #{}, user #{} sent {}]'.format( - update_object.chat_id, update_object.from_id, - update_object.message)) -''' - -client.add_update_handler(auto_reply_thread) -while number_of_auto_replies > 0: - # A real application would do more work here - sleep(1) \ No newline at end of file