mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Only keep MessageHandler
This commit is contained in:
parent
90a4e4c411
commit
ee2d66b416
@ -34,7 +34,4 @@ from .client.input_media_photo import InputMediaPhoto
|
|||||||
from .client.input_media_video import InputMediaVideo
|
from .client.input_media_video import InputMediaVideo
|
||||||
from .client.input_phone_contact import InputPhoneContact
|
from .client.input_phone_contact import InputPhoneContact
|
||||||
from .client import Emoji
|
from .client import Emoji
|
||||||
from .client.handler import (
|
from .client.handler import MessageHandler
|
||||||
MessageHandler, EditedMessageHandler, ChannelPostHandler,
|
|
||||||
EditedChannelPostHandler
|
|
||||||
)
|
|
||||||
|
@ -189,25 +189,12 @@ class Client:
|
|||||||
self.dispatcher = Dispatcher(self, workers)
|
self.dispatcher = Dispatcher(self, workers)
|
||||||
self.update_handler = None
|
self.update_handler = None
|
||||||
|
|
||||||
def on(self, handler, group: int):
|
def on_message(self, group: int = 0):
|
||||||
def decorator(f):
|
def decorator(f):
|
||||||
self.add_handler(handler(f), group)
|
self.add_handler(pyrogram.MessageHandler(f), group)
|
||||||
return f
|
|
||||||
|
|
||||||
return decorator
|
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):
|
def add_handler(self, handler: Handler, group: int = 0):
|
||||||
self.dispatcher.add_handler(handler, group)
|
self.dispatcher.add_handler(handler, group)
|
||||||
|
|
||||||
|
@ -26,8 +26,7 @@ import pyrogram
|
|||||||
from pyrogram.api import types
|
from pyrogram.api import types
|
||||||
from . import message_parser
|
from . import message_parser
|
||||||
from ..handler import (
|
from ..handler import (
|
||||||
Handler, MessageHandler, EditedMessageHandler,
|
Handler, MessageHandler
|
||||||
ChannelPostHandler, EditedChannelPostHandler
|
|
||||||
)
|
)
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -65,18 +64,14 @@ class Dispatcher:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def dispatch(self, update):
|
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
|
key = MessageHandler
|
||||||
value = update.message
|
value = 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
|
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -16,8 +16,5 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# 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 .handler import Handler
|
||||||
from .message_handler import MessageHandler
|
from .message_handler import MessageHandler
|
||||||
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
|
Loading…
Reference in New Issue
Block a user