Compare commits
5 Commits
mtpager
...
notificati
Author | SHA1 | Date | |
---|---|---|---|
|
f153350ab5 | ||
|
6ad4272c5c | ||
|
024f89d3fa | ||
|
1940c97c6d | ||
|
673a618873 |
@ -52,6 +52,7 @@ from .unarchive_chats import UnarchiveChats
|
||||
from .unban_chat_member import UnbanChatMember
|
||||
from .unpin_all_chat_messages import UnpinAllChatMessages
|
||||
from .unpin_chat_message import UnpinChatMessage
|
||||
from .update_chat_notifications import UpdateChatNotifications
|
||||
from .update_chat_username import UpdateChatUsername
|
||||
|
||||
|
||||
@ -75,6 +76,7 @@ class Chats(
|
||||
GetChatMembersCount,
|
||||
IterDialogs,
|
||||
IterChatMembers,
|
||||
UpdateChatNotifications,
|
||||
UpdateChatUsername,
|
||||
SetChatPermissions,
|
||||
GetDialogsCount,
|
||||
|
67
pyrogram/methods/chats/update_chat_notifications.py
Normal file
67
pyrogram/methods/chats/update_chat_notifications.py
Normal file
@ -0,0 +1,67 @@
|
||||
from typing import Union
|
||||
|
||||
from pyrogram.raw.functions.account import UpdateNotifySettings
|
||||
from pyrogram.raw.types import InputNotifyPeer, InputPeerNotifySettings
|
||||
from pyrogram.scaffold import Scaffold
|
||||
|
||||
|
||||
class UpdateChatNotifications(Scaffold):
|
||||
async def update_chat_notifications(
|
||||
self,
|
||||
chat_id: Union[int, str],
|
||||
show_previews: bool = None,
|
||||
silent: bool = None,
|
||||
mute_until: int = None
|
||||
) -> bool:
|
||||
"""Update the notification settings for the selected chat
|
||||
|
||||
Parameters:
|
||||
chat_id (``int`` | ``str``):
|
||||
Unique identifier (int) or username (str) of the target chat.
|
||||
|
||||
show_previews (``bool``, *optional*):
|
||||
If the text of the message shall be displayed in notification.
|
||||
|
||||
silent (``bool``, *optional*):
|
||||
If the chat shall be muted.
|
||||
|
||||
mute_until (``int``, *optional*):
|
||||
When notifications shall be switched off. Unix time.
|
||||
Default to forever.
|
||||
|
||||
Returns:
|
||||
``bool``: True on success, False otherwise.
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
# Mute a chat permanently
|
||||
app.update_chat_notifications(chat_id, silent=True)
|
||||
|
||||
# Mute a chat for 10 minutes
|
||||
from time import time
|
||||
|
||||
app.update_chat_notifications(
|
||||
chat_id,
|
||||
silent=True,
|
||||
mute_until=time() + 600
|
||||
)
|
||||
|
||||
# Unmute a chat
|
||||
app.update_chat_notifications(chat_id, silent=False)
|
||||
"""
|
||||
|
||||
peer = await self.resolve_peer(chat_id)
|
||||
|
||||
r = await self.send(
|
||||
UpdateNotifySettings(
|
||||
peer=InputNotifyPeer(peer=peer),
|
||||
settings=InputPeerNotifySettings(
|
||||
show_previews=show_previews or None,
|
||||
silent=silent or None,
|
||||
mute_until=mute_until or None
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return r
|
@ -967,3 +967,83 @@ class Chat(Object):
|
||||
"""
|
||||
|
||||
return await self._client.mark_chat_unread(self.id)
|
||||
|
||||
async def enable_notifications(
|
||||
self,
|
||||
show_previews: bool = None,
|
||||
mute_until: int = None
|
||||
) -> bool:
|
||||
"""Bound method *enable_notifications* of :obj:`~pyrogram.types.Chat`.
|
||||
|
||||
Use as a shortcut for:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
client.update_chat_notifications(
|
||||
chat_id=chat_id,
|
||||
silent=False
|
||||
)
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
chat.enable_notifications()
|
||||
|
||||
Parameters:
|
||||
show_previews (``bool``, *optional*):
|
||||
If the text of the message shall be displayed in notification.
|
||||
|
||||
mute_until (``int``, *optional*):
|
||||
When notifications shall be switched off. Unix time.
|
||||
Default to forever.
|
||||
|
||||
Returns:
|
||||
``bool``: True on success, False otherwise.
|
||||
"""
|
||||
|
||||
return await self._client.update_chat_notifications(
|
||||
self.id,
|
||||
show_previews=show_previews or None,
|
||||
silent=False,
|
||||
mute_until=mute_until or None
|
||||
)
|
||||
|
||||
async def disable_notifications(
|
||||
self,
|
||||
show_previews: bool = None,
|
||||
mute_until: int = None
|
||||
) -> bool:
|
||||
"""Bound method *disable_notifications* of :obj:`~pyrogram.types.Chat`.
|
||||
|
||||
Use as a shortcut for:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
client.update_chat_notifications(
|
||||
chat_id=chat_id,
|
||||
silent=True
|
||||
)
|
||||
|
||||
Example:
|
||||
.. code-block:: python
|
||||
|
||||
chat.disable_notifications()
|
||||
|
||||
Parameters:
|
||||
show_previews (``bool``, *optional*):
|
||||
If the text of the message shall be displayed in notification.
|
||||
|
||||
mute_until (``int``, *optional*):
|
||||
When notifications shall be switched off. Unix time.
|
||||
Default to forever.
|
||||
|
||||
Returns:
|
||||
``bool``: True on success, False otherwise.
|
||||
"""
|
||||
|
||||
return await self._client.update_chat_notifications(
|
||||
self.id,
|
||||
show_previews=show_previews or None,
|
||||
silent=True,
|
||||
mute_until=mute_until or None
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user