Compare commits

...

9 commits

Author SHA1 Message Date
wulan17
7fabbd8c14
pyrofork: Add STARS_AMOUNT_INVALID exception
Some checks are pending
Build-docs / build (push) Waiting to run
Pyrofork / build (macos-latest, 3.10) (push) Waiting to run
Pyrofork / build (macos-latest, 3.11) (push) Waiting to run
Pyrofork / build (macos-latest, 3.12) (push) Waiting to run
Pyrofork / build (macos-latest, 3.13) (push) Waiting to run
Pyrofork / build (macos-latest, 3.9) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.10) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.11) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.12) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.13) (push) Waiting to run
Pyrofork / build (ubuntu-latest, 3.9) (push) Waiting to run
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 22:44:59 +07:00
wulan17
588a9d2ec6
pyrofork: Add paid_message_price_changed field to Message
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 22:36:11 +07:00
wulan17
9a8fcec0dc
pyrofork: Add ALLOW_PAYMENT_REQUIRED_X exception
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 22:26:27 +07:00
wulan17
4df8138e79
pyrofork: Add linked_forum field to Chat
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 22:04:45 +07:00
wulan17
6835bccf11
pyrofork: Drop Chat.is_forum and add new ChatType (FORUM)
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 22:00:51 +07:00
wulan17
c7f7707fc6
pyrofork: Add new ChatType (MONOFORUM)
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 22:00:17 +07:00
uNickz
28f7137828
pyrofork: Add file_name param on InputMedia
Some checks failed
Build-docs / build (push) Has been cancelled
Pyrofork / build (macos-latest, 3.10) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.11) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.12) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.13) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.9) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.10) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.11) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.12) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.13) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.9) (push) Has been cancelled
* Add file_name param on InputMedia

Add file_name param on:
 - InputMediaVideo
 - InputMediaAudio
 - InputMediaDocument

---------

