Implement discord.MessageFlags
Refactor flags placement and use it for suppression.
This commit is contained in:
@ -38,6 +38,7 @@ from .enums import MessageType, try_enum
|
||||
from .errors import InvalidArgument, ClientException, HTTPException
|
||||
from .embeds import Embed
|
||||
from .member import Member
|
||||
from .flags import MessageFlags
|
||||
|
||||
class Attachment:
|
||||
"""Represents an attachment from Discord.
|
||||
@ -237,6 +238,8 @@ class Message:
|
||||
A list of attachments given to a message.
|
||||
pinned: :class:`bool`
|
||||
Specifies if the message is currently pinned.
|
||||
flags: :class:`MessageFlags`
|
||||
Extra features of the message.
|
||||
reactions : List[:class:`Reaction`]
|
||||
Reactions to a message. Reactions can be either custom emoji or standard unicode emoji.
|
||||
activity: Optional[:class:`dict`]
|
||||
@ -263,7 +266,7 @@ class Message:
|
||||
'mention_everyone', 'embeds', 'id', 'mentions', 'author',
|
||||
'_cs_channel_mentions', '_cs_raw_mentions', 'attachments',
|
||||
'_cs_clean_content', '_cs_raw_channel_mentions', 'nonce', 'pinned',
|
||||
'role_mentions', '_cs_raw_role_mentions', 'type', 'call',
|
||||
'role_mentions', '_cs_raw_role_mentions', 'type', 'call', 'flags',
|
||||
'_cs_system_content', '_cs_guild', '_state', 'reactions',
|
||||
'application', 'activity')
|
||||
|
||||
@ -280,19 +283,20 @@ class Message:
|
||||
self._edited_timestamp = utils.parse_time(data['edited_timestamp'])
|
||||
self.type = try_enum(MessageType, data['type'])
|
||||
self.pinned = data['pinned']
|
||||
self.flags = MessageFlags._from_value(data.get('flags', 0))
|
||||
self.mention_everyone = data['mention_everyone']
|
||||
self.tts = data['tts']
|
||||
self.content = data['content']
|
||||
self.nonce = data.get('nonce')
|
||||
|
||||
for handler in ('author', 'member', 'mentions', 'mention_roles', 'call'):
|
||||
for handler in ('author', 'member', 'mentions', 'mention_roles', 'call', 'flags'):
|
||||
try:
|
||||
getattr(self, '_handle_%s' % handler)(data[handler])
|
||||
except KeyError:
|
||||
continue
|
||||
|
||||
def __repr__(self):
|
||||
return '<Message id={0.id} channel={0.channel!r} type={0.type!r} author={0.author!r}>'.format(self)
|
||||
return '<Message id={0.id} channel={0.channel!r} type={0.type!r} author={0.author!r} flags={0.flags!r}>'.format(self)
|
||||
|
||||
def _try_patch(self, data, key, transform=None):
|
||||
try:
|
||||
@ -361,6 +365,9 @@ class Message:
|
||||
def _handle_pinned(self, value):
|
||||
self.pinned = value
|
||||
|
||||
def _handle_flags(self, value):
|
||||
self.flags = MessageFlags._from_value(value)
|
||||
|
||||
def _handle_application(self, value):
|
||||
self.application = value
|
||||
|
||||
@ -772,7 +779,9 @@ class Message:
|
||||
except KeyError:
|
||||
pass
|
||||
else:
|
||||
await self._state.http.suppress_message_embeds(self.channel.id, self.id, suppress=suppress)
|
||||
flags = MessageFlags._from_value(self.flags.value)
|
||||
flags.suppress_embeds = suppress
|
||||
fields['flags'] = flags.value
|
||||
|
||||
delete_after = fields.pop('delete_after', None)
|
||||
|
||||
@ -783,6 +792,27 @@ class Message:
|
||||
if delete_after is not None:
|
||||
await self.delete(delay=delete_after)
|
||||
|
||||
async def publish(self):
|
||||
"""|coro|
|
||||
|
||||
Publishes this message to your announcement channel.
|
||||
|
||||
You must have the :attr:`~Permissions.manage_messages` permission to use this.
|
||||
|
||||
.. note::
|
||||
|
||||
This can only be used by non-bot accounts.
|
||||
|
||||
Raises
|
||||
-------
|
||||
Forbidden
|
||||
You do not have the proper permissions to publish this message.
|
||||
HTTPException
|
||||
Publishing the message failed.
|
||||
"""
|
||||
|
||||
await self._state.http.publish_message(self.channel.id, self.id)
|
||||
|
||||
async def pin(self):
|
||||
"""|coro|
|
||||
|
||||
|
Reference in New Issue
Block a user