mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 20:14:51 +00:00
pyrofork: Add reply_markup parameter to Client.send_invoice
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
0a844bd5ed
commit
c8d2c6a152
3 changed files with 31 additions and 3 deletions
|
|
@ -39,6 +39,7 @@ class SendInvoice:
|
|||
message_thread_id: int = None,
|
||||
quote_text: str = None,
|
||||
quote_entities: List["types.MessageEntity"] = None,
|
||||
reply_markup: "types.InlineKeyboardMarkup" = None
|
||||
):
|
||||
"""Use this method to send invoices.
|
||||
|
||||
|
|
@ -96,6 +97,9 @@ class SendInvoice:
|
|||
List of special entities that appear in quote_text, which can be specified instead of *parse_mode*.
|
||||
for reply_to_message only.
|
||||
|
||||
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
|
||||
An inline keyboard. If empty, one 'Buy' button will be shown.
|
||||
|
||||
Returns:
|
||||
:obj:`~pyrogram.types.Message`: On success, the sent message is returned.
|
||||
|
||||
|
|
@ -112,6 +116,21 @@ class SendInvoice:
|
|||
))
|
||||
"""
|
||||
|
||||
if reply_markup is not None:
|
||||
has_buy_button = False
|
||||
for i in reply_markup.inline_keyboard:
|
||||
for j in i:
|
||||
if isinstance(j, types.InlineKeyboardButtonBuy):
|
||||
has_buy_button = True
|
||||
if not has_buy_button:
|
||||
text = "Pay"
|
||||
if currency == "XTR":
|
||||
prices_total = 0
|
||||
for price in prices:
|
||||
prices_total += price.amount
|
||||
text = f"Pay ⭐️{prices_total}"
|
||||
reply_markup.inline_keyboard.insert(0, [types.InlineKeyboardButtonBuy(text=text)])
|
||||
|
||||
reply_to = await utils.get_reply_to(
|
||||
client=self,
|
||||
chat_id=chat_id,
|
||||
|
|
@ -145,7 +164,8 @@ class SendInvoice:
|
|||
),
|
||||
random_id=self.rnd_id(),
|
||||
reply_to=reply_to,
|
||||
message=""
|
||||
message="",
|
||||
reply_markup=await reply_markup.write(self) if reply_markup is not None else None
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,12 @@
|
|||
#
|
||||
# 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 ..object import Object
|
||||
|
||||
from pyrogram import raw
|
||||
|
||||
class InlineKeyboardButtonBuy(Object):
|
||||
"""One button of the inline keyboard.
|
||||
For simple invoice buttons.
|
||||
|
|
@ -42,4 +45,7 @@ class InlineKeyboardButtonBuy(Object):
|
|||
text=b.text
|
||||
)
|
||||
|
||||
# TODO: Implement write method
|
||||
async def write(self, _: "pyrogram.Client"):
|
||||
return raw.types.KeyboardButtonBuy(
|
||||
text=self.text
|
||||
)
|
||||
|
|
|
|||
|
|
@ -29,8 +29,10 @@ class InlineKeyboardMarkup(Object):
|
|||
"""An inline keyboard that appears right next to the message it belongs to.
|
||||
|
||||
Parameters:
|
||||
inline_keyboard (List of List of :obj:`~pyrogram.types.InlineKeyboardButton`):
|
||||
inline_keyboard (List of List of :obj:`~pyrogram.types.InlineKeyboardButton` | :obj:`~pyrogram.types.InlineKeyboardButtonBuy`):
|
||||
List of button rows, each represented by a List of InlineKeyboardButton objects.
|
||||
:obj:`~pyrogram.types.InlineKeyboardButtonBuy` objects is only for :meth:`~pyrogram.Client.send_invoice`.
|
||||
and only one needed in the first row.
|
||||
"""
|
||||
|
||||
def __init__(self, inline_keyboard: List[List[Union["types.InlineKeyboardButton", "types.InlineKeyboardButtonBuy"]]]):
|
||||
|
|
|
|||
Loading…
Reference in a new issue