2727
2828from typing import TYPE_CHECKING , Any , ClassVar , TypeVar
2929
30- from .enums import ButtonStyle , ChannelType , ComponentType , InputTextStyle , SeparatorSpacingSize , try_enum
30+ from .enums import (
31+ ButtonStyle ,
32+ ChannelType ,
33+ ComponentType ,
34+ InputTextStyle ,
35+ SeparatorSpacingSize ,
36+ try_enum ,
37+ )
3138from .partial_emoji import PartialEmoji , _EmojiTag
3239from .utils import MISSING , get_slots
3340
3441if TYPE_CHECKING :
3542 from .emoji import AppEmoji , GuildEmoji
3643 from .types .components import ActionRow as ActionRowPayload
44+ from .types .components import BaseComponent as BaseComponentPayload
3745 from .types .components import ButtonComponent as ButtonComponentPayload
3846 from .types .components import Component as ComponentPayload
39- from .types .components import BaseComponent as BaseComponentPayload
47+ from .types .components import ContainerComponent as ContainerComponentPayload
48+ from .types .components import FileComponent as FileComponentPayload
4049 from .types .components import InputText as InputTextComponentPayload
50+ from .types .components import MediaGalleryComponent as MediaGalleryComponentPayload
51+ from .types .components import MediaGalleryItem as MediaGalleryItemPayload
52+ from .types .components import SectionComponent as SectionComponentPayload
4153 from .types .components import SelectMenu as SelectMenuPayload
4254 from .types .components import SelectOption as SelectOptionPayload
55+ from .types .components import SeparatorComponent as SeparatorComponentPayload
4356 from .types .components import TextDisplayComponent as TextDisplayComponentPayload
44- from .types .components import SectionComponent as SectionComponentPayload
45- from .types .components import UnfurledMediaItem as UnfurledMediaItemPayload
4657 from .types .components import ThumbnailComponent as ThumbnailComponentPayload
47- from .types .components import MediaGalleryItem as MediaGalleryItemPayload
48- from .types .components import MediaGalleryComponent as MediaGalleryComponentPayload
49- from .types .components import FileComponent as FileComponentPayload
50- from .types .components import SeparatorComponent as SeparatorComponentPayload
51- from .types .components import ContainerComponent as ContainerComponentPayload
58+ from .types .components import UnfurledMediaItem as UnfurledMediaItemPayload
5259
5360__all__ = (
5461 "Component" ,
6370
6471C = TypeVar ("C" , bound = "Component" )
6572
73+
6674class Component :
6775 """Represents a Discord Bot UI Kit Component.
6876
@@ -532,7 +540,9 @@ class Section(Component):
532540 def __init__ (self , data : SectionComponentPayload ):
533541 self .type : ComponentType = try_enum (ComponentType , data ["type" ])
534542 self .id : str = data .get ("id" )
535- self .components : list [Component ] = [_component_factory (d ) for d in data .get ("components" , [])]
543+ self .components : list [Component ] = [
544+ _component_factory (d ) for d in data .get ("components" , [])
545+ ]
536546 self .accessory : Component | None = None
537547 if _accessory := data .get ("accessory" ):
538548 self .accessory = _component_factory (_accessory )
@@ -541,7 +551,7 @@ def to_dict(self) -> SectionComponentPayload:
541551 payload = {
542552 "type" : int (self .type ),
543553 "id" : self .id ,
544- "components" : [c .to_dict () for c in self .components ]
554+ "components" : [c .to_dict () for c in self .components ],
545555 }
546556 if self .accessory :
547557 payload ["accessory" ] = self .accessory .to_dict ()
@@ -573,11 +583,7 @@ def __init__(self, data: TextDisplayComponentPayload):
573583 self .content : str = data .get ("content" )
574584
575585 def to_dict (self ) -> TextDisplayComponentPayload :
576- return {
577- "type" : int (self .type ),
578- "id" : self .id ,
579- "content" : self .content
580- }
586+ return {"type" : int (self .type ), "id" : self .id , "content" : self .content }
581587
582588
583589COMPONENT_MAPPINGS = {
@@ -598,6 +604,7 @@ def to_dict(self) -> TextDisplayComponentPayload:
598604 17 : None ,
599605}
600606
607+
601608def _component_factory (data : ComponentPayload ) -> Component :
602609 component_type = data ["type" ]
603610 if cls := COMPONENT_MAPPINGS .get (component_type ):
0 commit comments