mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2026-01-02 05:24:51 +00:00
Pyrofork: Move ListenerTypes to pyrogram.enums
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
d6e0a4f520
commit
b36a46efc0
18 changed files with 76 additions and 44 deletions
8
docs/source/api/enums/ListenerTypes.rst
Normal file
8
docs/source/api/enums/ListenerTypes.rst
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
ListenerTypes
|
||||
=============
|
||||
|
||||
.. autoclass:: pyrogram.enums.ListenerTypes()
|
||||
:members:
|
||||
|
||||
.. raw:: html
|
||||
:file: ./cleanup.html
|
||||
|
|
@ -45,7 +45,7 @@ from pyrogram.errors import CDNFileHashMismatch
|
|||
from pyrogram.errors import (
|
||||
SessionPasswordNeeded,
|
||||
VolumeLocNotFound, ChannelPrivate,
|
||||
BadRequest, ListenerTimeout,
|
||||
BadRequest
|
||||
)
|
||||
from pyrogram.handlers.handler import Handler
|
||||
from pyrogram.methods import Methods
|
||||
|
|
@ -57,7 +57,7 @@ except Exception:
|
|||
pass
|
||||
else:
|
||||
from pyrogram.storage import MongoStorage
|
||||
from pyrogram.types import User, TermsOfService, ListenerTypes
|
||||
from pyrogram.types import User, TermsOfService
|
||||
from pyrogram.utils import ainput
|
||||
from .dispatcher import Dispatcher
|
||||
from .file_id import FileId, FileType, ThumbnailSource
|
||||
|
|
@ -332,7 +332,7 @@ class Client(Methods):
|
|||
self.updates_watchdog_task = None
|
||||
self.updates_watchdog_event = asyncio.Event()
|
||||
self.last_update_time = datetime.now()
|
||||
self.listeners = {listener_type: [] for listener_type in ListenerTypes}
|
||||
self.listeners = {listener_type: [] for listener_type in pyrogram.enums.ListenerTypes}
|
||||
self.loop = asyncio.get_event_loop()
|
||||
|
||||
def __enter__(self):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ from .chat_event_action import ChatEventAction
|
|||
from .chat_member_status import ChatMemberStatus
|
||||
from .chat_members_filter import ChatMembersFilter
|
||||
from .chat_type import ChatType
|
||||
from .listerner_types import ListenerTypes
|
||||
from .message_entity_type import MessageEntityType
|
||||
from .message_media_type import MessageMediaType
|
||||
from .message_service_type import MessageServiceType
|
||||
|
|
@ -39,6 +40,7 @@ __all__ = [
|
|||
'ChatMemberStatus',
|
||||
'ChatMembersFilter',
|
||||
'ChatType',
|
||||
'ListenerTypes',
|
||||
'MessageEntityType',
|
||||
'MessageMediaType',
|
||||
'MessageServiceType',
|
||||
|
|
|
|||
32
pyrogram/enums/listerner_types.py
Normal file
32
pyrogram/enums/listerner_types.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# Pyrofork - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2020 Cezar H. <https://github.com/usernein>
|
||||
# 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 enum import auto
|
||||
|
||||
from .auto_name import AutoName
|
||||
|
||||
|
||||
class ListenerTypes(AutoName):
|
||||
"""Listener type enumeration used in :obj:`~pyrogram.types.Client`."""
|
||||
|
||||
MESSAGE = auto()
|
||||
"A Message"
|
||||
|
||||
CALLBACK_QUERY = auto()
|
||||
"A CallbackQuery"
|
||||
|
|
@ -22,7 +22,7 @@ from typing import Callable, Tuple
|
|||
import pyrogram
|
||||
|
||||
from pyrogram.utils import PyromodConfig
|
||||
from pyrogram.types import ListenerTypes, CallbackQuery, Identifier, Listener
|
||||
from pyrogram.types import CallbackQuery, Identifier, Listener
|
||||
|
||||
from .handler import Handler
|
||||
|
||||
|
|
@ -99,7 +99,7 @@ class CallbackQueryHandler(Handler):
|
|||
data = self.compose_data_identifier(query)
|
||||
|
||||
listener = client.get_listener_matching_with_data(
|
||||
data, ListenerTypes.CALLBACK_QUERY
|
||||
data, pyrogram.enums.ListenerTypes.CALLBACK_QUERY
|
||||
)
|
||||
|
||||
listener_does_match = False
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ from inspect import iscoroutinefunction
|
|||
from typing import Callable
|
||||
import pyrogram
|
||||
|
||||
from pyrogram.types import ListenerTypes, Message, Identifier
|
||||
from pyrogram.types import Message, Identifier
|
||||
|
||||
from .handler import Handler
|
||||
|
||||
|
|
@ -73,7 +73,7 @@ class MessageHandler(Handler):
|
|||
from_user_id=[from_user_id, from_user_username],
|
||||
)
|
||||
|
||||
listener = client.get_listener_matching_with_data(data, ListenerTypes.MESSAGE)
|
||||
listener = client.get_listener_matching_with_data(data, pyrogram.enums.ListenerTypes.MESSAGE)
|
||||
|
||||
listener_does_match = False
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import pyrogram
|
|||
|
||||
from pyrogram.filters import Filter
|
||||
from typing import List, Optional, Union
|
||||
from pyrogram.types import ListenerTypes
|
||||
|
||||
class Ask:
|
||||
async def ask(
|
||||
|
|
@ -29,7 +28,7 @@ class Ask:
|
|||
chat_id: Union[Union[int, str], List[Union[int, str]]],
|
||||
text: str,
|
||||
filters: Optional[Filter] = None,
|
||||
listener_type: ListenerTypes = ListenerTypes.MESSAGE,
|
||||
listener_type: "pyrogram.enums.ListenerTypes" = pyrogram.enums.ListenerTypes.MESSAGE,
|
||||
timeout: Optional[int] = None,
|
||||
unallowed_click_alert: bool = True,
|
||||
user_id: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
|
|
@ -61,7 +60,7 @@ class Ask:
|
|||
filters (:obj:`~pyrogram.filters`, *optional*):
|
||||
A filter to check the incoming message against.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`, *optional*):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`, *optional*):
|
||||
The type of listener to listen for.
|
||||
Default to Message.
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
import pyrogram
|
||||
|
||||
from typing import Optional
|
||||
from pyrogram.types import ListenerTypes, Identifier, Listener
|
||||
from pyrogram.types import Identifier, Listener
|
||||
|
||||
class GetListenerMatchingWithData:
|
||||
def get_listener_matching_with_data(
|
||||
self: "pyrogram.Client",
|
||||
data: Identifier,
|
||||
listener_type: ListenerTypes
|
||||
listener_type: "pyrogram.enums.ListenerTypes"
|
||||
) -> Optional[Listener]:
|
||||
"""Gets a listener that matches the given data.
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class GetListenerMatchingWithData:
|
|||
data (:obj:`~pyrogram.types.Identifier`):
|
||||
The Identifier to match agains.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`):
|
||||
The type of listener to get.
|
||||
|
||||
Returns:
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
import pyrogram
|
||||
|
||||
from typing import Optional
|
||||
from pyrogram.types import ListenerTypes, Identifier, Listener
|
||||
from pyrogram.types import Identifier, Listener
|
||||
|
||||
class GetListenerMatchingWithIdentifierPattern:
|
||||
def get_listener_matching_with_identifier_pattern(
|
||||
self: "pyrogram.Client",
|
||||
pattern: Identifier,
|
||||
listener_type: ListenerTypes
|
||||
listener_type: "pyrogram.enums.ListenerTypes"
|
||||
) -> Optional[Listener]:
|
||||
"""Gets a listener that matches the given identifier pattern.
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class GetListenerMatchingWithIdentifierPattern:
|
|||
pattern (:obj:`~pyrogram.types.Identifier`):
|
||||
The Identifier to match agains.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`):
|
||||
The type of listener to get.
|
||||
|
||||
Returns:
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
import pyrogram
|
||||
|
||||
from typing import List
|
||||
from pyrogram.types import ListenerTypes, Identifier, Listener
|
||||
from pyrogram.types import Identifier, Listener
|
||||
|
||||
class GetManyListenersMatchingWithData:
|
||||
def get_many_listeners_matching_with_data(
|
||||
self: "pyrogram.Client",
|
||||
data: Identifier,
|
||||
listener_type: ListenerTypes,
|
||||
listener_type: "pyrogram.enums.ListenerTypes",
|
||||
) -> List[Listener]:
|
||||
"""Gets multiple listener that matches the given data.
|
||||
|
||||
|
|
@ -36,7 +36,7 @@ class GetManyListenersMatchingWithData:
|
|||
data (:obj:`~pyrogram.types.Identifier`):
|
||||
The Identifier to match agains.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`):
|
||||
The type of listener to get.
|
||||
|
||||
Returns:
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
import pyrogram
|
||||
|
||||
from typing import List
|
||||
from pyrogram.types import ListenerTypes, Identifier, Listener
|
||||
from pyrogram.types import Identifier, Listener
|
||||
|
||||
class GetManyListenersMatchingWithIdentifierPattern:
|
||||
def get_many_listeners_matching_with_identifier_pattern(
|
||||
self: "pyrogram.Client",
|
||||
pattern: Identifier,
|
||||
listener_type: ListenerTypes,
|
||||
listener_type: "pyrogram.enums.ListenerTypes",
|
||||
) -> List[Listener]:
|
||||
"""Gets multiple listener that matches the given identifier pattern.
|
||||
|
||||
|
|
@ -40,7 +40,7 @@ class GetManyListenersMatchingWithIdentifierPattern:
|
|||
pattern (:obj:`~pyrogram.types.Identifier`):
|
||||
The Identifier to match agains.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`):
|
||||
The type of listener to get.
|
||||
|
||||
Returns:
|
||||
|
|
|
|||
|
|
@ -24,14 +24,14 @@ import pyrogram
|
|||
from pyrogram.errors import ListenerTimeout
|
||||
from pyrogram.filters import Filter
|
||||
from typing import List, Optional, Union
|
||||
from pyrogram.types import ListenerTypes, Identifier, Listener
|
||||
from pyrogram.types import Identifier, Listener
|
||||
from pyrogram.utils import PyromodConfig
|
||||
|
||||
class Listen:
|
||||
async def listen(
|
||||
self: "pyrogram.Client",
|
||||
filters: Optional[Filter] = None,
|
||||
listener_type: ListenerTypes = ListenerTypes.MESSAGE,
|
||||
listener_type: "pyrogram.enums.ListenerTypes" = pyrogram.enums.ListenerTypes.MESSAGE,
|
||||
timeout: Optional[int] = None,
|
||||
unallowed_click_alert: bool = True,
|
||||
chat_id: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
|
|
@ -59,7 +59,7 @@ class Listen:
|
|||
filters (:obj:`~pyrogram.filters`, *optional*):
|
||||
A filter to check the incoming message against.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`, *optional*):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`, *optional*):
|
||||
The type of listener to listen for.
|
||||
Default to Message.
|
||||
|
||||
|
|
|
|||
|
|
@ -21,14 +21,14 @@ import pyrogram
|
|||
|
||||
from pyrogram.filters import Filter
|
||||
from typing import Callable, List, Optional, Union
|
||||
from pyrogram.types import ListenerTypes, Identifier, Listener
|
||||
from pyrogram.types import Identifier, Listener
|
||||
|
||||
class RegisterNextStepHandler:
|
||||
def register_next_step_handler(
|
||||
self: "pyrogram.Client",
|
||||
callback: Callable,
|
||||
filters: Optional[Filter] = None,
|
||||
listener_type: ListenerTypes = ListenerTypes.MESSAGE,
|
||||
listener_type: "pyrogram.enums.ListenerTypes" = pyrogram.enums.ListenerTypes.MESSAGE,
|
||||
unallowed_click_alert: bool = True,
|
||||
chat_id: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
user_id: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
|
|
@ -49,7 +49,7 @@ class RegisterNextStepHandler:
|
|||
filters (:obj:`~pyrogram.filters`, *optional*):
|
||||
A filter to check the incoming message against.
|
||||
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`, *optional*):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`, *optional*):
|
||||
The type of listener to listen for.
|
||||
Default to Message.
|
||||
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@
|
|||
import pyrogram
|
||||
|
||||
from typing import List, Union
|
||||
from pyrogram.types import ListenerTypes, Identifier
|
||||
from pyrogram.types import Identifier
|
||||
|
||||
class StopListening:
|
||||
async def stop_listening(
|
||||
self: "pyrogram.Client",
|
||||
listener_type: ListenerTypes = ListenerTypes.MESSAGE,
|
||||
listener_type: "pyrogram.enums.ListenerTypes" = pyrogram.enums.ListenerTypes.MESSAGE,
|
||||
chat_id: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
user_id: Union[Union[int, str], List[Union[int, str]]] = None,
|
||||
message_id: Union[int, List[int]] = None,
|
||||
|
|
@ -38,7 +38,7 @@ class StopListening:
|
|||
Uses :meth:`~pyrogram.Client.get_many_listeners_matching_with_identifier_pattern`.
|
||||
|
||||
Parameters:
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`, *optional*):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`, *optional*):
|
||||
The type of listener to stop listening for.
|
||||
Default to Message.
|
||||
|
||||
|
|
|
|||
|
|
@ -575,7 +575,7 @@ class Message(Object, Update):
|
|||
|
||||
return await self._client.listen(
|
||||
(self.chat.id, from_user_id, self.id),
|
||||
listener_type=types.ListenerTypes.CALLBACK_QUERY,
|
||||
listener_type=pyrogram.enums.ListenerTypes.CALLBACK_QUERY,
|
||||
timeout=timeout,
|
||||
filters=filters,
|
||||
unallowed_click_alert=alert,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
from .identifier import Identifier
|
||||
from .listener import Listener
|
||||
from .listener_types import ListenerTypes
|
||||
|
||||
__all__ = ["Identifier", "Listener", "ListenerTypes"]
|
||||
__all__ = ["Identifier", "Listener"]
|
||||
|
|
@ -24,8 +24,6 @@ from typing import Callable
|
|||
import pyrogram
|
||||
|
||||
from .identifier import Identifier
|
||||
from .listener_types import ListenerTypes
|
||||
|
||||
|
||||
@dataclass
|
||||
class Listener:
|
||||
|
|
@ -33,7 +31,7 @@ class Listener:
|
|||
It enables you to wait for specific events like messages or callback queries and provides mechanisms for defining the conditions and filters that trigger these listeners.
|
||||
|
||||
Parameters:
|
||||
listener_type (:obj:`~pyrogram.types.ListenerTypes`):
|
||||
listener_type (:obj:`~pyrogram.enums.ListenerTypes`):
|
||||
The type of listener that specifies the event you want to listen for.
|
||||
It can be either a “message” or a “callback_query.”
|
||||
|
||||
|
|
@ -55,7 +53,7 @@ class Listener:
|
|||
callback (``Callable``, *optional*):
|
||||
The callback to call when the listener is fulfilled.
|
||||
"""
|
||||
listener_type: ListenerTypes
|
||||
listener_type: pyrogram.enums.ListenerTypes
|
||||
filters: "pyrogram.filters.Filter"
|
||||
unallowed_click_alert: bool
|
||||
identifier: Identifier
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
from enum import Enum
|
||||
|
||||
|
||||
class ListenerTypes(Enum):
|
||||
MESSAGE = "message"
|
||||
CALLBACK_QUERY = "callback_query"
|
||||
Loading…
Reference in a new issue