mirror of
https://github.com/Rapptz/discord.py.git
synced 2026-09-21 03:27:42 +00:00
Validate message file upload limit
This commit is contained in:
@@ -173,6 +173,9 @@ def handle_message_parameters(
|
|||||||
if attachments is not MISSING and files is not MISSING:
|
if attachments is not MISSING and files is not MISSING:
|
||||||
raise TypeError('Cannot mix attachments and files keyword arguments.')
|
raise TypeError('Cannot mix attachments and files keyword arguments.')
|
||||||
|
|
||||||
|
if files is not MISSING and len(files) > 10:
|
||||||
|
raise ValueError('files has a maximum of 10 elements.')
|
||||||
|
|
||||||
payload = {}
|
payload = {}
|
||||||
if embeds is not MISSING:
|
if embeds is not MISSING:
|
||||||
if len(embeds) > 10:
|
if len(embeds) > 10:
|
||||||
|
|||||||
@@ -571,6 +571,9 @@ def interaction_message_response_params(
|
|||||||
if attachments is not MISSING and files is not MISSING:
|
if attachments is not MISSING and files is not MISSING:
|
||||||
raise TypeError('Cannot mix attachments and files keyword arguments.')
|
raise TypeError('Cannot mix attachments and files keyword arguments.')
|
||||||
|
|
||||||
|
if files is not MISSING and len(files) > 10:
|
||||||
|
raise ValueError('files has a maximum of 10 elements.')
|
||||||
|
|
||||||
data: Optional[Dict[str, Any]] = {
|
data: Optional[Dict[str, Any]] = {
|
||||||
'tts': tts,
|
'tts': tts,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
"""
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015-present Rapptz
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the "Software"),
|
||||||
|
to deal in the Software without restriction, including without limitation
|
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||||||
|
Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||||
|
DEALINGS IN THE SOFTWARE.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
|
import discord
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from discord.http import handle_message_parameters
|
||||||
|
from discord.webhook.async_ import interaction_message_response_params
|
||||||
|
|
||||||
|
|
||||||
|
def make_file(index: int) -> discord.File:
|
||||||
|
return discord.File(BytesIO(b'test'), filename=f'test-{index}.txt')
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_message_parameters_rejects_too_many_files():
|
||||||
|
files = [make_file(index) for index in range(11)]
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match='files has a maximum of 10 elements'):
|
||||||
|
handle_message_parameters(content='test', files=files)
|
||||||
|
|
||||||
|
|
||||||
|
def test_interaction_message_response_params_rejects_too_many_files():
|
||||||
|
files = [make_file(index) for index in range(11)]
|
||||||
|
|
||||||
|
with pytest.raises(ValueError, match='files has a maximum of 10 elements'):
|
||||||
|
interaction_message_response_params(type=4, content='test', files=files)
|
||||||
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user