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-05-07 12:30:55 +00:00
|
|
|
#
|
2020-03-21 14:43:32 +00:00
|
|
|
# This file is part of Pyrogram.
|
2018-05-07 12:30:55 +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-05-07 12:30:55 +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-05-07 12:30:55 +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-05-07 12:30:55 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
import asyncio
|
2019-04-20 15:59:42 +00:00
|
|
|
import os
|
2018-06-24 16:26:11 +00:00
|
|
|
import platform
|
2018-05-07 12:30:55 +00:00
|
|
|
import re
|
2019-06-15 21:02:31 +00:00
|
|
|
import sys
|
2020-12-20 17:28:21 +00:00
|
|
|
from io import StringIO
|
2020-12-20 16:58:35 +00:00
|
|
|
from mimetypes import MimeTypes
|
2019-06-15 21:02:31 +00:00
|
|
|
from pathlib import Path
|
2018-05-07 12:30:55 +00:00
|
|
|
|
2020-08-30 22:17:33 +00:00
|
|
|
import pyrogram
|
2018-06-24 16:26:11 +00:00
|
|
|
from pyrogram import __version__
|
2020-08-22 06:05:05 +00:00
|
|
|
from pyrogram.parser import Parser
|
|
|
|
from pyrogram.session.internals import MsgId
|
2020-12-20 17:28:21 +00:00
|
|
|
from .mime_types import mime_types
|
2018-05-07 12:30:55 +00:00
|
|
|
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
class Scaffold:
|
|
|
|
APP_VERSION = f"Pyrogram {__version__}"
|
|
|
|
DEVICE_MODEL = f"{platform.python_implementation()} {platform.python_version()}"
|
|
|
|
SYSTEM_VERSION = f"{platform.system()} {platform.release()}"
|
2018-06-24 16:26:11 +00:00
|
|
|
|
|
|
|
LANG_CODE = "en"
|
|
|
|
|
2019-06-15 21:02:31 +00:00
|
|
|
PARENT_DIR = Path(sys.argv[0]).parent
|
|
|
|
|
2021-03-20 12:16:55 +00:00
|
|
|
INVITE_LINK_RE = re.compile(r"^(?:https?://)?(?:www\.)?(?:t(?:elegram)?\.(?:org|me|dog)/joinchat/)([\w-]+)$")
|
2020-08-22 06:05:05 +00:00
|
|
|
WORKERS = min(32, os.cpu_count() + 4)
|
2019-06-15 21:02:31 +00:00
|
|
|
WORKDIR = PARENT_DIR
|
|
|
|
CONFIG_FILE = PARENT_DIR / "config.ini"
|
2018-05-07 12:30:55 +00:00
|
|
|
|
2019-07-11 17:28:33 +00:00
|
|
|
PARSE_MODES = ["combined", "markdown", "md", "html", None]
|
|
|
|
|
2020-12-20 17:28:21 +00:00
|
|
|
mimetypes = MimeTypes()
|
|
|
|
mimetypes.readfp(StringIO(mime_types))
|
2019-04-20 15:59:42 +00:00
|
|
|
|
2019-06-19 14:10:37 +00:00
|
|
|
def __init__(self):
|
2020-08-30 22:17:33 +00:00
|
|
|
try:
|
|
|
|
asyncio.get_event_loop()
|
|
|
|
except RuntimeError:
|
|
|
|
# This happens when creating Client instances inside different threads that don't have an event loop.
|
|
|
|
# Set the main event loop in this thread.
|
|
|
|
asyncio.set_event_loop(pyrogram.main_event_loop)
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
self.session_name = None
|
|
|
|
self.api_id = None
|
|
|
|
self.api_hash = None
|
|
|
|
self.app_version = None
|
|
|
|
self.device_model = None
|
|
|
|
self.system_version = None
|
|
|
|
self.lang_code = None
|
|
|
|
self.ipv6 = None
|
|
|
|
self.proxy = None
|
|
|
|
self.test_mode = None
|
|
|
|
self.bot_token = None
|
|
|
|
self.phone_number = None
|
|
|
|
self.phone_code = None
|
|
|
|
self.password = None
|
|
|
|
self.force_sms = None
|
|
|
|
self.workers = None
|
|
|
|
self.workdir = None
|
|
|
|
self.config_file = None
|
|
|
|
self.plugins = None
|
|
|
|
self.parse_mode = None
|
|
|
|
self.no_updates = None
|
|
|
|
self.takeout = None
|
|
|
|
self.sleep_threshold = None
|
|
|
|
|
2021-04-07 11:57:59 +00:00
|
|
|
self.handler_executor = None
|
|
|
|
self.filter_executor = None
|
|
|
|
self.progress_executor = None
|
2020-08-22 06:05:05 +00:00
|
|
|
|
2019-06-19 14:10:37 +00:00
|
|
|
self.storage = None
|
2018-05-07 12:30:55 +00:00
|
|
|
|
|
|
|
self.rnd_id = MsgId
|
|
|
|
|
2019-06-26 14:08:24 +00:00
|
|
|
self.parser = Parser(self)
|
2019-07-11 17:28:33 +00:00
|
|
|
self.parse_mode = "combined"
|
2018-05-07 12:30:55 +00:00
|
|
|
|
|
|
|
self.session = None
|
2020-08-22 06:05:05 +00:00
|
|
|
|
2018-05-07 12:30:55 +00:00
|
|
|
self.media_sessions = {}
|
2020-08-21 05:28:27 +00:00
|
|
|
self.media_sessions_lock = asyncio.Lock()
|
2018-05-07 12:30:55 +00:00
|
|
|
|
2019-08-13 11:15:58 +00:00
|
|
|
self.is_connected = None
|
|
|
|
self.is_initialized = None
|
2018-05-07 12:30:55 +00:00
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
self.no_updates = None
|
2019-01-03 11:20:42 +00:00
|
|
|
self.takeout_id = None
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
self.dispatcher = None
|
2018-05-07 12:30:55 +00:00
|
|
|
|
2018-05-23 12:27:17 +00:00
|
|
|
self.disconnect_handler = None
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
self.loop = None
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def send(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def resolve_peer(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-04 13:37:26 +00:00
|
|
|
def fetch_peers(self, *args, **kwargs):
|
2019-01-02 21:39:16 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-04 13:37:26 +00:00
|
|
|
def add_handler(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def save_file(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
2018-05-09 18:27:29 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def get_messages(self, *args, **kwargs):
|
2019-01-04 13:37:26 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def get_history(self, *args, **kwargs):
|
2018-05-09 18:27:29 +00:00
|
|
|
pass
|
2019-01-04 15:10:34 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def get_dialogs(self, *args, **kwargs):
|
2019-01-04 15:10:34 +00:00
|
|
|
pass
|
2019-01-04 16:13:44 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def get_chat_members(self, *args, **kwargs):
|
2019-01-04 16:13:44 +00:00
|
|
|
pass
|
2019-01-24 16:21:41 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def get_chat_members_count(self, *args, **kwargs):
|
2019-01-24 16:21:41 +00:00
|
|
|
pass
|
2019-03-21 17:37:00 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def answer_inline_query(self, *args, **kwargs):
|
2019-03-21 17:37:00 +00:00
|
|
|
pass
|
2019-04-20 15:59:42 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def get_profile_photos(self, *args, **kwargs):
|
2019-04-20 15:59:42 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def edit_message_text(self, *args, **kwargs):
|
2019-04-20 15:59:42 +00:00
|
|
|
pass
|
2019-05-30 22:20:09 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def edit_inline_text(self, *args, **kwargs):
|
2019-05-30 22:20:09 +00:00
|
|
|
pass
|
2019-06-14 00:12:06 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def edit_message_media(self, *args, **kwargs):
|
2019-06-14 00:12:06 +00:00
|
|
|
pass
|
2019-06-14 00:46:27 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def edit_inline_media(self, *args, **kwargs):
|
2019-06-14 02:52:05 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def edit_message_reply_markup(self, *args, **kwargs):
|
2019-06-14 00:46:27 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
async def edit_inline_reply_markup(self, *args, **kwargs):
|
2019-06-14 02:52:05 +00:00
|
|
|
pass
|
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
def guess_mime_type(self, *args, **kwargs):
|
2019-06-14 00:46:27 +00:00
|
|
|
pass
|
2019-06-14 02:52:05 +00:00
|
|
|
|
2020-08-21 05:28:27 +00:00
|
|
|
def guess_extension(self, *args, **kwargs):
|
2019-06-14 02:52:05 +00:00
|
|
|
pass
|
2020-08-22 06:05:05 +00:00
|
|
|
|
|
|
|
def load_config(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def load_session(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def load_plugins(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def handle_download(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def start(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def stop(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def connect(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def authorize(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def disconnect(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def initialize(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
async def terminate(self, *args, **kwargs):
|
|
|
|
pass
|