pyrofork: Fix critical issue

Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
wulan17 2025-03-26 22:05:05 +07:00
parent 8b2ae07ea0
commit fb7d5a46a2
No known key found for this signature in database
GPG key ID: 318CD6CD3A6AC0A5
19 changed files with 128 additions and 47 deletions

View file

@ -442,12 +442,12 @@ def start(format: bool = False):
references, count = get_references(c.qualname, "constructors") references, count = get_references(c.qualname, "constructors")
if references: if references:
docstring += f"\n Functions:\n This object can be returned by " \ docstring += "\n Functions:\n This object can be returned by " \
f"{count} function{'s' if count > 1 else ''}.\n\n" \ f"{count} function{'s' if count > 1 else ''}.\n\n" \
f" .. currentmodule:: pyrogram.raw.functions\n\n" \ " .. currentmodule:: pyrogram.raw.functions\n\n" \
f" .. autosummary::\n" \ " .. autosummary::\n" \
f" :nosignatures:\n\n" \ " :nosignatures:\n\n" \
f" " + references " " + references
write_types = read_types = "" if c.has_flags else "# No flags\n " write_types = read_types = "" if c.has_flags else "# No flags\n "

View file

@ -29,7 +29,7 @@ from pygments.styles.friendly import FriendlyStyle
FriendlyStyle.background_color = "#f3f2f1" FriendlyStyle.background_color = "#f3f2f1"
project = "Pyrofork" project = "Pyrofork"
copyright = f"2022-present, Mayuri-Chan" copyright = "2022-present, Mayuri-Chan"
author = "Mayuri-Chan" author = "Mayuri-Chan"
version = ".".join(__version__.split(".")[:-1]) version = ".".join(__version__.split(".")[:-1])

View file

@ -17,13 +17,17 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
from concurrent.futures.thread import ThreadPoolExecutor
from . import raw, types, filters, handlers, emoji, enums
from .client import Client
from .sync import idle, compose
__fork_name__ = "PyroFork" __fork_name__ = "PyroFork"
__version__ = "2.3.59" __version__ = "2.3.59"
__license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)" __license__ = "GNU Lesser General Public License v3.0 (LGPL-3.0)"
__copyright__ = "Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>" __copyright__ = "Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>"
from concurrent.futures.thread import ThreadPoolExecutor
class StopTransmission(Exception): class StopTransmission(Exception):
pass pass
@ -36,9 +40,20 @@ class StopPropagation(StopAsyncIteration):
class ContinuePropagation(StopAsyncIteration): class ContinuePropagation(StopAsyncIteration):
pass pass
from . import raw, types, filters, handlers, emoji, enums
from .client import Client
from .sync import idle, compose
crypto_executor = ThreadPoolExecutor(1, thread_name_prefix="CryptoWorker") crypto_executor = ThreadPoolExecutor(1, thread_name_prefix="CryptoWorker")
__all__ = [
"Client",
"idle",
"compose",
"crypto_executor",
"StopTransmission",
"StopPropagation",
"ContinuePropagation",
"raw",
"types",
"filters",
"handlers",
"emoji",
"enums",
]

View file