Co-authored-by: KurimuzonAkuma <31959970+KurimuzonAkuma@users.noreply.github.com>
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 20:33:30 +07:00
wulan17
7c94fc8009
pyrofork: Refactor Message.link
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 20:33:30 +07:00
wulan17
969a2c0f55
pyrofork: fix RequestedChat type (#140)
Signed-off-by: wulan17 <wulan17@komodos.id>
2025-06-09 20:33:29 +07:00
15 changed files with 133 additions and 23 deletions

View file

@ -605,6 +605,7 @@ def pyrogram_api():
Invoice
LabeledPrice
PaidMedia
PaidMessagePriceChanged
PaymentForm
PaymentInfo
PaymentRefunded

View file

@ -503,3 +503,4 @@ BOOSTS_EMPTY You can't modify the icon of the General topic.
BOOST_NOT_MODIFIED You're already boosting the specified channel.
PAYMENT_REQUIRED The payment is required
BOOST_PEER_INVALID The specified `boost_peer` is invalid.
STARS_AMOUNT_INVALID The specified `amount` is invalid.
1 id message
503 BOOST_NOT_MODIFIED You're already boosting the specified channel.
504 PAYMENT_REQUIRED The payment is required
505 BOOST_PEER_INVALID The specified `boost_peer` is invalid.
506 STARS_AMOUNT_INVALID The specified `amount` is invalid.

View file

@ -44,3 +44,4 @@ GROUPCALL_ALREADY_STARTED The groupcall has already started, you can join direct
GROUPCALL_FORBIDDEN The group call has already ended
LIVE_DISABLED Story is disabled server-side
CHAT_GUEST_SEND_FORBIDDEN You need to join the discussion group before commenting
ALLOW_PAYMENT_REQUIRED_X Payment of {value} stars is required to perform this action
1 id message
44 GROUPCALL_FORBIDDEN The group call has already ended
45 LIVE_DISABLED Story is disabled server-side
46 CHAT_GUEST_SEND_FORBIDDEN You need to join the discussion group before commenting
47 ALLOW_PAYMENT_REQUIRED_X Payment of {value} stars is required to perform this action

View file

@ -39,3 +39,9 @@ class ChatType(AutoName):
CHANNEL = auto()
"Chat is a channel"
FORUM = auto()
"Chat is a forum"
MONOFORUM = auto()
"Chat is a monoforum"

View file

@ -132,3 +132,6 @@ class MessageServiceType(AutoName):
SCREENSHOT_TAKEN = auto()
"Screenshot taken"
PAID_MESSAGE_PRICE_CHANGED = auto()
"Paid message price changed"

View file

@ -271,7 +271,7 @@ class SendMediaGroup:
w=i.width,
h=i.height
),
raw.types.DocumentAttributeFilename(file_name=os.path.basename(i.media)),
raw.types.DocumentAttributeFilename(file_name=i.file_name or os.path.basename(i.media)),
]
if is_animation:
attributes.append(raw.types.DocumentAttributeAnimated())
@ -339,7 +339,7 @@ class SendMediaGroup:
w=i.width,
h=i.height
),
raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "video.mp4")),
raw.types.DocumentAttributeFilename(file_name=i.file_name or getattr(i.media, "name", "video.mp4")),
],
),
),
@ -371,7 +371,7 @@ class SendMediaGroup:
performer=i.performer,
title=i.title
),
raw.types.DocumentAttributeFilename(file_name=os.path.basename(i.media)),
raw.types.DocumentAttributeFilename(file_name=i.file_name or os.path.basename(i.media)),
],
),
),
@ -419,7 +419,7 @@ class SendMediaGroup:
performer=i.performer,
title=i.title
),
raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "audio.mp3")),
raw.types.DocumentAttributeFilename(file_name=i.file_name or getattr(i.media, "name", "audio.mp3")),
],
),
),
@ -445,7 +445,7 @@ class SendMediaGroup:
file=file,
thumb=thumb,
attributes=[
raw.types.DocumentAttributeFilename(file_name=os.path.basename(i.media)),
raw.types.DocumentAttributeFilename(file_name=i.file_name or os.path.basename(i.media)),
],
),
),
@ -490,7 +490,7 @@ class SendMediaGroup:
file=file,
thumb=thumb,
attributes=[
raw.types.DocumentAttributeFilename(file_name=getattr(i.media, "name", "file.zip")),
raw.types.DocumentAttributeFilename(file_name=i.file_name or getattr(i.media, "name", "file.zip")),
],
),
),

View file

@ -17,7 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
from pyrogram import raw, types
from pyrogram import enums, raw, types
from ..object import Object
from typing import Union
@ -114,7 +114,7 @@ class KeyboardButton(Object):
is_creator=b.peer_type.creator,
is_bot_participant=b.peer_type.bot_participant,
is_username=b.peer_type.has_username,
is_forum=b.peer_type.forum,
is_forum=True if b.peer_type.type == enums.ChatType.FORUM else False,
max=b.max_quantity
)
)
@ -155,7 +155,7 @@ class KeyboardButton(Object):
creator=self.request_chat.is_creator,
bot_participant=self.request_chat.is_bot_participant,
has_username=self.request_chat.is_username,
forum=self.request_chat.is_forum
forum=True if self.request_chat.type == enums.ChatType.FORUM else False
),
max_quantity=self.request_chat.max,
name_requested=self.request_chat.is_name_requested,

View file

@ -65,8 +65,10 @@ class RequestedChat(Object):
"raw.types.PeerChannel"
]
) -> "RequestedChat":
if isinstance(request, raw.types.RequestedPeerChannel) or isinstance(request, raw.types.PeerChannel):
if getattr(request, "broadcast", None):
type = enums.ChatType.CHANNEL
elif getattr(request, "megagroup", None):
type = enums.ChatType.SUPERGROUP
else:
type = enums.ChatType.GROUP
photo = None

