Only keep MessageHandler

This commit is contained in:
Dan 2018-04-07 23:34:28 +02:00
parent 90a4e4c411
commit ee2d66b416
7 changed files with 11 additions and 107 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -16,8 +16,5 @@
# 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 .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

View File

@ -1,24 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <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 .handler import Handler
class ChannelPostHandler(Handler):
def __init__(self, callback: callable):
super().__init__(callback)

View File

@ -1,24 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <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 .handler import Handler
class EditedChannelPostHandler(Handler):
def __init__(self, callback: callable):
super().__init__(callback)

View File

@ -1,24 +0,0 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-2018 Dan Tès <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 .handler import Handler
class EditedMessageHandler(Handler):
def __init__(self, callback: callable):
super().__init__(callback)