diff --git a/pyrogram/__init__.py b/pyrogram/__init__.py index e0dfe473..e366ae20 100644 --- a/pyrogram/__init__.py +++ b/pyrogram/__init__.py @@ -34,7 +34,4 @@ from .client.input_media_photo import InputMediaPhoto from .client.input_media_video import InputMediaVideo from .client.input_phone_contact import InputPhoneContact from .client import Emoji -from .client.handler import ( - MessageHandler, EditedMessageHandler, ChannelPostHandler, - EditedChannelPostHandler -) +from .client.handler import MessageHandler diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index cd7fe030..0495fe56 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -189,25 +189,12 @@ class Client: self.dispatcher = Dispatcher(self, workers) self.update_handler = None - def on(self, handler, group: int): + def on_message(self, group: int = 0): def decorator(f): - self.add_handler(handler(f), group) - return f + self.add_handler(pyrogram.MessageHandler(f), group) return decorator - def on_message(self, group: int = 0): - return self.on(pyrogram.MessageHandler, group) - - def on_edited_message(self, group: int = 0): - return self.on(pyrogram.EditedMessageHandler, group) - - def on_channel_post(self, group: int = 0): - return self.on(pyrogram.ChannelPostHandler, group) - - def on_edited_channel_post(self, group: int = 0): - return self.on(pyrogram.EditedChannelPostHandler, group) - def add_handler(self, handler: Handler, group: int = 0): self.dispatcher.add_handler(handler, group) diff --git a/pyrogram/client/dispatcher/dispatcher.py b/pyrogram/client/dispatcher/dispatcher.py index 1584740d..58a17599 100644 --- a/pyrogram/client/dispatcher/dispatcher.py +++ b/pyrogram/client/dispatcher/dispatcher.py @@ -26,8 +26,7 @@ import pyrogram from pyrogram.api import types from . import message_parser from ..handler import ( - Handler, MessageHandler, EditedMessageHandler, - ChannelPostHandler, EditedChannelPostHandler + Handler, MessageHandler ) log = logging.getLogger(__name__) @@ -65,18 +64,14 @@ class Dispatcher: ) def dispatch(self, update): - if update.message: + message = (update.message + or update.channel_post + or update.edited_message + or update.edited_channel_post) + + if message: key = MessageHandler - value = update.message - elif update.edited_message: - key = EditedMessageHandler - value = update.edited_message - elif update.channel_post: - key = ChannelPostHandler - value = update.channel_post - elif update.edited_channel_post: - key = EditedChannelPostHandler - value = update.edited_channel_post + value = message else: return diff --git a/pyrogram/client/handler/__init__.py b/pyrogram/client/handler/__init__.py index f9366fd0..c86ca6ec 100644 --- a/pyrogram/client/handler/__init__.py +++ b/pyrogram/client/handler/__init__.py @@ -16,8 +16,5 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from .channel_post_handler import ChannelPostHandler -from .edited_channel_post_handler import EditedChannelPostHandler -from .edited_message_handler import EditedMessageHandler from .handler import Handler from .message_handler import MessageHandler diff --git a/pyrogram/client/handler/channel_post_handler.py b/pyrogram/client/handler/channel_post_handler.py deleted file mode 100644 index 35310d46..00000000 --- a/pyrogram/client/handler/channel_post_handler.py +++ /dev/null @@ -1,24 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# 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 . - -from .handler import Handler - - -class ChannelPostHandler(Handler): - def __init__(self, callback: callable): - super().__init__(callback) diff --git a/pyrogram/client/handler/edited_channel_post_handler.py b/pyrogram/client/handler/edited_channel_post_handler.py deleted file mode 100644 index fb5abd85..00000000 --- a/pyrogram/client/handler/edited_channel_post_handler.py +++ /dev/null @@ -1,24 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# 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 . - -from .handler import Handler - - -class EditedChannelPostHandler(Handler): - def __init__(self, callback: callable): - super().__init__(callback) diff --git a/pyrogram/client/handler/edited_message_handler.py b/pyrogram/client/handler/edited_message_handler.py deleted file mode 100644 index 05fb0690..00000000 --- a/pyrogram/client/handler/edited_message_handler.py +++ /dev/null @@ -1,24 +0,0 @@ -# Pyrogram - Telegram MTProto API Client Library for Python -# Copyright (C) 2017-2018 Dan Tès -# -# 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 . - -from .handler import Handler - - -class EditedMessageHandler(Handler): - def __init__(self, callback: callable): - super().__init__(callback)