Skip to content

Commit 236386a

Browse files
committed
Extract ComponentLimits to ui.constant
Move the ComponentLimits class from discord/ui/core.py into a new discord/ui/constant.py and update all UI modules to import ComponentLimits from .constant. Also export the constant module in discord/ui/__init__.py and remove ComponentLimits from core's exports. This centralizes UI constraint constants into a dedicated module.
1 parent 6b38959 commit 236386a

11 files changed

Lines changed: 110 additions & 81 deletions

File tree

discord/ui/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
from .text_display import *
2929
from .thumbnail import *
3030
from .view import *
31+
from .constant import *

discord/ui/checkbox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from ..components import Checkbox as CheckboxComponent
3131
from ..enums import ComponentType
32-
from .core import ComponentLimits
32+
from .constant import ComponentLimits
3333
from .item import ModalItem
3434

3535
__all__ = ("Checkbox",)

discord/ui/checkbox_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from ..components import CheckboxGroupOption
3434
from ..enums import ComponentType
3535
from ..utils import MISSING
36-
from .core import ComponentLimits
36+
from .constant import ComponentLimits
3737
from .item import ModalItem
3838

3939
__all__ = ("CheckboxGroup",)

discord/ui/constant.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
"""
2+
The MIT License (MIT)
3+
4+
Copyright (c) 2021-present Pycord Development
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a
7+
copy of this software and associated documentation files (the "Software"),
8+
to deal in the Software without restriction, including without limitation
9+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+
and/or sell copies of the Software, and to permit persons to whom the
11+
Software is furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22+
DEALINGS IN THE SOFTWARE.
23+
"""
24+
25+
from __future__ import annotations
26+
27+
__all__ = ("ComponentLimits",)
28+
29+
class ComponentLimits:
30+
# View constraints
31+
VIEW_CHILDREN_MAX = 40
32+
33+
# ActionRow constraints
34+
ACTION_ROW_CHILDREN_MAX = 5
35+
36+
# Button constraints
37+
BUTTON_LABEL_MAX = 80
38+
39+
# MediaGallery constraints
40+
MEDIA_GALLERY_ITEMS_MIN = 1
41+
MEDIA_GALLERY_ITEMS_MAX = 10
42+
43+
# MediaGalleryItem constraints
44+
MEDIA_GALLERY_ITEM_DESCRIPTION_MAX = 256
45+
46+
# Select constraints
47+
SELECT_PLACEHOLDER_MAX = 150
48+
SELECT_OPTIONS_MAX = 25
49+
SELECT_DEFAULT_VALUES_MAX = 25
50+
51+
# Select option constraints
52+
SELECT_OPTION_LABEL_MAX = 100
53+
SELECT_OPTION_VALUE_MAX = 100
54+
SELECT_OPTION_DESCRIPTION_MAX = 100
55+
56+
# Section constraints
57+
SECTION_ACCESSORY_MAX = 1
58+
SECTION_CHILDREN_MIN = 1
59+
SECTION_CHILDREN_MAX = 3
60+
61+
# TextInput constraints
62+
TEXT_INPUT_MAX_COUNT = 5
63+
TEXT_INPUT_LABEL_MAX = 45
64+
TEXT_INPUT_PLACEHOLDER_MAX = 100
65+
TEXT_INPUT_MIN_LENGTH_MIN = 0
66+
TEXT_INPUT_MIN_LENGTH_MAX = 4000
67+
TEXT_INPUT_MAX_LENGTH_MIN = 1
68+
TEXT_INPUT_MAX_LENGTH_MAX = 4000
69+
TEXT_INPUT_VALUE_MAX = 4000
70+
71+
# TextDisplay constraints
72+
TEXT_DISPLAY_CONTENT_MAX = 4000
73+
74+
# Thumbnail constraints
75+
THUMBNAIL_DESCRIPTION_MAX = 256
76+
77+
# Custom ID constraints
78+
CUSTOM_ID_MIN = 1
79+
CUSTOM_ID_MAX = 100
80+
81+
# RadioGroup constraints
82+
RADIO_OPTIONS_MAX = 10
83+
84+
# CheckboxGroup constraints
85+
CHECKBOX_OPTIONS_MAX = 10
86+
CHECKBOX_MIN_VALUES_MIN = 0
87+
CHECKBOX_MIN_VALUES_MAX = 10
88+
CHECKBOX_MAX_VALUES_MIN = 1
89+
CHECKBOX_MAX_VALUES_MAX = 10
90+
91+
# FileUpload constraints
92+
FILE_UPLOAD_MIN_FILES = 0
93+
FILE_UPLOAD_MAX_FILES_MIN = 1
94+
FILE_UPLOAD_MAX_FILES_MAX = 10
95+
96+
# Modal constraints
97+
MODAL_TITLE_MAX = 45
98+
MODAL_ROWS_MAX = 5

discord/ui/core.py

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -32,79 +32,8 @@
3232
from ..utils import find, get
3333
from .item import Item, ItemCallbackType
3434

