Browse Source

Rename allowed mention parameters to allowed_mentions

pull/2634/head
Rapptz 5 years ago
parent
commit
d853a57e86
  1. 19
      discord/abc.py
  2. 16
      discord/client.py
  3. 12
      discord/http.py
  4. 8
      discord/state.py
  5. 14
      discord/webhook.py

19
discord/abc.py

@ -770,7 +770,7 @@ class Messageable(metaclass=abc.ABCMeta):
async def send(self, content=None, *, tts=False, embed=None, file=None, async def send(self, content=None, *, tts=False, embed=None, file=None,
files=None, delete_after=None, nonce=None, files=None, delete_after=None, nonce=None,
mentions=None): allowed_mentions=None):
"""|coro| """|coro|
Sends a message to the destination with the content given. Sends a message to the destination with the content given.
@ -806,7 +806,7 @@ class Messageable(metaclass=abc.ABCMeta):
If provided, the number of seconds to wait in the background If provided, the number of seconds to wait in the background
before deleting the message we just sent. If the deletion fails, before deleting the message we just sent. If the deletion fails,
then it is silently ignored. then it is silently ignored.
mentions: :class:`AllowedMentions` allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message. Controls the mentions being processed in this message.
.. versionadded:: 1.4 .. versionadded:: 1.4
@ -833,13 +833,13 @@ class Messageable(metaclass=abc.ABCMeta):
if embed is not None: if embed is not None:
embed = embed.to_dict() embed = embed.to_dict()
if mentions is not None: if allowed_mentions is not None:
if state.mentions is not None: if state.allowed_mentions is not None:
mentions = state.mentions.merge(mentions).to_dict() allowed_mentions = state.allowed_mentions.merge(allowed_mentions).to_dict()
else: else:
mentions = mentions.to_dict() allowed_mentions = allowed_mentions.to_dict()
else: else:
mentions = state.mentions and state.mentions.to_dict() allowed_mentions = state.allowed_mentions and state.allowed_mentions.to_dict()
if file is not None and files is not None: if file is not None and files is not None:
raise InvalidArgument('cannot pass both file and files parameter to send()') raise InvalidArgument('cannot pass both file and files parameter to send()')
@ -862,12 +862,13 @@ class Messageable(metaclass=abc.ABCMeta):
try: try:
data = await state.http.send_files(channel.id, files=files, content=content, tts=tts, data = await state.http.send_files(channel.id, files=files, content=content, tts=tts,
embed=embed, nonce=nonce, mentions=mentions) embed=embed, nonce=nonce, allowed_mentions=allowed_mentions)
finally: finally:
for f in files: for f in files:
f.close() f.close()
else: else:
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed, nonce=nonce, mentions=mentions) data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
nonce=nonce, allowed_mentions=allowed_mentions)
ret = state.create_message(channel=channel, data=data) ret = state.create_message(channel=channel, data=data)
if delete_after is not None: if delete_after is not None:

16
discord/client.py

@ -150,7 +150,7 @@ class Client:
A status to start your presence with upon logging on to Discord. A status to start your presence with upon logging on to Discord.
activity: Optional[:class:`.BaseActivity`] activity: Optional[:class:`.BaseActivity`]
An activity to start your presence with upon logging on to Discord. An activity to start your presence with upon logging on to Discord.
mentions: Optional[:class:`AllowedMentions`] allowed_mentions: Optional[:class:`AllowedMentions`]
Control how the client handles mentions by default on every message sent. Control how the client handles mentions by default on every message sent.
.. versionadded:: 1.4 .. versionadded:: 1.4
@ -667,21 +667,21 @@ class Client:
raise TypeError('activity must derive from BaseActivity.') raise TypeError('activity must derive from BaseActivity.')
@property @property
def mentions(self): def allowed_mentions(self):
"""Optional[:class:`AllowedMentions`]: The allowed mention configuration. """Optional[:class:`AllowedMentions`]: The allowed mention configuration.
.. versionadded:: 1.4 .. versionadded:: 1.4
""" """
return self._connection.mentions return self._connection.allowed_mentions
@mentions.setter @allowed_mentions.setter
def mentions(self, value): def allowed_mentions(self, value):
if value is None: if value is None:
self._connection.mentions = value self._connection.allowed_mentions = value
elif isinstance(value, AllowedMentions): elif isinstance(value, AllowedMentions):
self._connection.mentions = value self._connection.allowed_mentions = value
else: else:
raise TypeError('mentions must be AllowedMentions not {0.__class__!r}'.format(value)) raise TypeError('allowed_mentions must be AllowedMentions not {0.__class__!r}'.format(value))
# helpers/getters # helpers/getters

12
discord/http.py