@ -33,7 +33,7 @@ from importlib import import_module
from io import StringIO, BytesIO from io import StringIO, BytesIO
from mimetypes import MimeTypes from mimetypes import MimeTypes
from pathlib import Path from pathlib import Path
from typing import Union, List, Optional, Callable, AsyncGenerator, Type, Tuple from typing import Union, List, Optional, Callable, AsyncGenerator, Tuple
import pyrogram import pyrogram
from pyrogram import __version__, __license__ from pyrogram import __version__, __license__
@ -51,24 +51,26 @@ from pyrogram.handlers.handler import Handler
from pyrogram.methods import Methods from pyrogram.methods import Methods
from pyrogram.session import Auth, Session from pyrogram.session import Auth, Session
from pyrogram.storage import FileStorage, MemoryStorage, Storage from pyrogram.storage import FileStorage, MemoryStorage, Storage
from pyrogram.types import User, TermsOfService
from pyrogram.utils import ainput
from .connection import Connection
from .connection.transport import TCPAbridged
from .dispatcher import Dispatcher
from .file_id import FileId, FileType, ThumbnailSource
from .mime_types import mime_types
from .parser import Parser
from .session.internals import MsgId
log = logging.getLogger(__name__)
MONGO_AVAIL = False
try: try:
import pymongo import pymongo
except Exception: except Exception:
pass pass
else: else:
from pyrogram.storage import MongoStorage from pyrogram.storage import MongoStorage
from pyrogram.types import User, TermsOfService MONGO_AVAIL = True
from pyrogram.utils import ainput
from .connection import Connection
from .connection.transport import TCP, TCPAbridged
from .dispatcher import Dispatcher
from .file_id import FileId, FileType, ThumbnailSource
from .filters import Filter
from .mime_types import mime_types
from .parser import Parser
from .session.internals import MsgId
log = logging.getLogger(__name__)
class Client(Methods): class Client(Methods):
@ -316,9 +318,7 @@ class Client(Methods):
elif self.in_memory: elif self.in_memory:
self.storage = MemoryStorage(self.name) self.storage = MemoryStorage(self.name)
elif self.mongodb: elif self.mongodb:
try: if not MONGO_AVAIL:
import pymongo
except Exception:
log.warning( log.warning(
"pymongo is missing! " "pymongo is missing! "
"Using MemoryStorage as session storage" "Using MemoryStorage as session storage"
@ -953,7 +953,7 @@ class Client(Methods):
) )
count += 1 count += 1
except Exception as e: except Exception:
pass pass
else: else:
for path, handlers in include: for path, handlers in include:

View file

@ -23,3 +23,13 @@ from .tcp_abridged_o import TCPAbridgedO
from .tcp_full import TCPFull from .tcp_full import TCPFull
from .tcp_intermediate import TCPIntermediate from .tcp_intermediate import TCPIntermediate
from .tcp_intermediate_o import TCPIntermediateO from .tcp_intermediate_o import TCPIntermediateO
__all__ = [
"TCP",
"Proxy",
"TCPAbridged",
"TCPAbridgedO",
"TCPFull",
"TCPIntermediate",
"TCPIntermediateO"
]

View file

@ -71,7 +71,7 @@ def unpack(
message = Message.read(data) message = Message.read(data)
except KeyError as e: except KeyError as e:
if e.args[0] == 0: if e.args[0] == 0:
raise ConnectionError(f"Received empty data. Check your internet connection.") raise ConnectionError("Received empty data. Check your internet connection.")
left = data.read().hex() left = data.read().hex()
@ -79,7 +79,7 @@ def unpack(
left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left] left = [[left[i:i + 8] for i in range(0, len(left), 8)] for left in left]
left = "\n".join(" ".join(x for x in left) for left in left) left = "\n".join(" ".join(x for x in left) for left in left)
raise ValueError(f"The server sent an unknown constructor: {hex(e.args[0])}\n{left}") raise ValueError("The server sent an unknown constructor: {hex(e.args[0])}\n{left}")
# https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key # https://core.telegram.org/mtproto/security_guidelines#checking-sha256-hash-value-of-msg-key
# 96 = 88 + 8 (incoming message) # 96 = 88 + 8 (incoming message)

View file

@ -42,3 +42,31 @@ from .message_reaction_updated_handler import MessageReactionUpdatedHandler
from .message_reaction_count_updated_handler import MessageReactionCountUpdatedHandler from .message_reaction_count_updated_handler import MessageReactionCountUpdatedHandler
from .pre_checkout_query_handler import PreCheckoutQueryHandler from .pre_checkout_query_handler import PreCheckoutQueryHandler
from .shipping_query_handler import ShippingQueryHandler from .shipping_query_handler import ShippingQueryHandler
__all__ = [
"BotBusinessConnectHandler",
"BotBusinessMessageHandler",
"CallbackQueryHandler",
"ChatJoinRequestHandler",
"ChatMemberUpdatedHandler",
"ConversationHandler",
"ChosenInlineResultHandler",
"DeletedMessagesHandler",
"DeletedBotBusinessMessagesHandler",
"DisconnectHandler",
"EditedMessageHandler",
"EditedBotBusinessMessageHandler",
"ErrorHandler",
"InlineQueryHandler",
"MessageHandler",
"PollHandler",
"PreCheckoutQueryHandler",
"PurchasedPaidMediaHandler",
"RawUpdateHandler",
"UserStatusHandler",
"StoryHandler",
"MessageReactionUpdatedHandler",
"MessageReactionCountUpdatedHandler",
"PreCheckoutQueryHandler",
"ShippingQueryHandler",
]

View file

@ -101,9 +101,9 @@ def kb(rows=None, **kwargs):
line = [] line = []
for button in row: for button in row:
button_type = type(button) button_type = type(button)
if button_type == str: if isinstance(button_type, str):
button = KeyboardButton(button) button = KeyboardButton(button)
elif button_type == dict: elif isinstance(button_type, dict):
button = KeyboardButton(**button) button = KeyboardButton(**button)
line.append(button) line.append(button)

View file

@ -17,7 +17,6 @@
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
import pyrogram import pyrogram
from pyrogram import raw from pyrogram import raw
from pyrogram import types
from typing import Union from typing import Union

View file

@ -16,7 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. # along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from typing import Callable, Optional, Union from typing import Callable
import pyrogram import pyrogram
from pyrogram.filters import Filter from pyrogram.filters import Filter

View file

@ -180,8 +180,12 @@ class CopyMediaGroup:
**await self.parser.parse( **await self.parser.parse(
captions[i] if isinstance(captions, list) and i < len(captions) and captions[i] else captions[i] if isinstance(captions, list) and i < len(captions) and captions[i] else
captions if isinstance(captions, str) and i == 0 else captions if isinstance(captions, str) and i == 0 else
message.caption if message.caption and message.caption != "None" and not type( message.caption if (
captions) is str else "") message.caption
and message.caption != "None"
and not isinstance(captions, str)
) else ""
)
) )
) )

