Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pyrogram/handlers/callback_query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
# 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 Any, Callable

import pyrogram
from pyrogram.filters import Filter
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.CallbackQuery], Any]

class CallbackQueryHandler(Handler):
"""The CallbackQuery handler class. Used to handle callback queries coming from inline buttons.
Expand All @@ -27,21 +33,21 @@ class CallbackQueryHandler(Handler):
:meth:`~pyrogram.Client.on_callback_query` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a new CallbackQuery arrives. It takes *(client, callback_query)*
as positional arguments (look at the section below for a detailed description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
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.
The Client itself, useful when you want to call other API methods inside the callback query handler.

callback_query (:obj:`~pyrogram.types.CallbackQuery`):
The received callback query.
"""

def __init__(self, callback: callable, filters=None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)
16 changes: 12 additions & 4 deletions pyrogram/handlers/chat_member_updated_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# 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 Any, Callable

import pyrogram
from pyrogram.filters import Filter
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.ChatMemberUpdated], Any]


class ChatMemberUpdatedHandler(Handler):
"""The ChatMemberUpdated handler class. Used to handle changes in the status of a chat member.
Expand All @@ -27,21 +34,22 @@ class ChatMemberUpdatedHandler(Handler):
:meth:`~pyrogram.Client.on_chat_member_updated` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a new ChatMemberUpdated event arrives. It takes
*(client, chat_member_updated)* as positional arguments (look at the section below for a detailed
description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
Pass one or more filters to allow only a subset of updates 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 handler.
The Client itself, useful when you want to call other API methods inside the chat member updated
handler.

chat_member_updated (:obj:`~pyrogram.types.ChatMemberUpdated`):
The received chat member update.
"""

def __init__(self, callback: callable, filters=None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)
16 changes: 12 additions & 4 deletions pyrogram/handlers/chosen_inline_result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# 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 Any, Callable

import pyrogram
from pyrogram.filters import Filter
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.ChosenInlineResult], Any]


class ChosenInlineResultHandler(Handler):
"""The ChosenInlineResultHandler handler class. Used to handle chosen inline results coming from inline queries.
Expand All @@ -27,22 +34,23 @@ class ChosenInlineResultHandler(Handler):
:meth:`~pyrogram.Client.on_chosen_inline_result` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a new chosen inline result arrives.
It takes *(client, chosen_inline_result)* as positional arguments (look at the section below for a
detailed description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
Pass one or more filters to allow only a subset of chosen inline results 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.
The Client itself, useful when you want to call other API methods inside the choose inline result
handler.

chosen_inline_result (:obj:`~pyrogram.types.ChosenInlineResult`):
The received chosen inline result.
"""

def __init__(self, callback: callable, filters=None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)
15 changes: 9 additions & 6 deletions pyrogram/handlers/deleted_messages_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
# 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, Callable
from typing import Any, Callable, List

import pyrogram
from pyrogram.filters import Filter
from pyrogram.types import Message
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
List[pyrogram.types.Message]], Any]


class DeletedMessagesHandler(Handler):
"""The deleted messages handler class. Used to handle deleted messages coming from any chat
Expand All @@ -32,26 +35,26 @@ class DeletedMessagesHandler(Handler):
:meth:`~pyrogram.Client.on_deleted_messages` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when one or more messages have been deleted.
It takes *(client, messages)* as positional arguments (look at the section below for a detailed description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
Pass one or more filters to allow only a subset of messages 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.
The Client itself, useful when you want to call other API methods inside the deleted message handler.

messages (List of :obj:`~pyrogram.types.Message`):
The deleted messages, as list.
"""

def __init__(self, callback: Callable, filters: Filter = None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)

async def check(self, client: "pyrogram.Client", messages: List[Message]):
async def check(self, client: "pyrogram.Client", messages: List[Message]) -> bool:
# Every message should be checked, if at least one matches the filter True is returned
# otherwise, or if the list is empty, False is returned
for message in messages:
Expand Down
9 changes: 7 additions & 2 deletions pyrogram/handlers/disconnect_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
# 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 Any, Callable

import pyrogram
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client"], Any]


