Skip to content

Commit

Permalink
pyrofork: Add get_stars_transaction method
Browse files Browse the repository at this point in the history
Signed-off-by: wulan17 <wulan17@nusantararom.org>
  • Loading branch information
wulan17 committed Jul 31, 2024
1 parent 2f71f64 commit c6a3114
Show file tree
Hide file tree
Showing 8 changed files with 293 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ def get_title_list(s: str) -> list:
Telegram Business
create_invoice_link
get_business_connection
get_stars_transactions
""",
authorization="""
Authorization
Expand Down Expand Up @@ -601,6 +602,11 @@ def get_title_list(s: str) -> list:
BotCommandScopeChatAdministrators
BotCommandScopeChatMember
""",
business="""
Telegram Business
StarsStatus
StarsTransaction
""",
input_media="""
Input Media
InputMedia
Expand Down
13 changes: 13 additions & 0 deletions compiler/docs/template/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@ Bot commands

{bot_commands}

Telegram Business
-------------

.. autosummary::
:nosignatures:

{business}

.. toctree::
:hidden:

{business}

Input Media
-----------

Expand Down
2 changes: 2 additions & 0 deletions pyrogram/methods/business/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@

from .create_invoice_link import CreateInvoiceLink
from .get_business_connection import GetBusinessConnection
from .get_stars_transactions import GetStarsTransactions


class TelegramBusiness(
CreateInvoiceLink,
GetBusinessConnection,
GetStarsTransactions
):
pass
72 changes: 72 additions & 0 deletions pyrogram/methods/business/get_stars_transactions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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
from pyrogram import types
from typing import Union, Optional, AsyncGenerator


class GetStarsTransactions:
async def get_stars_transactions(
self: "pyrogram.Client",
chat_id: Union[int, str] = "me",
limit: int = 0,
offset: str = "",
is_inbound: bool = None,
is_outbound: bool = None,
is_ascending: bool = None
) -> "types.StarsStatus":
"""Get stars transactions.
.. include:: /_includes/usable-by/users-bots.rst
Parameters:
chat_id (``int`` | ``str``, *optional*):
Unique identifier (int) or username (str) of the target user.
You can also use chat public link in form of *t.me/<username>* (str).
default to self.
limit (``int``, *optional*):
Limits the number of transactions to be retrieved.
offset (``str``, *optional*):
Offset the list of transactions to be retrieved.
is_inbound (``bool``, *optional*):
True, if only inbound transactions should be retrieved.
is_outbound (``bool``, *optional*):
True, if only outbound transactions should be retrieved.
is_ascending (``bool``, *optional*):
True, if transactions should be returned in ascending order.
"""
peer = await self.resolve_peer(chat_id)

r = await self.invoke(
raw.functions.payments.GetStarsTransactions(
peer=peer,
limit=limit,
offset=offset,
inbound=is_inbound,
outbound=is_outbound,
ascending=is_ascending
)
)
await types.StarsStatus._parse(self, r)
1 change: 1 addition & 0 deletions pyrogram/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from .authorization import *
from .bots_and_keyboards import *
from .business import *
from .inline_mode import *
from .input_media import *
from .input_message_content import *
Expand Down
25 changes: 25 additions & 0 deletions pyrogram/types/business/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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 .stars_status import StarsStatus
from .stars_transaction import StarsTransaction

__all__ = [
"StarsStatus",
"StarsTransaction"
]
52 changes: 52 additions & 0 deletions pyrogram/types/business/stars_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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 pyrogram import raw, types
from ..object import Object

class StarsStatus(Object):
"""Contains information about stars status.
Parameters:
balance (``int``):
Current balance of stars.
history (List of :obj:`~pyrogram.types.StarsTransaction`):
Stars transactions history.
"""
def __init__(
self,
*,
balance: int,
history: list
):
super().__init__()

self.balance = balance
self.history = history

@staticmethod
async def _parse(
client,
stars_status: "raw.types.StarsStatus"
) -> "StarsStatus":
users = {user.id: user for user in stars_status.users}
return StarsStatus(
balance=stars_status.balance,
history=[await types.StarsTransaction._parse(client, history, users) for history in stars_status.history]
)
122 changes: 122 additions & 0 deletions pyrogram/types/business/stars_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# 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 StarsTransaction(Object):
"""Contains information about stars transaction.
Parameters:
id (``int``):
Unique transaction identifier.
stars (``int``):
Amount of stars in the transaction.
date (:py:obj:`~datetime.datetime`):
Date of the transaction.
chat (:obj:`~pyrogram.types.Chat`):
Chat where the transaction was made.
is_refund (``bool``, *optional*):
True, If the transaction is a refund.
is_pending (``bool``, *optional*):
True, If the transaction is pending.
is_failed (``bool``, *optional*):
True, If the transaction failed.
title (``str``, *optional*):
Title of the transaction.
description (``str``, *optional*):
Description of the transaction.
transaction_date (:py:obj:`~datetime.datetime`, *optional*):
Date of the transaction.
transaction_url (``str``, *optional*):
URL of the transaction.
payload (``str``, *optional*):
Payload of the transaction.
message_id (``int``, *optional*):
Identifier of the message where the transaction was made.
""" # TODO photo, extended_media
def __init__(
self,
*,
id: int,
stars: int,
date: int,
chat: "types.Chat",
is_refund: bool = None,
is_pending: bool = None,
is_failed: bool = None,
title: str = None,
description: str = None,
transaction_date: int = None,
transaction_url: str = None,
payload: str = None,
message_id: int = None
):
super().__init__()

self.id = id
self.stars = stars
self.date = date
self.chat = chat
self.is_refund = is_refund
self.is_pending = is_pending
self.is_failed = is_failed
self.title = title
self.description = description
self.transaction_date = transaction_date
self.transaction_url = transaction_url
self.payload = payload
self.message_id = message_id

@staticmethod
async def _parse(
client,
transaction: "raw.types.StarsTransaction",
users: dict
) -> "StarsTransaction":
chat_id = utils.get_peer_id(utils.get_raw_peer_id(transaction.peer))
chat = await types.User._parse(client, users.get(chat_id, None))
return StarsTransaction(
id=transaction.id,
stars=transaction.stars,
date=transaction.date,
chat=chat,
is_refund=transaction.refund,
is_pending=transaction.pending,
is_failed=transaction.failed,
title=transaction.title,
description=transaction.description,
transaction_date=transaction.transaction_date,
transaction_url=transaction.transaction_url,
payload=transaction.bot_payload,
message_id=transaction.msg_id
)

0 comments on commit c6a3114

Please sign in to comment.