View file

@ -18,7 +18,6 @@
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
import html import html
import logging
import re import re
from typing import Optional from typing import Optional

View file

@ -30,3 +30,24 @@ from .primitives.int import Int, Long, Int128, Int256
from .primitives.string import String from .primitives.string import String
from .primitives.vector import Vector from .primitives.vector import Vector
from .tl_object import TLObject from .tl_object import TLObject
__all__ = [
"FutureSalt",
"FutureSalts",
"GzipPacked",
"List",
"Message",
"MsgContainer",
"Bool",
"BoolFalse",
"BoolTrue",
"Bytes",
"Double",
"Int",
"Long",
"Int128",
"Int256",
"String",
"Vector",
"TLObject"
]

View file

@ -20,3 +20,9 @@
from .data_center import DataCenter from .data_center import DataCenter
from .msg_factory import MsgFactory from .msg_factory import MsgFactory
from .msg_id import MsgId from .msg_id import MsgId
__all__ = [
"DataCenter",
"MsgFactory",
"MsgId"
]

View file

@ -30,3 +30,8 @@ from .update import *
from .user_and_chats import * from .user_and_chats import *
from .payments import * from .payments import *
from .pyromod import * from .pyromod import *
__all__ = [
"List",
"Object"
]

View file

@ -18,8 +18,7 @@
from typing import List from typing import List
import pyrogram from pyrogram import raw, types
from pyrogram import raw, types, utils
from ..object import Object from ..object import Object

View file

@ -16,11 +16,8 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
from typing import List, Optional, Union
import pyrogram
from pyrogram import raw from pyrogram import raw
from pyrogram.file_id import FileId, FileType, FileUniqueId, FileUniqueType, ThumbnailSource
from ..object import Object from ..object import Object

View file

@ -57,7 +57,7 @@ class TranscribedAudio(Object):
self.trial_remains_until_date = trial_remains_until_date self.trial_remains_until_date = trial_remains_until_date
@staticmethod @staticmethod
def _parse(transcribe_result: "raw.types.messages.TranscribedAudio") -> "TranscribeAudio": def _parse(transcribe_result: "raw.types.messages.TranscribedAudio") -> "TranscribedAudio":
return TranscribedAudio( return TranscribedAudio(
transcription_id=transcribe_result.transcription_id, transcription_id=transcribe_result.transcription_id,
text=transcribe_result.text, text=transcribe_result.text,

View file

@ -16,8 +16,6 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>. # along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
import pyrogram
from pyrogram import raw from pyrogram import raw
from ..object import Object from ..object import Object