mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-03 14:04:51 +00:00
pyrofork: add InlineKeyboardButtonBuy and MessageInvoice
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
fac571aff9
commit
59461adc55
10 changed files with 161 additions and 3 deletions
|
|
@ -481,6 +481,7 @@ def pyrogram_api():
|
||||||
Giveaway
|
Giveaway
|
||||||
GiveawayLaunched
|
GiveawayLaunched
|
||||||
GiveawayResult
|
GiveawayResult
|
||||||
|
MessageInvoice
|
||||||
MessageStory
|
MessageStory
|
||||||
WebPage
|
WebPage
|
||||||
WebPageEmpty
|
WebPageEmpty
|
||||||
|
|
@ -536,6 +537,7 @@ def pyrogram_api():
|
||||||
ReplyKeyboardRemove
|
ReplyKeyboardRemove
|
||||||
InlineKeyboardMarkup
|
InlineKeyboardMarkup
|
||||||
InlineKeyboardButton
|
InlineKeyboardButton
|
||||||
|
InlineKeyboardButtonBuy
|
||||||
RequestPeerTypeChannel
|
RequestPeerTypeChannel
|
||||||
RequestPeerTypeChat
|
RequestPeerTypeChat
|
||||||
RequestPeerTypeUser
|
RequestPeerTypeUser
|
||||||
|
|
|
||||||
|
|
@ -78,3 +78,6 @@ class MessageMediaType(AutoName):
|
||||||
|
|
||||||
STORY = auto()
|
STORY = auto()
|
||||||
"Forwarded story media"
|
"Forwarded story media"
|
||||||
|
|
||||||
|
INVOICE = auto()
|
||||||
|
"Invoice media"
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ from .game_high_score import GameHighScore
|
||||||
from .inline_keyboard_button import InlineKeyboardButton
|
from .inline_keyboard_button import InlineKeyboardButton
|
||||||
from .inline_keyboard_markup import InlineKeyboardMarkup
|
from .inline_keyboard_markup import InlineKeyboardMarkup
|
||||||
from .keyboard_button import KeyboardButton
|
from .keyboard_button import KeyboardButton
|
||||||
|
from .inline_keyboard_button_buy import InlineKeyboardButtonBuy
|
||||||
from .login_url import LoginUrl
|
from .login_url import LoginUrl
|
||||||
from .menu_button import MenuButton
|
from .menu_button import MenuButton
|
||||||
from .menu_button_commands import MenuButtonCommands
|
from .menu_button_commands import MenuButtonCommands
|
||||||
|
|
@ -61,6 +62,7 @@ __all__ = [
|
||||||
"ForceReply",
|
"ForceReply",
|
||||||
"GameHighScore",
|
"GameHighScore",
|
||||||
"InlineKeyboardButton",
|
"InlineKeyboardButton",
|
||||||
|
"InlineKeyboardButtonBuy",
|
||||||
"InlineKeyboardMarkup",
|
"InlineKeyboardMarkup",
|
||||||
"KeyboardButton",
|
"KeyboardButton",
|
||||||
"ReplyKeyboardMarkup",
|
"ReplyKeyboardMarkup",
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,9 @@ class InlineKeyboardButton(Object):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if isinstance(b, raw.types.KeyboardButtonBuy):
|
||||||
|
return types.InlineKeyboardButtonBuy.read(b)
|
||||||
|
|
||||||
async def write(self, client: "pyrogram.Client"):
|
async def write(self, client: "pyrogram.Client"):
|
||||||
if self.callback_data is not None:
|
if self.callback_data is not None:
|
||||||
# Telegram only wants bytes, but we are allowed to pass strings too, for convenience.
|
# Telegram only wants bytes, but we are allowed to pass strings too, for convenience.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
# 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 ..object import Object
|
||||||
|
|
||||||
|
class InlineKeyboardButtonBuy(Object):
|
||||||
|
"""One button of the inline keyboard.
|
||||||
|
For simple invoice buttons.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
text (``str``):
|
||||||
|
Text of the button. If none of the optional fields are used, it will be sent as a message when
|
||||||
|
the button is pressed.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
text: str
|
||||||
|
):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.text = str(text)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def read(b):
|
||||||
|
return InlineKeyboardButtonBuy(
|
||||||
|
text=b.text
|
||||||
|
)
|
||||||
|
|
||||||
|
# TODO: Implement write method
|
||||||
|
|
@ -17,7 +17,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 Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrofork. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
from typing import List
|
from typing import List, Union
|
||||||
|
|
||||||
import pyrogram
|
import pyrogram
|
||||||
from pyrogram import raw
|
from pyrogram import raw
|
||||||
|
|
@ -33,7 +33,7 @@ class InlineKeyboardMarkup(Object):
|
||||||
List of button rows, each represented by a List of InlineKeyboardButton objects.
|
List of button rows, each represented by a List of InlineKeyboardButton objects.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, inline_keyboard: List[List["types.InlineKeyboardButton"]]):
|
def __init__(self, inline_keyboard: List[List[Union["types.InlineKeyboardButton", "types.InlineKeyboardButtonBuy"]]]):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.inline_keyboard = inline_keyboard
|
self.inline_keyboard = inline_keyboard
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ class ReplyKeyboardMarkup(Object):
|
||||||
placeholder=kb.placeholder
|
placeholder=kb.placeholder
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO: Implement KeyboardButtonBuy.write method
|
||||||
async def write(self, _: "pyrogram.Client"):
|
async def write(self, _: "pyrogram.Client"):
|
||||||
return raw.types.ReplyKeyboardMarkup(
|
return raw.types.ReplyKeyboardMarkup(
|
||||||
rows=[raw.types.KeyboardButtonRow(
|
rows=[raw.types.KeyboardButtonRow(
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,7 @@ from .web_app_data import WebAppData
|
||||||
from .web_page import WebPage
|
from .web_page import WebPage
|
||||||
from .web_page_empty import WebPageEmpty
|
from .web_page_empty import WebPageEmpty
|
||||||
from .web_page_preview import WebPagePreview
|
from .web_page_preview import WebPagePreview
|
||||||
|
from .message_invoice import MessageInvoice
|
||||||
from .message_reactions import MessageReactions
|
from .message_reactions import MessageReactions
|
||||||
from .message_reaction_updated import MessageReactionUpdated
|
from .message_reaction_updated import MessageReactionUpdated
|
||||||
from .message_reaction_count_updated import MessageReactionCountUpdated
|
from .message_reaction_count_updated import MessageReactionCountUpdated
|
||||||
|
|
@ -67,5 +68,5 @@ from .exported_story_link import ExportedStoryLink
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
"Animation", "Audio", "AvailableEffect", "Contact", "Document", "Game", "GiftedPremium", "Giveaway", "GiveawayLaunched", "GiveawayResult", "Location", "MediaArea", "MediaAreaChannelPost", "MediaAreaCoordinates", "Message", "MessageEntity", "Photo", "Thumbnail",
|
||||||
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
"StrippedThumbnail", "Poll", "PollOption", "Sticker", "StickerSet", "Venue", "Video", "VideoNote", "Voice", "WebPage", "WebPageEmpty", "WebPagePreview", "Dice",
|
||||||
"Reaction", "WebAppData", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
"Reaction", "WebAppData", "MessageInvoice", "MessageReactions", "ReactionCount", "ReactionType", "MessageReactionUpdated", "MessageReactionCountUpdated", "MessageStory", "Story", "StoryDeleted", "StorySkipped", "StoryViews", "StoryForwardHeader", "StoriesPrivacyRules", "ExportedStoryLink"
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -223,6 +223,9 @@ class Message(Object, Update):
|
||||||
giveaway_result (:obj:`~pyrogram.types.GiveawayResult`, *optional*):
|
giveaway_result (:obj:`~pyrogram.types.GiveawayResult`, *optional*):
|
||||||
Message is a giveaway result, information about the giveaway result.
|
Message is a giveaway result, information about the giveaway result.
|
||||||
|
|
||||||
|
invoice (:obj:`~pyrogram.types.MessageInvoice`, *optional*):
|
||||||
|
Message is an invoice for a payment, information about the invoice.
|
||||||
|
|
||||||
story (:obj:`~pyrogram.types.MessageStory` | :obj:`~pyrogram.types.Story`, *optional*):
|
story (:obj:`~pyrogram.types.MessageStory` | :obj:`~pyrogram.types.Story`, *optional*):
|
||||||
Message is a forwarded story, information about the forwarded story.
|
Message is a forwarded story, information about the forwarded story.
|
||||||
|
|
||||||
|
|
@ -472,6 +475,7 @@ class Message(Object, Update):
|
||||||
giveaway: "types.Giveaway" = None,
|
giveaway: "types.Giveaway" = None,
|
||||||
giveaway_result: "types.GiveawayResult" = None,
|
giveaway_result: "types.GiveawayResult" = None,
|
||||||
boosts_applied: int = None,
|
boosts_applied: int = None,
|
||||||
|
invoice: "types.MessageInvoice" = None,
|
||||||
story: Union["types.MessageStory", "types.Story"] = None,
|
story: Union["types.MessageStory", "types.Story"] = None,
|
||||||
video: "types.Video" = None,
|
video: "types.Video" = None,
|
||||||
voice: "types.Voice" = None,
|
voice: "types.Voice" = None,
|
||||||
|
|
@ -581,6 +585,7 @@ class Message(Object, Update):
|
||||||
self.giveaway = giveaway
|
self.giveaway = giveaway
|
||||||
self.giveaway_result = giveaway_result
|
self.giveaway_result = giveaway_result
|
||||||
self.boosts_applied = boosts_applied
|
self.boosts_applied = boosts_applied
|
||||||
|
self.invoice = invoice
|
||||||
self.story = story
|
self.story = story
|
||||||
self.video = video
|
self.video = video
|
||||||
self.voice = voice
|
self.voice = voice
|
||||||
|
|
@ -958,6 +963,7 @@ class Message(Object, Update):
|
||||||
game = None
|
game = None
|
||||||
giveaway = None
|
giveaway = None
|
||||||
giveaway_result = None
|
giveaway_result = None
|
||||||
|
invoice = None
|
||||||
story = None
|
story = None
|
||||||
audio = None
|
audio = None
|
||||||
voice = None
|
voice = None
|
||||||
|
|
@ -1054,6 +1060,9 @@ class Message(Object, Update):
|
||||||
elif isinstance(media, raw.types.MessageMediaDice):
|
elif isinstance(media, raw.types.MessageMediaDice):
|
||||||
dice = types.Dice._parse(client, media)
|
dice = types.Dice._parse(client, media)
|
||||||
media_type = enums.MessageMediaType.DICE
|
media_type = enums.MessageMediaType.DICE
|
||||||
|
elif isinstance(media, raw.types.MessageMediaInvoice):
|
||||||
|
invoice = types.MessageInvoice._parse(media)
|
||||||
|
media = enums.MessageMediaType.INVOICE
|
||||||
else:
|
else:
|
||||||
media = None
|
media = None
|
||||||
|
|
||||||
|
|
@ -1137,6 +1146,7 @@ class Message(Object, Update):
|
||||||
game=game,
|
game=game,
|
||||||
giveaway=giveaway,
|
giveaway=giveaway,
|
||||||
giveaway_result=giveaway_result,
|
giveaway_result=giveaway_result,
|
||||||
|
invoice=invoice,
|
||||||
story=story,
|
story=story,
|
||||||
video=video,
|
video=video,
|
||||||
video_note=video_note,
|
video_note=video_note,
|
||||||
|
|
|
||||||
91
pyrogram/types/messages_and_media/message_invoice.py
Normal file
91
pyrogram/types/messages_and_media/message_invoice.py
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
# 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/>.
|
||||||
|
|
||||||
|
import pyrogram
|
||||||
|
|
||||||
|
from pyrogram import raw, types, utils
|
||||||
|
from ..object import Object
|
||||||
|
|
||||||
|
|
||||||
|
class MessageInvoice(Object):
|
||||||
|
"""Contains information about an Invoice.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
title (``str``):
|
||||||
|
Product name.
|
||||||
|
|
||||||
|
description (``str``):
|
||||||
|
Product description.
|
||||||
|
|
||||||
|
currency (``str``):
|
||||||
|
Currency code.
|
||||||
|
|
||||||
|
total_amount (``int``):
|
||||||
|
Total price in the smallest units of the currency.
|
||||||
|
|
||||||
|
start_parameter (``str``):
|
||||||
|
Unique bot deep-linking parameter that can be used to generate this invoice.
|
||||||
|
|
||||||
|
shipping_address_requested (``bool``, *optional*):
|
||||||
|
True, if the the shipping address is requested.
|
||||||
|
|
||||||
|
test (``bool``, *optional*):
|
||||||
|
True, if the invoice is a test invoice.
|
||||||
|
|
||||||
|
receipt_message_id (``int``, *optional*):
|
||||||
|
The message_id of the message sent to the chat when the invoice is paid.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
*,
|
||||||
|
title: str,
|
||||||
|
description : str,
|
||||||
|
currency: str,
|
||||||
|
total_amount: int,
|
||||||
|
start_parameter: str,
|
||||||
|
shipping_address_requested: bool = None,
|
||||||
|
test: bool = None,
|
||||||
|
receipt_message_id: int = None,
|
||||||
|
# TODO: Implement photo, extended_media parameters
|
||||||
|
):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.title = title
|
||||||
|
self.description = description
|
||||||
|
self.currency = currency
|
||||||
|
self.total_amount = total_amount
|
||||||
|
self.start_parameter = start_parameter
|
||||||
|
self.shipping_address_requested = shipping_address_requested
|
||||||
|
self.test = test
|
||||||
|
self.receipt_message_id = receipt_message_id
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _parse(
|
||||||
|
message_invoice: "raw.types.MessageMediaInvoice"
|
||||||
|
) -> "MessageInvoice":
|
||||||
|
return MessageInvoice(
|
||||||
|
title=message_invoice.title,
|
||||||
|
description=message_invoice.description,
|
||||||
|
currency=message_invoice.currency,
|
||||||
|
total_amount=message_invoice.total_amount,
|
||||||
|
start_parameter=message_invoice.start_param,
|
||||||
|
shipping_address_requested=message_invoice.shipping_address_requested,
|
||||||
|
test=message_invoice.test,
|
||||||
|
receipt_message_id=message_invoice.receipt_msg_id
|
||||||
|
)
|
||||||
Loading…
Reference in a new issue