Skip to content

Commit

Permalink
Add new files.
Browse files Browse the repository at this point in the history
Signed-off-by: Aliwoto <[email protected]>
  • Loading branch information
ALiwoto committed Jun 6, 2024
1 parent 6e16ae7 commit bf207c8
Show file tree
Hide file tree
Showing 31 changed files with 2,213 additions and 0 deletions.
49 changes: 49 additions & 0 deletions pyrogram/enums/client_platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from enum import auto

from .auto_name import AutoName


class ClientPlatform(AutoName):
"""Valid platforms for a :obj:`~pyrogram.Client`."""

ANDROID = auto()
"Android"

IOS = auto()
"iOS"

WP = auto()
"Windows Phone"

BB = auto()
"Blackberry"

DESKTOP = auto()
"Desktop"

WEB = auto()
"Web"

UBP = auto()
"Ubuntu Phone"

OTHER = auto()
"Other"
49 changes: 49 additions & 0 deletions pyrogram/handlers/pre_checkout_query_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable

from .handler import Handler


class PreCheckoutQueryHandler(Handler):
"""The PreCheckoutQueryHandler handler class. Used to handle pre-checkout queries coming from buy buttons.
It is intended to be used with :meth:`~pyrogram.Client.add_handler`
For a nicer way to register this handler, have a look at the
:meth:`~pyrogram.Client.on_pre_checkout_query` decorator.
Parameters:
callback (``Callable``):
Pass a function that will be called when a new PreCheckoutQuery arrives. It takes *(client, pre_checkout_query)*
as positional arguments (look at the section below for a detailed description).
filters (:obj:`Filters`):
Pass one or more filters to allow only a subset of callback queries to be passed
in your callback function.
Other parameters:
client (:obj:`~pyrogram.Client`):
The Client itself, useful when you want to call other API methods inside the message handler.
pre_checkout_query (:obj:`~pyrogram.types.PreCheckoutQuery`):
The received callback query.
"""

def __init__(self, callback: Callable, filters=None):
super().__init__(callback, filters)
64 changes: 64 additions & 0 deletions pyrogram/methods/bots/answer_pre_checkout_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import pyrogram
from pyrogram import raw


class AnswerPreCheckoutQuery:
async def answer_pre_checkout_query(
self: "pyrogram.Client",
pre_checkout_query_id: str,
success: bool = None,
error: str = None
):
"""Send answers to pre-checkout queries.
.. include:: /_includes/usable-by/bots.rst
Parameters:
pre_checkout_query_id (``str``):
Unique identifier for the query to be answered.
success (``bool``, *optional*):
Set this flag if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order.
Otherwise do not set it, and set the error field, instead.
error (``str``, *optional*):
Error message in human readable form that explains the reason for failure to proceed with the checkout.
Required if ``success`` isn't set.
Returns:
``bool``: True, on success.
Example:
.. code-block:: python
# Proceed with the order
await app.answer_pre_checkout_query(query_id, success=True)
# Answer with error message
await app.answer_pre_checkout_query(query_id, error=error)
"""
return await self.invoke(
raw.functions.messages.SetBotPrecheckoutResults(
query_id=int(pre_checkout_query_id),
success=success or None,
error=error or None
)
)
25 changes: 25 additions & 0 deletions pyrogram/methods/business/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from .get_business_connection import GetBusinessConnection


class Business(
GetBusinessConnection
):
pass
54 changes: 54 additions & 0 deletions pyrogram/methods/business/get_business_connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import pyrogram
from pyrogram import raw, types


class GetBusinessConnection:
async def get_business_connection(
self: "pyrogram.Client",
connection_id: str
):
"""Get a business connection information.
.. include:: /_includes/usable-by/users-bots.rst
Parameters:
connection_id (``str``):
Unique identifier of the business connection.
Returns:
:obj:`~pyrogram.types.BusinessConnection`: On success the business connection is returned.
Example:
.. code-block:: python
# Get a business connection information
app.get_business_connection(connection_id)
"""
r = await self.invoke(
raw.functions.account.GetBotBusinessConnection(
connection_id=connection_id
)
)

users = {i.id: i for i in r.users}
chats = {i.id: i for i in r.chats}

return types.BusinessConnection._parse(self, r.updates[0].connection, users)
48 changes: 48 additions & 0 deletions pyrogram/methods/chats/get_personal_channels.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import List, Optional

import pyrogram
from pyrogram import raw, types


class GetPersonalChannels:
async def get_personal_channels(
self: "pyrogram.Client"
) -> Optional[List["types.Chat"]]:
"""Get all your public channels.
.. include:: /_includes/usable-by/users.rst
Returns:
List of :obj:`~pyrogram.types.Chat`: On success, a list of personal channels is returned.
Example:
.. code-block:: python
# Get all your personal channels
await app.get_personal_channels()
"""
r = await self.invoke(
raw.functions.channels.GetAdminedPublicChannels(
for_personal=True
)
)

return types.List(types.Chat._parse_chat(self, i) for i in r.chats) or None
61 changes: 61 additions & 0 deletions pyrogram/methods/decorators/on_pre_checkout_query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram 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.
#
# Pyrogram 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 Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Callable, Optional, Union

import pyrogram
from pyrogram.filters import Filter


class OnPreCheckoutQuery:
def on_pre_checkout_query(
self: Union["OnPreCheckoutQuery", Filter, None] = None,
filters: Optional[Filter] = None,
group: int = 0,
) -> Callable:
"""Decorator for handling pre-checkout queries.
This does the same thing as :meth:`~pyrogram.Client.add_handler` using the
:obj:`~pyrogram.handlers.PreCheckoutQueryHandler`.
Parameters:
filters (:obj:`~pyrogram.filters`, *optional*):
Pass one or more filters to allow only a subset of callback queries to be passed
in your function.
group (``int``, *optional*):
The group identifier, defaults to 0.
"""

def decorator(func: Callable) -> Callable:
if isinstance(self, pyrogram.Client):
self.add_handler(pyrogram.handlers.PreCheckoutQueryHandler(func, filters), group)
elif isinstance(self, Filter) or self is None:
if not hasattr(func, "handlers"):
func.handlers = []

func.handlers.append(
(
pyrogram.handlers.PreCheckoutQueryHandler(func, self),
group if filters is None else filters
)
)

return func

return decorator
Loading

0 comments on commit bf207c8

Please sign in to comment.