View file

@ -62,6 +62,10 @@ class InputMediaAudio(InputMedia):
title (``str``, *optional*):
Title of the audio
file_name (``str``, *optional*):
File name of the audio sent.
Defaults to file's path basename.
"""
def __init__(
@ -73,7 +77,8 @@ class InputMediaAudio(InputMedia):
caption_entities: List[MessageEntity] = None,
duration: int = 0,
performer: str = "",
title: str = ""
title: str = "",
file_name: str = None
):
super().__init__(media, caption, parse_mode, caption_entities)
@ -81,3 +86,4 @@ class InputMediaAudio(InputMedia):
self.duration = duration
self.performer = performer
self.title = title
self.file_name = file_name

View file

@ -51,6 +51,10 @@ class InputMediaDocument(InputMedia):
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in the caption, which can be specified instead of *parse_mode*.
file_name (``str``, *optional*):
File name of the document sent.
Defaults to file's path basename.
"""
def __init__(
@ -59,8 +63,10 @@ class InputMediaDocument(InputMedia):
thumb: str = None,
caption: str = "",
parse_mode: Optional["enums.ParseMode"] = None,
caption_entities: List[MessageEntity] = None
caption_entities: List[MessageEntity] = None,
file_name: str = None
):
super().__init__(media, caption, parse_mode, caption_entities)
self.thumb = thumb
self.file_name = file_name

View file

@ -62,6 +62,10 @@ class InputMediaVideo(InputMedia):
duration (``int``, *optional*):
Video duration.
file_name (``str``, *optional*):
File name of the video sent.
Defaults to file's path basename.
supports_streaming (``bool``, *optional*):
Pass True, if the uploaded video is suitable for streaming.
@ -79,6 +83,7 @@ class InputMediaVideo(InputMedia):
width: int = 0,
height: int = 0,
duration: int = 0,
file_name: str = None,
supports_streaming: bool = True,
has_spoiler: bool = None,
):
@ -88,5 +93,6 @@ class InputMediaVideo(InputMedia):
self.width = width
self.height = height
self.duration = duration
self.file_name = file_name
self.supports_streaming = supports_streaming
self.has_spoiler = has_spoiler

View file

