Skip to content

Commit

Permalink
Add show_message_sender_enabled, has_aggressive_anti_spam_enabled, ha…
Browse files Browse the repository at this point in the history
…s_protected_content, is_forum to ChatEvent
  • Loading branch information
SpEcHiDe authored Nov 5, 2024
1 parent 9199ea4 commit f0ab18f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 2 deletions.
12 changes: 12 additions & 0 deletions pyrogram/enums/chat_event_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,17 @@ class ChatEventAction(AutoName):
MEMBER_SUBSCRIPTION_EXTENDED = auto()
"A chat member extended their subscription to the chat (``old_chat_member`` and ``new_chat_member``)"

SHOW_MESSAGE_SENDER_ENABLED = auto()
"the show message senders have been enabled or disabled (see ``show_message_sender_enabled``)"

AGGRESSIVE_ANTI_SPAM_TOGGLED = auto()
"The ``has_aggressive_anti_spam_enabled`` setting of a supergroup was toggled. (see ``has_aggressive_anti_spam_enabled``)"

PROTECTED_CONTENT_TOGGLED = auto()
"The ``has_protected_content`` setting of a channel was toggled (see ``has_protected_content``)"

CHAT_IS_FORUM_TOGGLED = auto()
"The ``is_forum`` setting of a channel was toggled. (see ``is_forum``)"

UNKNOWN = auto()
"Unknown chat event action"
52 changes: 52 additions & 0 deletions pyrogram/types/user_and_chats/chat_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,22 @@ class ChatEvent(Object):
Affected chat member status of the user.
For :obj:`~pyrogram.enums.ChatEventAction.MEMBER_SUBSCRIPTION_EXTENDED` action only.
show_message_sender_enabled (``bool``, *optional*):
The show_message_sender setting of a channel was toggled.
For :obj:`~pyrogram.enums.ChatEventAction.SHOW_MESSAGE_SENDER_ENABLED` action only.
has_aggressive_anti_spam_enabled (``bool``, *optional*):
The ``has_aggressive_anti_spam_enabled`` setting of a supergroup was toggled.
For :obj:`~pyrogram.enums.ChatEventAction.AGGRESSIVE_ANTI_SPAM_TOGGLED` action only.
has_protected_content (``bool``, *optional*):
The ``has_protected_content`` setting of a channel was toggled.
For :obj:`~pyrogram.enums.ChatEventAction.PROTECTED_CONTENT_TOGGLED` action only.
is_forum (``bool``, *optional*):
The ``is_forum`` setting of a channel was toggled.
For :obj:`~pyrogram.enums.ChatEventAction.CHAT_IS_FORUM_TOGGLED` action only.
"""

def __init__(
Expand Down Expand Up @@ -220,6 +236,11 @@ def __init__(

old_chat_member: "types.ChatMember" = None,
new_chat_member: "types.ChatMember" = None,

show_message_sender_enabled: bool = None,
has_aggressive_anti_spam_enabled: bool = None,
has_protected_content: bool = None,
is_forum: bool = None,
):
super().__init__()

Expand Down Expand Up @@ -290,6 +311,11 @@ def __init__(
self.old_chat_member = old_chat_member
self.new_chat_member = new_chat_member

self.show_message_sender_enabled = show_message_sender_enabled
self.has_aggressive_anti_spam_enabled = has_aggressive_anti_spam_enabled
self.has_protected_content = has_protected_content
self.is_forum = is_forum

@staticmethod
async def _parse(
client: "pyrogram.Client",
Expand Down Expand Up @@ -365,6 +391,11 @@ async def _parse(
old_chat_member: Optional[types.ChatMember] = None
new_chat_member: Optional[types.ChatMember] = None

show_message_sender_enabled: Optional[bool] = None
has_aggressive_anti_spam_enabled: Optional[bool] = None
has_protected_content: Optional[bool] = None
is_forum: Optional[bool] = None

if isinstance(action, raw.types.ChannelAdminLogEventActionChangeAbout):
old_description = action.prev_value
new_description = action.new_value
Expand Down Expand Up @@ -509,6 +540,22 @@ async def _parse(
new_chat_member = types.ChatMember._parse(client, action.new_participant, users, chats)
action = enums.ChatEventAction.MEMBER_SUBSCRIPTION_EXTENDED

elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleSignatureProfiles):
show_message_sender_enabled = action.new_value
action = enums.ChatEventAction.SHOW_MESSAGE_SENDER_ENABLED

elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleAntiSpam):
has_aggressive_anti_spam_enabled = action.new_value
action = enums.ChatEventAction.AGGRESSIVE_ANTI_SPAM_TOGGLED

elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleNoForwards):
has_protected_content = action.new_value
action = enums.ChatEventAction.PROTECTED_CONTENT_TOGGLED

elif isinstance(action, raw.types.ChannelAdminLogEventActionToggleForum):
is_forum = action.new_value
action = enums.ChatEventAction.CHAT_IS_FORUM_TOGGLED

else:
action = f"{enums.ChatEventAction.UNKNOWN}-{action.QUALNAME}"

Expand Down Expand Up @@ -579,4 +626,9 @@ async def _parse(

old_chat_member=old_chat_member,
new_chat_member=new_chat_member,

show_message_sender_enabled=show_message_sender_enabled,
has_aggressive_anti_spam_enabled=has_aggressive_anti_spam_enabled,
has_protected_content=has_protected_content,
is_forum=is_forum,
)
4 changes: 2 additions & 2 deletions pyrogram/types/user_and_chats/chat_event_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,6 @@ def write(self) -> "raw.base.ChannelAdminLogEventsFilter":
group_call=group_call,
invites=invites,
# send
forums=forum_changes.
sub_extend=subscription_extensions
forums=forum_changes,
sub_extend=subscription_extensions,
)

0 comments on commit f0ab18f

Please sign in to comment.