2018-05-07 12:30:55 +00:00
|
|
|
# Pyrogram - Telegram MTProto API Client Library for Python
|
|
|
|
# Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
|
|
|
|
#
|
|
|
|
# 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-24 16:26:11 +00:00
|
|
|
import platform
|
2018-05-07 12:30:55 +00:00
|
|
|
import re
|
|
|
|
from queue import Queue
|
|
|
|
from threading import Lock
|
|
|
|
|
2018-06-24 16:26:11 +00:00
|
|
|
from pyrogram import __version__
|
2018-05-07 12:30:55 +00:00
|
|
|
from ..style import Markdown, HTML
|
|
|
|
from ...api.core import Object
|
2018-06-24 15:47:29 +00:00
|
|
|
from ...session import Session
|
2018-06-24 16:26:11 +00:00
|
|
|
from ...session.internals import MsgId
|
2018-05-07 12:30:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BaseClient:
|
2018-06-24 16:26:11 +00:00
|
|
|
APP_VERSION = "Pyrogram \U0001f525 {}".format(__version__)
|
|
|
|
|
|
|
|
DEVICE_MODEL = "{} {}".format(
|
|
|
|
platform.python_implementation(),
|
|
|
|
platform.python_version()
|
|
|
|
)
|
|
|
|
|
|
|
|
SYSTEM_VERSION = "{} {}".format(
|
|
|
|
platform.system(),
|
|
|
|
platform.release()
|
|
|
|
)
|
|
|
|
|
|
|
|
LANG_CODE = "en"
|
|
|
|
|
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
|
|
|
|
DOWNLOAD_WORKERS = 1
|
|
|
|
OFFLINE_SLEEP = 300
|
2018-10-13 08:41:58 +00:00
|
|
|
WORKERS = 4
|
2018-10-13 08:38:44 +00:00
|
|
|
WORKDIR = "."
|
|
|
|
CONFIG_FILE = "./config.ini"
|
2018-05-07 12:30:55 +00:00
|
|
|
|
|
|
|
MEDIA_TYPE_ID = {
|
|
|
|
0: "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",
|
2018-05-07 12:30:55 +00:00
|
|
|
13: "video_note"
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
2018-08-27 00:11:07 +00:00
|
|
|
self.bot_token = None
|
2018-05-07 12:30:55 +00:00
|
|
|
self.dc_id = None
|
|
|
|
self.auth_key = None
|
|
|
|
self.user_id = None
|
|
|
|
self.date = None
|
|
|
|
|
|
|
|
self.rnd_id = MsgId
|
|
|
|
self.channels_pts = {}
|
|
|
|
|
|
|
|
self.peers_by_id = {}
|
|
|
|
self.peers_by_username = {}
|
|
|
|
self.peers_by_phone = {}
|
|
|
|
|
|
|
|
self.markdown = Markdown(self.peers_by_id)
|
|
|
|
self.html = HTML(self.peers_by_id)
|
|
|
|
|
|
|
|
self.session = None
|
|
|
|
self.media_sessions = {}
|
|
|
|
self.media_sessions_lock = Lock()
|
|
|
|
|
|
|
|
self.is_started = None
|
|
|
|
self.is_idle = None
|
|
|
|
|
|
|
|
self.updates_queue = Queue()
|
|
|
|
self.updates_workers_list = []
|
|
|
|
self.download_queue = Queue()
|
|
|
|
self.download_workers_list = []
|
|
|
|
|
2018-05-23 12:27:17 +00:00
|
|
|
self.disconnect_handler = None
|
|
|
|
|
2018-06-24 15:47:29 +00:00
|
|
|
def send(self, data: Object, retries: int = Session.MAX_RETRIES, timeout: float = Session.WAIT_TIMEOUT):
|
2018-05-07 12:30:55 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
def resolve_peer(self, peer_id: int or str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def add_handler(self, handler, group: int = 0) -> tuple:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def save_file(
|
|
|
|
self,
|
|
|
|
path: str,
|
|
|
|
file_id: int = None,
|
|
|
|
file_part: int = 0,
|
|
|
|
progress: callable = None,
|
|
|
|
progress_args: tuple = ()
|
|
|
|
):
|
|
|
|
pass
|
2018-05-09 18:27:29 +00:00
|
|
|
|
|
|
|
def get_messages(
|
|
|
|
self,
|
|
|
|
chat_id: int or str,
|
2018-10-28 16:18:00 +00:00
|
|
|
message_ids: int or list = None,
|
|
|
|
reply_to_message_ids: int or list = None,
|
2018-05-09 18:27:29 +00:00
|
|
|
replies: int = 1
|
|
|
|
):
|
|
|
|
pass
|