mirror of
https://github.com/Mayuri-Chan/pyrofork.git
synced 2025-12-29 12:04:51 +00:00
pyrofork: Update ChatMemberUpdatedHandler to support UpdateBotStopped updates
Signed-off-by: wulan17 <wulan17@nusantararom.org>
This commit is contained in:
parent
b7dcc5b298
commit
f03f5ffd79
3 changed files with 36 additions and 7 deletions
|
|
@ -53,7 +53,7 @@ from pyrogram.raw.types import (
|
|||
UpdateDeleteMessages, UpdateDeleteChannelMessages,
|
||||
UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery,
|
||||
UpdateUserStatus, UpdateBotInlineQuery, UpdateMessagePoll,
|
||||
UpdateBotInlineSend, UpdateChatParticipant, UpdateChannelParticipant,
|
||||
UpdateBotInlineSend, UpdateChatParticipant, UpdateChannelParticipant, UpdateBotStopped,
|
||||
UpdateBotChatInviteRequester, UpdateStory,
|
||||
UpdateBotMessageReaction,
|
||||
UpdateBotMessageReactions
|
||||
|
|
@ -70,7 +70,7 @@ class Dispatcher:
|
|||
DELETE_MESSAGES_UPDATES = (UpdateDeleteMessages, UpdateDeleteChannelMessages)
|
||||
DELETE_BOT_BUSINESS_MESSAGES_UPDATES = (UpdateBotDeleteBusinessMessage,)
|
||||
CALLBACK_QUERY_UPDATES = (UpdateBotCallbackQuery, UpdateInlineBotCallbackQuery)
|
||||
CHAT_MEMBER_UPDATES = (UpdateChatParticipant, UpdateChannelParticipant)
|
||||
CHAT_MEMBER_UPDATES = (UpdateChatParticipant, UpdateChannelParticipant, UpdateBotStopped,)
|
||||
USER_STATUS_UPDATES = (UpdateUserStatus,)
|
||||
BOT_INLINE_QUERY_UPDATES = (UpdateBotInlineQuery,)
|
||||
POLL_UPDATES = (UpdateMessagePoll,)
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ from .auto_name import AutoName
|
|||
class ChatMemberStatus(AutoName):
|
||||
"""Chat member status enumeration used in :obj:`~pyrogram.types.ChatMember`."""
|
||||
|
||||
OWNER = auto()
|
||||
OWNER = auto() # TODO: rename to 'creator'
|
||||
"Chat owner"
|
||||
|
||||
ADMINISTRATOR = auto()
|
||||
|
|
@ -40,5 +40,5 @@ class ChatMemberStatus(AutoName):
|
|||
LEFT = auto()
|
||||
"Left chat member"
|
||||
|
||||
BANNED = auto()
|
||||
BANNED = auto() # TODO: rename to 'kicked'
|
||||
"Banned chat member"
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ from datetime import datetime
|
|||
from typing import Dict, Union
|
||||
|
||||
import pyrogram
|
||||
from pyrogram import raw, utils
|
||||
from pyrogram import types
|
||||
from pyrogram import enums, raw, types, utils
|
||||
from ..object import Object
|
||||
from ..update import Update
|
||||
|
||||
|
|
@ -78,10 +77,40 @@ class ChatMemberUpdated(Object, Update):
|
|||
@staticmethod
|
||||
def _parse(
|
||||
client: "pyrogram.Client",
|
||||
update: Union["raw.types.UpdateChatParticipant", "raw.types.UpdateChannelParticipant"],
|
||||
update: Union["raw.types.UpdateChatParticipant", "raw.types.UpdateChannelParticipant", "raw.types.UpdateBotStopped"],
|
||||
users: Dict[int, "raw.types.User"],
|
||||
chats: Dict[int, "raw.types.Chat"]
|
||||
) -> "ChatMemberUpdated":
|
||||
if isinstance(update, raw.types.UpdateBotStopped):
|
||||
from_user = types.User._parse(client, users[update.user_id])
|
||||
_chat_member_one = types.ChatMember(
|
||||
user=from_user,
|
||||
status=enums.ChatMemberStatus.BANNED,
|
||||
client=client
|
||||
)
|
||||
_chat_member_two = types.ChatMember(
|
||||
user=from_user,
|
||||
status=enums.ChatMemberStatus.MEMBER,
|
||||
client=client
|
||||
)
|
||||
if update.stopped:
|
||||
return ChatMemberUpdated(
|
||||
chat=types.Chat._parse_chat(client, users[update.user_id]),
|
||||
from_user=from_user,
|
||||
date=utils.timestamp_to_datetime(update.date),
|
||||
old_chat_member=_chat_member_two,
|
||||
new_chat_member=_chat_member_one,
|
||||
client=client
|
||||
)
|
||||
return ChatMemberUpdated(
|
||||
chat=types.Chat._parse_chat(client, users[update.user_id]),
|
||||
from_user=from_user,
|
||||
date=utils.timestamp_to_datetime(update.date),
|
||||
old_chat_member=_chat_member_one,
|
||||
new_chat_member=_chat_member_two,
|
||||
client=client
|
||||
)
|
||||
|
||||
chat_id = getattr(update, "chat_id", None) or getattr(update, "channel_id")
|
||||
|
||||
old_chat_member = None
|
||||
|
|
|
|||
Loading…
Reference in a new issue