From ecfc6ae87dedc5633182d5b0ba5022b340501537 Mon Sep 17 00:00:00 2001 From: Shrimadhav U K Date: Fri, 9 Jul 2021 23:20:47 +0530 Subject: [PATCH] Add pm_oneside parameter in pin_message (#3095) --- telethon/client/messages.py | 13 ++++++++++--- telethon/tl/custom/message.py | 4 ++-- telethon_generator/data/errors.csv | 1 + telethon_generator/data/methods.csv | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/telethon/client/messages.py b/telethon/client/messages.py index 6bdb7f5d..31a954f1 100644 --- a/telethon/client/messages.py +++ b/telethon/client/messages.py @@ -1322,7 +1322,8 @@ class MessageMethods: entity: 'hints.EntityLike', message: 'typing.Optional[hints.MessageIDLike]', *, - notify: bool = False + notify: bool = False, + pm_oneside: bool = False ): """ Pins a message in a chat. @@ -1342,6 +1343,11 @@ class MessageMethods: notify (`bool`, optional): Whether the pin should notify people or not. + + pm_oneside (`bool`, optional): + Whether the message should be pinned for everyone or not. + By default it has the opposite behaviour of official clients, + and it will pin the message for both sides, in private chats. Example .. code-block:: python @@ -1350,7 +1356,7 @@ class MessageMethods: message = await client.send_message(chat, 'Pinotifying is fun!') await client.pin_message(chat, message, notify=True) """ - return await self._pin(entity, message, unpin=False, notify=notify) + return await self._pin(entity, message, unpin=False, notify=notify, pm_oneside=pm_oneside) async def unpin_message( self: 'TelegramClient', @@ -1382,7 +1388,7 @@ class MessageMethods: """ return await self._pin(entity, message, unpin=True, notify=notify) - async def _pin(self, entity, message, *, unpin, notify=False): + async def _pin(self, entity, message, *, unpin, notify=False, pm_oneside=False): message = utils.get_message_id(message) or 0 entity = await self.get_input_entity(entity) if message <= 0: # old behaviour accepted negative IDs to unpin @@ -1394,6 +1400,7 @@ class MessageMethods: id=message, silent=not notify, unpin=unpin, + pm_oneside=pm_oneside ) result = await self(request) diff --git a/telethon/tl/custom/message.py b/telethon/tl/custom/message.py index 3d069bf7..b55f9065 100644 --- a/telethon/tl/custom/message.py +++ b/telethon/tl/custom/message.py @@ -1038,7 +1038,7 @@ class Message(ChatGetter, SenderGetter, TLObject): await self._client.send_read_acknowledge( await self.get_input_chat(), max_id=self.id) - async def pin(self, *, notify=False): + async def pin(self, *, notify=False, pm_oneside=False): """ Pins the message. Shorthand for `telethon.client.messages.MessageMethods.pin_message` @@ -1049,7 +1049,7 @@ class Message(ChatGetter, SenderGetter, TLObject): # That or figure out a way to always set it directly. if self._client: return await self._client.pin_message( - await self.get_input_chat(), self.id, notify=notify) + await self.get_input_chat(), self.id, notify=notify, pm_oneside=pm_oneside) async def unpin(self): """ diff --git a/telethon_generator/data/errors.csv b/telethon_generator/data/errors.csv index 1fef87da..7e176924 100644 --- a/telethon_generator/data/errors.csv +++ b/telethon_generator/data/errors.csv @@ -27,6 +27,7 @@ BANK_CARD_NUMBER_INVALID,400,Incorrect credit card number BASE_PORT_LOC_INVALID,400,Base port location invalid BANNED_RIGHTS_INVALID,400,"You cannot use that set of permissions in this request, i.e. restricting view_messages as a default" BOTS_TOO_MUCH,400,There are too many bots in this chat/channel +BOT_ONESIDE_NOT_AVAIL,400, BOT_CHANNELS_NA,400,Bots can't edit admin privileges BOT_COMMAND_DESCRIPTION_INVALID,400,"The command description was empty, too long or had invalid characters used" BOT_COMMAND_INVALID,400, diff --git a/telethon_generator/data/methods.csv b/telethon_generator/data/methods.csv index 00dc3ca5..82bce6ed 100644 --- a/telethon_generator/data/methods.csv +++ b/telethon_generator/data/methods.csv @@ -296,7 +296,7 @@ messages.toggleStickerSets,user, messages.uninstallStickerSet,user,STICKERSET_INVALID messages.updateDialogFilter,user, messages.updateDialogFiltersOrder,user, -messages.updatePinnedMessage,both, +messages.updatePinnedMessage,both,BOT_ONESIDE_NOT_AVAIL messages.uploadEncryptedFile,user, messages.uploadMedia,both,BOT_MISSING MEDIA_INVALID PEER_ID_INVALID payments.clearSavedInfo,user,