@ -310,7 +310,7 @@ class HTTPClient:
return self.request(Route('POST', '/users/@me/channels'), json=payload) return self.request(Route('POST', '/users/@me/channels'), json=payload)
def send_message(self, channel_id, content, *, tts=False, embed=None, nonce=None, mentions=None): def send_message(self, channel_id, content, *, tts=False, embed=None, nonce=None, allowed_mentions=None):
r = Route('POST', '/channels/{channel_id}/messages', channel_id=channel_id) r = Route('POST', '/channels/{channel_id}/messages', channel_id=channel_id)
payload = {} payload = {}
@ -326,15 +326,15 @@ class HTTPClient:
if nonce: if nonce:
payload['nonce'] = nonce payload['nonce'] = nonce
if mentions: if allowed_mentions:
payload['allowed_mentions'] = mentions payload['allowed_mentions'] = allowed_mentions
return self.request(r, json=payload) return self.request(r, json=payload)
def send_typing(self, channel_id): def send_typing(self, channel_id):
return self.request(Route('POST', '/channels/{channel_id}/typing', channel_id=channel_id)) return self.request(Route('POST', '/channels/{channel_id}/typing', channel_id=channel_id))
def send_files(self, channel_id, *, files, content=None, tts=False, embed=None, nonce=None, mentions=None): def send_files(self, channel_id, *, files, content=None, tts=False, embed=None, nonce=None, allowed_mentions=None):
r = Route('POST', '/channels/{channel_id}/messages', channel_id=channel_id) r = Route('POST', '/channels/{channel_id}/messages', channel_id=channel_id)
form = aiohttp.FormData() form = aiohttp.FormData()
@ -345,8 +345,8 @@ class HTTPClient:
payload['embed'] = embed payload['embed'] = embed
if nonce: if nonce:
payload['nonce'] = nonce payload['nonce'] = nonce
if mentions: if allowed_mentions:
payload['allowed_mentions'] = mentions payload['allowed_mentions'] = allowed_mentions
form.add_field('payload_json', utils.to_json(payload)) form.add_field('payload_json', utils.to_json(payload))
if len(files) == 1: if len(files) == 1:

8
discord/state.py

@ -79,12 +79,12 @@ class ConnectionState:
self._fetch_offline = options.get('fetch_offline_members', True) self._fetch_offline = options.get('fetch_offline_members', True)
self.heartbeat_timeout = options.get('heartbeat_timeout', 60.0) self.heartbeat_timeout = options.get('heartbeat_timeout', 60.0)
self.guild_subscriptions = options.get('guild_subscriptions', True) self.guild_subscriptions = options.get('guild_subscriptions', True)
mentions = options.get('mentions') allowed_mentions = options.get('allowed_mentions')
if mentions is not None and not isinstance(mentions, AllowedMentions): if allowed_mentions is not None and not isinstance(allowed_mentions, AllowedMentions):
raise TypeError('mentions parameter must be AllowedMentions') raise TypeError('allowed_mentions parameter must be AllowedMentions')
self.mentions = mentions self.allowed_mentions = allowed_mentions
# Only disable cache if both fetch_offline and guild_subscriptions are off. # Only disable cache if both fetch_offline and guild_subscriptions are off.
self._cache_members = (self._fetch_offline or self.guild_subscriptions) self._cache_members = (self._fetch_offline or self.guild_subscriptions)
self._listeners = [] self._listeners = []

14
discord/webhook.py

@ -688,7 +688,7 @@ class Webhook:
return self._adapter.edit_webhook(**payload) return self._adapter.edit_webhook(**payload)
def send(self, content=None, *, wait=False, username=None, avatar_url=None, tts=False, def send(self, content=None, *, wait=False, username=None, avatar_url=None, tts=False,
file=None, files=None, embed=None, embeds=None, mentions=None): file=None, files=None, embed=None, embeds=None, allowed_mentions=None):
"""|maybecoro| """|maybecoro|
Sends a message using the webhook. Sends a message using the webhook.
@ -732,8 +732,8 @@ class Webhook:
embeds: List[:class:`Embed`] embeds: List[:class:`Embed`]
A list of embeds to send with the content. Maximum of 10. This cannot A list of embeds to send with the content. Maximum of 10. This cannot
be mixed with the ``embed`` parameter. be mixed with the ``embed`` parameter.
mentions: :class:`AllowedMentions` allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message. Controls the allowed_mentions being processed in this message.
.. versionadded:: 1.4 .. versionadded:: 1.4
@ -781,13 +781,13 @@ class Webhook:
if username: if username:
payload['username'] = username payload['username'] = username
previous_mentions = getattr(self._state, 'mentions', None) previous_mentions = getattr(self._state, 'allowed_mentions', None)
if mentions: if allowed_mentions:
if previous_mentions is not None: if previous_mentions is not None:
payload['allowed_mentions'] = previous_mentions.merge(mentions).to_dict() payload['allowed_mentions'] = previous_mentions.merge(allowed_mentions).to_dict()
else: else:
payload['allowed_mentions'] = mentions.to_dict() payload['allowed_mentions'] = allowed_mentions.to_dict()
elif previous_mentions is not None: elif previous_mentions is not None:
payload['allowed_mentions'] = previous_mentions.to_dict() payload['allowed_mentions'] = previous_mentions.to_dict()

Loading…
Cancel
Save