@ -480,6 +480,7 @@ class Message(Object, Update):
gift_code: "types.GiftCode" = None,
gift: "types.Gift" = None,
screenshot_taken: "types.ScreenshotTaken" = None,
paid_message_price_changed: "types.PaidMessagePriceChanged" = None,
invoice: "types.Invoice" = None,
story: Union["types.MessageStory", "types.Story"] = None,
alternative_videos: List["types.AlternativeVideo"] = None,
@ -596,6 +597,7 @@ class Message(Object, Update):
self.gift_code = gift_code
self.gift = gift
self.screenshot_taken = screenshot_taken
self.paid_message_price_changed = paid_message_price_changed
self.invoice = invoice
self.story = story
self.video = video
@ -760,6 +762,7 @@ class Message(Object, Update):
gift_code = None
gift = None
screenshot_taken = None
paid_message_price_changed = None
service_type = None
chat_join_type = None
@ -881,6 +884,9 @@ class Message(Object, Update):
elif isinstance(action, raw.types.MessageActionScreenshotTaken):
screenshot_taken = types.ScreenshotTaken()
service_type = enums.MessageServiceType.SCREENSHOT_TAKEN
elif isinstance(action, raw.types.MessageActionPaidMessagesPrice):
paid_message_price_changed = types.PaidMessagePriceChanged._parse(action)
service_type = enums.MessageServiceType.PAID_MESSAGE_PRICE_CHANGED
parsed_message = Message(
id=message.id,
@ -926,6 +932,7 @@ class Message(Object, Update):
contact_registered=contact_registered,
gift_code=gift_code,
screenshot_taken=screenshot_taken,
paid_message_price_changed=paid_message_price_changed,
raw=message,
chat_join_type=chat_join_type,
client=client
@ -970,7 +977,7 @@ class Message(Object, Update):
else:
parsed_message.message_thread_id = message.reply_to.reply_to_msg_id
parsed_message.is_topic_message = True
elif parsed_message.chat.is_forum and parsed_message.message_thread_id is None:
elif parsed_message.chat.type == enums.ChatType.FORUM and parsed_message.message_thread_id is None:
parsed_message.message_thread_id = 1
parsed_message.is_topic_message = True
@ -1299,7 +1306,7 @@ class Message(Object, Update):
pass
else:
parsed_message.reply_to_story = reply_to_story
if parsed_message.chat.is_forum and parsed_message.message_thread_id is None:
if parsed_message.chat.type == enums.ChatType.FORUM and parsed_message.message_thread_id is None:
parsed_message.message_thread_id = 1
parsed_message.is_topic_message = True
@ -1314,9 +1321,14 @@ class Message(Object, Update):
self.chat.type in (enums.ChatType.GROUP, enums.ChatType.SUPERGROUP, enums.ChatType.CHANNEL)
and self.chat.username
):
if self.chat.type == enums.ChatType.SUPERGROUP and self.message_thread_id:
return f"https://t.me/{self.chat.username}/{self.message_thread_id}/{self.id}"
return f"https://t.me/{self.chat.username}/{self.id}"
else:
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.id}"
if self.chat.type == enums.ChatType.PRIVATE:
return f"tg://openmessage?user_id={self.from_user.id}&message_id={self.id}"
if self.message_thread_id:
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.message_thread_id}/{self.id}"
return f"https://t.me/c/{utils.get_channel_id(self.chat.id)}/{self.id}"
@property
def content(self) -> str:

View file