class DisconnectHandler(Handler):
"""The Disconnect handler class. Used to handle disconnections. It is intended to be used with
Expand All @@ -27,7 +32,7 @@ class DisconnectHandler(Handler):
:meth:`~pyrogram.Client.on_disconnect` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a disconnection occurs. It takes *(client)*
as positional argument (look at the section below for a detailed description).

Expand All @@ -37,5 +42,5 @@ class DisconnectHandler(Handler):
is established.
"""

def __init__(self, callback: callable):
def __init__(self, callback: CallbackFunc):
super().__init__(callback)
6 changes: 4 additions & 2 deletions pyrogram/handlers/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

import inspect
from typing import Callable
from typing import Any, Callable

import pyrogram
from pyrogram.filters import Filter
from pyrogram.types import Update

CallbackFunc: Callable = Callable[..., Any]


class Handler:
def __init__(self, callback: Callable, filters: Filter = None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
self.callback = callback
self.filters = filters

Expand Down
13 changes: 10 additions & 3 deletions pyrogram/handlers/inline_query_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# 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 Any, Callable

import pyrogram
from pyrogram.filters import Filter
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.InlineQuery], Any]


class InlineQueryHandler(Handler):
"""The InlineQuery handler class. Used to handle inline queries.
Expand All @@ -27,11 +34,11 @@ class InlineQueryHandler(Handler):
:meth:`~pyrogram.Client.on_inline_query` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a new InlineQuery arrives. It takes *(client, inline_query)*
as positional arguments (look at the section below for a detailed description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
Pass one or more filters to allow only a subset of inline queries to be passed
in your callback function.

Expand All @@ -43,5 +50,5 @@ class InlineQueryHandler(Handler):
The received inline query.
"""

def __init__(self, callback: callable, filters=None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)
13 changes: 10 additions & 3 deletions pyrogram/handlers/message_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# 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 Any, Callable

import pyrogram
from pyrogram.filters import Filter
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.Message], Any]


class MessageHandler(Handler):
"""The Message handler class. Used to handle text, media and service messages coming from
Expand All @@ -27,11 +34,11 @@ class MessageHandler(Handler):
:meth:`~pyrogram.Client.on_message` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a new Message arrives. It takes *(client, message)*
as positional arguments (look at the section below for a detailed description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
Pass one or more filters to allow only a subset of messages to be passed
in your callback function.

Expand All @@ -43,5 +50,5 @@ class MessageHandler(Handler):
The received message.
"""

def __init__(self, callback: callable, filters=None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)
13 changes: 10 additions & 3 deletions pyrogram/handlers/poll_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@
# 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 Any, Callable

import pyrogram
from pyrogram.filters import Filter
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.Poll], Any]


class PollHandler(Handler):
"""The Poll handler class. Used to handle polls updates.
Expand All @@ -28,11 +35,11 @@ class PollHandler(Handler):
:meth:`~pyrogram.Client.on_poll` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
Pass a function that will be called when a new poll update arrives. It takes *(client, poll)*
as positional arguments (look at the section below for a detailed description).

filters (:obj:`Filters`):
filters (:obj:`Filter`):
Pass one or more filters to allow only a subset of polls to be passed
in your callback function.

Expand All @@ -44,5 +51,5 @@ class PollHandler(Handler):
The received poll.
"""

def __init__(self, callback: callable, filters=None):
def __init__(self, callback: CallbackFunc, filters: Filter = None):
super().__init__(callback, filters)
10 changes: 8 additions & 2 deletions pyrogram/handlers/raw_update_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
# 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 Any, Callable

import pyrogram
from .handler import Handler

CallbackFunc: Callable = Callable[["pyrogram.Client",
pyrogram.types.Update, Any, Any], Any]


class RawUpdateHandler(Handler):
"""The Raw Update handler class. Used to handle raw updates. It is intended to be used with
Expand All @@ -27,7 +33,7 @@ class RawUpdateHandler(Handler):
:meth:`~pyrogram.Client.on_raw_update` decorator.

Parameters:
callback (``callable``):
callback (``Callable``):
A function that will be called when a new update is received from the server. It takes
*(client, update, users, chats)* as positional arguments (look at the section below for
a detailed description).
Expand Down Expand Up @@ -61,5 +67,5 @@ class RawUpdateHandler(Handler):
- :obj:`~pyrogram.raw.types.ChannelForbidden`
"""

def __init__(self, callback: callable):
def __init__(self, callback: CallbackFunc):
super().__init__(callback)
Loading