mirror of
				https://github.com/Rapptz/discord.py.git
				synced 2025-10-31 05:23:03 +00:00 
			
		
		
		
	Add support for message pinning.
This includes `Client.pin_message`, `Client.unpin_message` and `Client.pins_from`. This also adds the `Message.pinned` attribute to the `Message` object.
This commit is contained in:
		| @@ -1110,6 +1110,75 @@ class Client: | ||||
|         data = yield from self.http.get_message(channel.id, id) | ||||
|         return Message(channel=channel, **data) | ||||
|  | ||||
|     @asyncio.coroutine | ||||
|     def pin_message(self, message): | ||||
|         """|coro| | ||||
|  | ||||
|         Pins a message. You must have Manage Messages permissions | ||||
|         to do this in a non-private channel context. | ||||
|  | ||||
|         Parameters | ||||
|         ----------- | ||||
|         message: :class:`Message` | ||||
|             The message to pin. | ||||
|  | ||||
|         Raises | ||||
|         ------- | ||||
|         Forbidden | ||||
|             You do not have permissions to pin the message. | ||||
|         NotFound | ||||
|             The message or channel was not found. | ||||
|         HTTPException | ||||
|             Pinning the message failed, probably due to the channel | ||||
|             having more than 50 pinned messages. | ||||
|         """ | ||||
|         yield from self.http.pin_message(message.channel.id, message.id) | ||||
|  | ||||
|     @asyncio.coroutine | ||||
|     def unpin_message(self, message): | ||||
|         """|coro| | ||||
|  | ||||
|         Unpins a message. You must have Manage Messages permissions | ||||
|         to do this in a non-private channel context. | ||||
|  | ||||
|         Parameters | ||||
|         ----------- | ||||
|         message: :class:`Message` | ||||
|             The message to unpin. | ||||
|  | ||||
|         Raises | ||||
|         ------- | ||||
|         Forbidden | ||||
|             You do not have permissions to unpin the message. | ||||
|         NotFound | ||||
|             The message or channel was not found. | ||||
|         HTTPException | ||||
|             Unpinning the message failed. | ||||
|         """ | ||||
|         yield from self.http.unpin_message(message.channel.id, message.id) | ||||
|  | ||||
|     @asyncio.coroutine | ||||
|     def pins_from(self, channel): | ||||
|         """|coro| | ||||
|  | ||||
|         Returns a list of :class:`Message` that are currently pinned for | ||||
|         the specified :class:`Channel` or :class:`PrivateChannel`. | ||||
|  | ||||
|         Parameters | ||||
|         ----------- | ||||
|         channel: :class:`Channel` or :class:`PrivateChannel` | ||||
|             The channel to look through pins for. | ||||
|  | ||||
|         Raises | ||||
|         ------- | ||||
|         NotFound | ||||
|             The channel was not found. | ||||
|         HTTPException | ||||
|             Retrieving the pinned messages failed. | ||||
|         """ | ||||
|  | ||||
|         data = yield from self.http.pins_from(channel.id) | ||||
|         return [Message(channel=channel, **m) for m in data] | ||||
|  | ||||
|     def _logs_from(self, channel, limit=100, before=None, after=None): | ||||
|         """|coro| | ||||
|   | ||||
| @@ -278,6 +278,18 @@ class HTTPClient: | ||||
|  | ||||
|         return self.get(url, params=params, bucket=_func_()) | ||||
|  | ||||
|     def pin_message(self, channel_id, message_id): | ||||
|         url = '{0.CHANNELS}/{1}/pins/{2}'.format(self, channel_id, message_id) | ||||
|         return self.put(url, bucket=_func_()) | ||||
|  | ||||
|     def unpin_message(self, channel_id, message_id): | ||||
|         url = '{0.CHANNELS}/{1}/pins/{2}'.format(self, channel_id, message_id) | ||||
|         return self.delete(url, bucket=_func_()) | ||||
|  | ||||
|     def pins_from(self, channel_id): | ||||
|         url = '{0.CHANNELS}/{1}/pins'.format(self, channel_id) | ||||
|         return self.get(url, bucket=_func_()) | ||||
|  | ||||
|     # Member management | ||||
|  | ||||
|     def kick(self, user_id, guild_id): | ||||
|   | ||||
| @@ -90,12 +90,14 @@ class Message: | ||||
|         The message ID. | ||||
|     attachments : list | ||||
|         A list of attachments given to a message. | ||||
|     pinned: bool | ||||
|         Specifies if the message is currently pinned. | ||||
|     """ | ||||
|  | ||||
|     __slots__ = [ 'edited_timestamp', 'timestamp', 'tts', 'content', 'channel', | ||||
|                   'mention_everyone', 'embeds', 'id', 'mentions', 'author', | ||||
|                   'channel_mentions', 'server', '_raw_mentions', 'attachments', | ||||
|                   '_clean_content', '_raw_channel_mentions', 'nonce', | ||||
|                   '_clean_content', '_raw_channel_mentions', 'nonce', 'pinned', | ||||
|                   'role_mentions', '_raw_role_mentions' ] | ||||
|  | ||||
|     def __init__(self, **kwargs): | ||||
| @@ -108,7 +110,8 @@ class Message: | ||||
|         # sometimes the .%f modifier is missing | ||||
|         self.edited_timestamp = utils.parse_time(data.get('edited_timestamp')) | ||||
|         self.timestamp = utils.parse_time(data.get('timestamp')) | ||||
|         self.tts = data.get('tts') | ||||
|         self.tts = data.get('tts', False) | ||||
|         self.pinned = data.get('pinned', False) | ||||
|         self.content = data.get('content') | ||||
|         self.mention_everyone = data.get('mention_everyone') | ||||
|         self.embeds = data.get('embeds') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user