Skip to content

Commit

Permalink
Rename allowed mention parameters to allowed_mentions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Apr 4, 2020
1 parent 730d79d commit 40d38b3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
19 changes: 10 additions & 9 deletions discord/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ async def _get_channel(self):

async def send(self, content=None, *, tts=False, embed=None, file=None,
files=None, delete_after=None, nonce=None,
mentions=None):
allowed_mentions=None):
"""|coro|
Sends a message to the destination with the content given.
Expand Down Expand Up @@ -806,7 +806,7 @@ async def send(self, content=None, *, tts=False, embed=None, file=None,
If provided, the number of seconds to wait in the background
before deleting the message we just sent. If the deletion fails,
then it is silently ignored.
mentions: :class:`AllowedMentions`
allowed_mentions: :class:`AllowedMentions`
Controls the mentions being processed in this message.
.. versionadded:: 1.4
Expand All @@ -833,13 +833,13 @@ async def send(self, content=None, *, tts=False, embed=None, file=None,
if embed is not None:
embed = embed.to_dict()

if mentions is not None:
if state.mentions is not None:
mentions = state.mentions.merge(mentions).to_dict()
if allowed_mentions is not None:
if state.allowed_mentions is not None:
allowed_mentions = state.allowed_mentions.merge(allowed_mentions).to_dict()
else:
mentions = mentions.to_dict()
allowed_mentions = allowed_mentions.to_dict()
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:
raise InvalidArgument('cannot pass both file and files parameter to send()')
Expand All @@ -862,12 +862,13 @@ async def send(self, content=None, *, tts=False, embed=None, file=None,

try:
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:
for f in files:
f.close()
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)
if delete_after is not None:
Expand Down
16 changes: 8 additions & 8 deletions discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class Client:
A status to start your presence with upon logging on to Discord.
activity: Optional[:class:`.BaseActivity`]
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.
.. versionadded:: 1.4
Expand Down Expand Up @@ -667,21 +667,21 @@ def activity(self, value):
raise TypeError('activity must derive from BaseActivity.')

@property
def mentions(self):
def allowed_mentions(self):
"""Optional[:class:`AllowedMentions`]: The allowed mention configuration.
.. versionadded:: 1.4
"""
return self._connection.mentions
return self._connection.allowed_mentions

@mentions.setter
def mentions(self, value):
@allowed_mentions.setter
def allowed_mentions(self, value):
if value is None:
self._connection.mentions = value
self._connection.allowed_mentions = value
elif isinstance(value, AllowedMentions):
self._connection.mentions = value
self._connection.allowed_mentions = value
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

Expand Down
12 changes: 6 additions & 6 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def start_private_message(self, user_id):

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)
payload = {}

Expand All @@ -326,15 +326,15 @@ def send_message(self, channel_id, content, *, tts=False, embed=None, nonce=None
if nonce:
payload['nonce'] = nonce

if mentions:
payload['allowed_mentions'] = mentions
if allowed_mentions:
payload['allowed_mentions'] = allowed_mentions

return self.request(r, json=payload)

def send_typing(self, 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)
form = aiohttp.FormData()

Expand All @@ -345,8 +345,8 @@ def send_files(self, channel_id, *, files, content=None, tts=False, embed=None,
payload['embed'] = embed
if nonce:
payload['nonce'] = nonce
if mentions:
payload['allowed_mentions'] = mentions
if allowed_mentions:
payload['allowed_mentions'] = allowed_mentions

form.add_field('payload_json', utils.to_json(payload))
if len(files) == 1:
Expand Down
8 changes: 4 additions & 4 deletions discord/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ def __init__(self, *, dispatch, chunker, handlers, syncer, http, loop, **options
self._fetch_offline = options.get('fetch_offline_members', True)
self.heartbeat_timeout = options.get('heartbeat_timeout', 60.0)
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):
raise TypeError('mentions parameter must be AllowedMentions')
if allowed_mentions is not None and not isinstance(allowed_mentions, 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.
self._cache_members = (self._fetch_offline or self.guild_subscriptions)
self._listeners = []
Expand Down

0 comments on commit 40d38b3

Please sign in to comment.