mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Support for sending a nonce.
This commit is contained in:
parent
b13d437bb9
commit
3330a19f35
@ -628,7 +628,7 @@ class Messageable(metaclass=abc.ABCMeta):
|
|||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def send(self, content=None, *, tts=False, embed=None, file=None, files=None, reason=None, delete_after=None):
|
def send(self, content=None, *, tts=False, embed=None, file=None, files=None, reason=None, delete_after=None, nonce=None):
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Sends a message to the destination with the content given.
|
Sends a message to the destination with the content given.
|
||||||
@ -658,6 +658,9 @@ class Messageable(metaclass=abc.ABCMeta):
|
|||||||
files: List[:class:`File`]
|
files: List[:class:`File`]
|
||||||
A list of files to upload. Must be a minimum of 2 and a
|
A list of files to upload. Must be a minimum of 2 and a
|
||||||
maximum of 10.
|
maximum of 10.
|
||||||
|
nonce: int
|
||||||
|
The nonce to use for sending this message. If the message was successfully sent,
|
||||||
|
then the message will have a nonce with this value.
|
||||||
delete_after: float
|
delete_after: float
|
||||||
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,
|
||||||
@ -697,7 +700,7 @@ class Messageable(metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
data = yield from state.http.send_files(channel.id, files=[(file.open_file(), file.filename)],
|
data = yield from state.http.send_files(channel.id, files=[(file.open_file(), file.filename)],
|
||||||
content=content, tts=tts, embed=embed)
|
content=content, tts=tts, embed=embed, nonce=nonce)
|
||||||
finally:
|
finally:
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
@ -707,12 +710,13 @@ class Messageable(metaclass=abc.ABCMeta):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
param = [(f.open_file(), f.filename) for f in files]
|
param = [(f.open_file(), f.filename) for f in files]
|
||||||
data = yield from state.http.send_files(channel.id, files=param, content=content, tts=tts, embed=embed)
|
data = yield from state.http.send_files(channel.id, files=param, content=content, tts=tts,
|
||||||
|
embed=embed, nonce=nonce)
|
||||||
finally:
|
finally:
|
||||||
for f in files:
|
for f in files:
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
data = yield from state.http.send_message(channel.id, content, tts=tts, embed=embed)
|
data = yield from state.http.send_message(channel.id, content, tts=tts, embed=embed, nonce=nonce)
|
||||||
|
|
||||||
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:
|
||||||
|
@ -294,7 +294,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):
|
def send_message(self, channel_id, content, *, tts=False, embed=None, nonce=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 = {}
|
||||||
|
|
||||||
@ -307,12 +307,15 @@ class HTTPClient:
|
|||||||
if embed:
|
if embed:
|
||||||
payload['embed'] = embed
|
payload['embed'] = embed
|
||||||
|
|
||||||
|
if nonce:
|
||||||
|
payload['nonce'] = nonce
|
||||||
|
|
||||||
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):
|
def send_files(self, channel_id, *, files, content=None, tts=False, embed=None, nonce=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()
|
||||||
|
|
||||||
@ -321,6 +324,8 @@ class HTTPClient:
|
|||||||
payload['content'] = content
|
payload['content'] = content
|
||||||
if embed:
|
if embed:
|
||||||
payload['embed'] = embed
|
payload['embed'] = embed
|
||||||
|
if nonce:
|
||||||
|
payload['nonce'] = nonce
|
||||||
|
|
||||||
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:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user