MTPyroger/pyrogram/methods/auth/initialize.py

50 lines
1.7 KiB
Python
Raw Normal View History

2020-03-21 14:43:32 +00:00
# Pyrogram - Telegram MTProto API Client Library for Python
2021-01-01 21:58:48 +00:00
# Copyright (C) 2017-2021 Dan <https://github.com/delivrance>
2018-01-23 14:34:36 +00:00
#
2020-03-21 14:43:32 +00:00
# This file is part of Pyrogram.
2018-01-23 14:34:36 +00:00
#
2020-03-21 14:43:32 +00:00
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
2018-01-23 14:34:36 +00:00
#
2020-03-21 14:43:32 +00:00
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
2018-01-23 14:34:36 +00:00
#
2020-03-21 14:43:32 +00:00
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
2018-01-23 14:34:36 +00:00
import logging
2018-01-23 14:34:36 +00:00
from pyrogram.scaffold import Scaffold
from pyrogram.syncer import Syncer
2018-01-23 14:34:36 +00:00
log = logging.getLogger(__name__)
class Initialize(Scaffold):
async def initialize(self):
"""Initialize the client by starting up workers.
2018-05-12 09:31:09 +00:00
This method will start updates and download workers.
It will also load plugins and start the internal dispatcher.
2018-05-12 09:31:09 +00:00
Raises:
ConnectionError: In case you try to initialize a disconnected client or in case you try to initialize an
already initialized client.
2018-05-12 09:31:09 +00:00
"""
if not self.is_connected:
raise ConnectionError("Can't initialize a disconnected client")
if self.is_initialized:
raise ConnectionError("Client is already initialized")
self.load_plugins()
await self.dispatcher.start()
await Syncer.add(self)
self.is_initialized = True