@ -27,6 +27,7 @@ from .input_stars_transaction import InputStarsTransaction
from .invoice import Invoice
from .labeled_price import LabeledPrice
from .paid_media import PaidMedia
from .paid_message_price_changed import PaidMessagePriceChanged
from .payment_form import PaymentForm
from .payment_info import PaymentInfo
from .payment_refunded import PaymentRefunded
@ -46,6 +47,7 @@ __all__ = [
"Invoice",
"LabeledPrice",
"PaidMedia",
"PaidMessagePriceChanged",
"PaymentForm",
"PaymentInfo",
"PaymentRefunded",

View file

@ -0,0 +1,49 @@
# Pyrofork - Telegram MTProto API Client Library for Python
# Copyright (C) 2022-present Mayuri-Chan <https://github.com/Mayuri-Chan>
#
# This file is part of Pyrofork.
#
# Pyrofork 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.
#
# Pyrofork 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 Pyrofork. If not, see <http://www.gnu.org/licenses/>.
from typing import List, Union
from pyrogram import raw
from pyrogram import types
from ..object import Object
class PaidMessagePriceChanged(Object):
"""A PaidMessagePriceChanged.
Parameters:
stars_amount (``int``):
Amount of stars.
extended_media (List of :obj:`~pyrogram.types.Animation` | :obj:`~pyrogram.types.ExtendedMediaPreview` | :obj:`~pyrogram.types.Photo` | :obj:`~pyrogram.types.Video`, *optional*):
Extended media.
"""
def __init__(
self,
*,
stars_amount: int,
):
super().__init__()
self.stars_amount = stars_amount
@staticmethod
def _parse(action: "raw.types.MessageActionPaidMessagesPrice") -> "PaidMessagePriceChanged":
return PaidMessagePriceChanged(
stars_amount=action.stars
)

View file

@ -56,9 +56,6 @@ class Chat(Object):
is_support (``bool``):
True, if this chat is part of the Telegram support team. Users and bots only.
is_forum (``bool``, *optional*):
True, if the supergroup chat is a forum
is_participants_hidden (``bool``, *optional*):
True, if the chat members are hidden.
Returned only in :meth:`~pyrogram.Client.get_chat`.
@ -170,6 +167,10 @@ class Chat(Object):
The linked discussion group (in case of channels) or the linked channel (in case of supergroups).
Returned only in :meth:`~pyrogram.Client.get_chat`.
linked_forum (:obj:`~pyrogram.types.Chat`, *optional*):
The linked monoforum (in case of channels) or the linked channel (in case of monoforum).
Returned only in :meth:`~pyrogram.Client.get_chat`.
send_as_chat (:obj:`~pyrogram.types.Chat`, *optional*):
The default "send_as" chat.
Returned only in :meth:`~pyrogram.Client.get_chat`.
@ -231,7 +232,6 @@ class Chat(Object):
is_scam: bool = None,
is_fake: bool = None,
is_support: bool = None,
is_forum: bool = None,
is_participants_hidden: bool = None,
is_join_request: bool = None,
is_join_to_send: bool = None,
@ -263,6 +263,7 @@ class Chat(Object):
permissions: "types.ChatPermissions" = None,
distance: int = None,
linked_chat: "types.Chat" = None,
linked_forum: "types.Chat" = None,
send_as_chat: "types.Chat" = None,
available_reactions: Optional["types.ChatReactions"] = None,
usernames: List["types.Username"] = None,
@ -286,7 +287,6 @@ class Chat(Object):
self.is_scam = is_scam
self.is_fake = is_fake
self.is_support = is_support
self.is_forum = is_forum
self.is_participants_hidden = is_participants_hidden
self.is_join_request = is_join_request
self.is_join_to_send = is_join_to_send
@ -318,6 +318,7 @@ class Chat(Object):
self.permissions = permissions
self.distance = distance
self.linked_chat = linked_chat
self.linked_forum = linked_forum
self.send_as_chat = send_as_chat
self.available_reactions = available_reactions
self.usernames = usernames
@ -394,6 +395,16 @@ class Chat(Object):
restriction_reason = getattr(channel, "restriction_reason", [])
user_name = getattr(channel, "username", None)
active_usernames = getattr(channel, "usernames", [])
if getattr(channel, "monoforum", None):
chat_type = enums.ChatType.MONOFORUM
elif getattr(channel, "forum", None):
chat_type = enums.ChatType.FORUM
elif getattr(channel, "megagroup", None):
chat_type = enums.ChatType.SUPERGROUP
elif getattr(channel, "broadcast", None):
chat_type = enums.ChatType.CHANNEL
else:
chat_type = enums.ChatType.GROUP
usernames = None
if len(active_usernames) >= 1:
usernames = []
@ -410,13 +421,12 @@ class Chat(Object):
return Chat(
id=peer_id,
type=enums.ChatType.SUPERGROUP if getattr(channel, "megagroup", None) else enums.ChatType.CHANNEL,
type=chat_type,
is_verified=getattr(channel, "verified", None),
is_restricted=getattr(channel, "restricted", None),
is_creator=getattr(channel, "creator", None),
is_scam=getattr(channel, "scam", None),
is_fake=getattr(channel, "fake", None),
is_forum=getattr(channel, "forum", None),
is_join_request=getattr(channel, "join_request", None),
is_join_to_send=getattr(channel, "join_to_send", None),
is_slowmode_enabled=getattr(channel, "slowmode_enabled", None),
@ -546,9 +556,14 @@ class Chat(Object):
linked_chat_raw = chats.get(full_chat.linked_chat_id, None)
linked_forum_raw = chats.get(getattr(chat_raw, "linked_monoforum_id"), None)
if linked_chat_raw:
parsed_chat.linked_chat = Chat._parse_channel_chat(client, linked_chat_raw)
if linked_forum_raw:
parsed_chat.linked_forum = Chat._parse_channel_chat(client, linked_forum_raw)
default_send_as = full_chat.default_send_as
if default_send_as: