2020-03-21 14:43:32 +00:00
|
|
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
|
|
|
# Copyright (C) 2017-2020 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
|
|
|
|
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
|
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
|
|
|
|
|
2018-06-13 18:53:31 +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]
|
|
|
|
|
2018-05-07 12:30:55 +00:00
|
|
|
MEDIA_TYPE_ID = {
|
2019-05-29 08:40:37 +00:00
|
|
|
0: "photo_thumbnail",
|
2018-05-11 09:57:05 +00:00
|
|
|
1: "chat_photo",
|
2018-05-07 12:30:55 +00:00
|
|
|
2: "photo",
|
|
|
|
3: "voice",
|
|
|
|
4: "video",
|
|
|
|
5: "document",
|
|
|
|
8: "sticker",
|
|
|
|
9: "audio",
|
2018-08-06 19:32:38 +00:00
|
|
|
10: "animation",
|
2019-05-29 08:40:37 +00:00
|
|
|
13: "video_note",
|
|
|
|
14: "document_thumbnail"
|
2018-05-07 12:30:55 +00:00
|
|
|
}
|
|
|
|
|
2019-04-20 15:59:42 +00:00
|
|
|
mime_types_to_extensions = {}
|
|
|
|
extensions_to_mime_types = {}
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
with open(f"{os.path.dirname(__file__)}/mime.types", "r", encoding="UTF-8") as f:
|
2019-04-20 15:59:42 +00:00
|
|
|
for match in re.finditer(r"^([^#\s]+)\s+(.+)$", f.read(), flags=re.M):
|
|
|
|
mime_type, extensions = match.groups()
|
|
|
|
|
2020-08-22 06:05:05 +00:00
|
|
|
extensions = [f".{ext}" for ext in extensions.split(" ")]
|
2019-04-20 15:59:42 +00:00
|
|
|
|
|
|
|
for ext in extensions:
|
|
|
|
extensions_to_mime_types[ext] = mime_type
|
|
|
|
|
|
|
|
mime_types_to_extensions[mime_type] = " ".join(extensions)
|
|
|
|
|
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
|
|
|
|
|
|
|
|
self.executor = None
|
|
|
|
|
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
|