35-
__all__ = ("ItemInterface", "ComponentLimits")
36-
37-
38-
class ComponentLimits:
39-
# View constraints
40-
VIEW_CHILDREN_MAX = 40
41-
42-
# ActionRow constraints
43-
ACTION_ROW_CHILDREN_MAX = 5
44-
45-
# Button constraints
46-
BUTTON_LABEL_MAX = 80
47-
48-
# MediaGallery constraints
49-
MEDIA_GALLERY_ITEMS_MIN = 1
50-
MEDIA_GALLERY_ITEMS_MAX = 10
51-
52-
# MediaGalleryItem constraints
53-
MEDIA_GALLERY_ITEM_DESCRIPTION_MAX = 256
54-
55-
# Select constraints
56-
SELECT_PLACEHOLDER_MAX = 150
57-
SELECT_OPTIONS_MAX = 25
58-
SELECT_DEFAULT_VALUES_MAX = 25
59-
60-
# Select option constraints
61-
SELECT_OPTION_LABEL_MAX = 100
62-
SELECT_OPTION_VALUE_MAX = 100
63-
SELECT_OPTION_DESCRIPTION_MAX = 100
64-
65-
# Section constraints
66-
SECTION_ACCESSORY_MAX = 1
67-
SECTION_CHILDREN_MIN = 1
68-
SECTION_CHILDREN_MAX = 3
69-
70-
# TextInput constraints
71-
TEXT_INPUT_MAX_COUNT = 5
72-
TEXT_INPUT_LABEL_MAX = 45
73-
TEXT_INPUT_PLACEHOLDER_MAX = 100
74-
TEXT_INPUT_MIN_LENGTH_MIN = 0
75-
TEXT_INPUT_MIN_LENGTH_MAX = 4000
76-
TEXT_INPUT_MAX_LENGTH_MIN = 1
77-
TEXT_INPUT_MAX_LENGTH_MAX = 4000
78-
TEXT_INPUT_VALUE_MAX = 4000
79-
80-
# TextDisplay constraints
81-
TEXT_DISPLAY_CONTENT_MAX = 4000
82-
83-
# Thumbnail constraints
84-
THUMBNAIL_DESCRIPTION_MAX = 256
85-
86-
# Custom ID constraints
87-
CUSTOM_ID_MIN = 1
88-
CUSTOM_ID_MAX = 100
89-
90-
# RadioGroup constraints
91-
RADIO_OPTIONS_MAX = 10
92-
93-
# CheckboxGroup constraints
94-
CHECKBOX_OPTIONS_MAX = 10
95-
CHECKBOX_MIN_VALUES_MIN = 0
96-
CHECKBOX_MIN_VALUES_MAX = 10
97-
CHECKBOX_MAX_VALUES_MIN = 1
98-
CHECKBOX_MAX_VALUES_MAX = 10
99-
100-
# FileUpload constraints
101-
FILE_UPLOAD_MIN_FILES = 0
102-
FILE_UPLOAD_MAX_FILES_MIN = 1
103-
FILE_UPLOAD_MAX_FILES_MAX = 10
104-
105-
# Modal constraints
106-
MODAL_TITLE_MAX = 45
107-
MODAL_ROWS_MAX = 5
35+
__all__ = ("ItemInterface")
36+
10837

10938

11039
if TYPE_CHECKING:

discord/ui/file_upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..components import FileUpload as FileUploadComponent
3131
from ..enums import ComponentType
3232
from ..message import Attachment
33-
from .core import ComponentLimits
33+
from .constant import ComponentLimits
3434
from .item import ModalItem
3535

3636
__all__ = ("FileUpload",)

discord/ui/input_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
from ..components import InputText as InputTextComponent
3131
from ..enums import ComponentType, InputTextStyle
32-
from .core import ComponentLimits
32+
from .constant import ComponentLimits
3333
from .item import ModalItem
3434

3535
__all__ = ("InputText", "TextInput")

discord/ui/media_gallery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from ..components import MediaGallery as MediaGalleryComponent
3030
from ..components import MediaGalleryItem
3131
from ..enums import ComponentType
32-
from .core import ComponentLimits
32+
from .constant import ComponentLimits
3333
from .item import ViewItem
3434

3535
__all__ = ("MediaGallery",)

discord/ui/modal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
from typing import TYPE_CHECKING, Any, Iterator, TypeVar
3434

3535
from ..utils import _get_event_loop
36-
from .core import ComponentLimits, ItemInterface
36+
from .core import ItemInterface
37+
from .constant import ComponentLimits
3738
from .input_text import InputText
3839
from .item import ModalItem
3940

discord/ui/radio_group.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from ..components import RadioGroupOption
3434
from ..enums import ComponentType
3535
from ..utils import MISSING
36-
from .core import ComponentLimits
36+
from .constant import ComponentLimits
3737
from .item import ModalItem
3838

3939
__all__ = ("RadioGroup",)

0 commit comments

Comments
 (0)