mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 01:16:35 +03:00
Get rid of signature warnings and use nicer *args instead
This commit is contained in:
parent
b760f0de50
commit
cf65e5b1cf
|
@ -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')
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue
Block a user