Browse Source

Validate message file upload limit

pull/10473/merge
harumaki4649 2 days ago
committed by GitHub
parent
commit
f6dbb848d0
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 3
      discord/http.py
  2. 3
      discord/webhook/async_.py
  3. 53
      tests/test_http.py

3
discord/http.py

@ -173,6 +173,9 @@ def handle_message_parameters(
if attachments is not MISSING and files is not MISSING:
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 = {}
if embeds is not MISSING:
if len(embeds) > 10:

3
discord/webhook/async_.py

@ -571,6 +571,9 @@ def interaction_message_response_params(
if attachments is not MISSING and files is not MISSING:
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]] = {
'tts': tts,
}

53
tests/test_http.py

@ -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)
Loading…
Cancel
Save