2018-05-07 12:30:55 +00:00
|
|
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
2019-01-01 11:36:16 +00:00
|
|
|
# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance>
|
2018-05-07 12:30:55 +00:00
|
|
|
#
|
|
|
|
# This file is part of Pyrogram.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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-06-18 19:21:26 +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
|
|
|
|
2018-06-24 16:26:11 +00:00
|
|
|
from pyrogram import __version__
|
2019-06-26 14:08:24 +00:00
|
|
|
from ..parser import Parser
|
2018-05-07 12:30:55 +00:00
|
|
|
from ...session.internals import MsgId
|
|
|
|
|
|
|
|
|
|
|
|
class BaseClient:
|
2019-03-27 14:44:29 +00:00
|
|
|
class StopTransmission(StopAsyncIteration):
|
2019-01-11 13:00:03 +00:00
|
|
|
pass
|
|
|
|
|
2019-05-17 23:45:01 +00:00
|
|
|
APP_VERSION = "Pyrogram {}".format(__version__)
|
2018-06-24 16:26:11 +00:00
|
|
|
|
|
|
|
DEVICE_MODEL = "{} {}".format(
|
|
|
|
platform.python_implementation(),
|
|
|
|
platform.python_version()
|
|
|
|
)
|
|
|
|
|
|
|
|
SYSTEM_VERSION = "{} {}".format(
|
|
|
|
platform.system(),
|
|
|
|
platform.release()
|
|
|
|
)
|
|
|
|
|
|
|
|
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-]+)$")
|
2018-05-07 12:30:55 +00:00
|
|
|
BOT_TOKEN_RE = re.compile(r"^\d+:[\w-]+$")
|
|
|
|
DIALOGS_AT_ONCE = 100
|
|
|
|
UPDATES_WORKERS = 1
|
2018-06-18 19:21:26 +00:00
|
|
|
DOWNLOAD_WORKERS = 4
|
2019-05-06 14:36:57 +00:00
|
|
|
OFFLINE_SLEEP = 900
|
2018-10-13 08:41:58 +00:00
|
|
|
WORKERS = 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 = {}
|
|
|
|
|
|
|
|
with open("{}/mime.types".format(os.path.dirname(__file__)), "r", encoding="UTF-8") as f:
|
|
|
|
for match in re.finditer(r"^([^#\s]+)\s+(.+)$", f.read(), flags=re.M):
|
|
|
|
mime_type, extensions = match.groups()
|
|
|
|
|
|
|
|
extensions = [".{}".format(ext) for ext in extensions.split(" ")]
|
|
|
|
|
|
|
|
for ext in extensions:
|
|
|
|
extensions_to_mime_types[ext] = mime_type
|
|
|
|
|
|
|
|
mime_types_to_extensions[mime_type] = " ".join(extensions)
|
|
|
|
|
2019-07-11 17:59:56 +00:00
|
|
|
is_idling = False
|
|
|
|
|
2018-05-07 12:30:55 +00:00
|
|
|
def __init__(self):
|
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
|
|
|
|
self.media_sessions = {}
|
2018-06-18 19:21:26 +00:00
|
|
|
self.media_sessions_lock = asyncio.Lock()
|
2018-05-07 12:30:55 +00:00
|
|
|
|
|
|
|
self.is_started = None
|
|
|
|
|
2019-01-03 11:20:42 +00:00
|
|
|
self.takeout_id = None
|
|
|
|
|
2018-06-18 19:21:26 +00:00
|
|
|
self.updates_queue = asyncio.Queue()
|
2019-06-24 15:33:33 +00:00
|
|
|
self.updates_worker_tasks = []
|
2018-06-18 19:21:26 +00:00
|
|
|
self.download_queue = asyncio.Queue()
|
|
|
|
self.download_worker_tasks = []
|
2018-05-07 12:30:55 +00:00
|
|
|
|
2018-05-23 12:27:17 +00:00
|
|
|
self.disconnect_handler = None
|
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def send(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def resolve_peer(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-17 11:34:30 +00:00
|
|
|
def fetch_peers(self, *args, **kwargs):
|
2019-01-02 21:39:16 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-17 11:34:30 +00:00
|
|
|
def add_handler(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def save_file(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def get_messages(self, *args, **kwargs):
|
2019-01-02 21:39:16 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def get_history(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def get_dialogs(self, *args, **kwargs):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
2018-05-09 18:27:29 +00:00
|
|
|
|
2019-01-07 21:57:19 +00:00
|
|
|
async def get_chat_members(self, *args, **kwargs):
|
2018-05-09 18:27:29 +00:00
|
|
|
pass
|
2019-01-24 16:21:41 +00:00
|
|
|
|
2019-01-25 09:24:04 +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
|
|
|
|
2019-03-22 12:47:31 +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
|
|
|
|
2019-07-31 11:33:04 +00:00
|
|
|
async def get_profile_photos(self, *args, **kwargs):
|
2019-04-20 15:59:42 +00:00
|
|
|
pass
|
|
|
|
|
2019-07-31 11:33:04 +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
|
|
|
|
2019-07-31 11:33:04 +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
|
|
|
|
2019-07-31 11:33:04 +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
|
|
|
|
2019-07-31 11:33:04 +00:00
|
|
|
async def edit_inline_media(self, *args, **kwargs):
|
2019-06-14 02:52:05 +00:00
|
|
|
pass
|
|
|
|
|
2019-07-31 11:33:04 +00:00
|
|
|
async def edit_message_reply_markup(self, *args, **kwargs):
|
2019-06-14 00:46:27 +00:00
|
|
|
pass
|
|
|
|
|
2019-07-31 11:33:04 +00:00
|
|
|
async def edit_inline_reply_markup(self, *args, **kwargs):
|
2019-06-14 02:52:05 +00:00
|
|
|
pass
|
|
|
|
|
2019-07-31 11:33:04 +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
|
|
|
|
2019-07-31 11:33:04 +00:00
|
|
|
def guess_extension(self, *args, **kwargs):
|
2019-06-14 02:52:05 +00:00
|
|
|
pass
|