|
26 | 26 | from __future__ import annotations |
27 | 27 |
|
28 | 28 | import asyncio |
| 29 | +import contextlib |
29 | 30 | import os |
30 | 31 | import sys |
31 | 32 | import time |
|
42 | 43 |
|
43 | 44 | from typing_extensions import Self |
44 | 45 |
|
| 46 | +import discord |
| 47 | + |
45 | 48 | from ..components import ActionRow as ActionRowComponent |
46 | 49 | from ..components import Button as ButtonComponent |
47 | | -from ..components import Component |
| 50 | +from ..components import Component, FileComponent, _component_factory |
48 | 51 | from ..components import Container as ContainerComponent |
49 | | -from ..components import FileComponent |
50 | 52 | from ..components import Label as LabelComponent |
51 | 53 | from ..components import MediaGallery as MediaGalleryComponent |
52 | 54 | from ..components import Section as SectionComponent |
53 | 55 | from ..components import SelectMenu as SelectComponent |
54 | 56 | from ..components import Separator as SeparatorComponent |
55 | 57 | from ..components import TextDisplay as TextDisplayComponent |
56 | 58 | from ..components import Thumbnail as ThumbnailComponent |
57 | | -from ..components import _component_factory |
58 | | -from ..utils import find |
59 | 59 | from .core import ItemInterface |
60 | 60 | from .item import ItemCallbackType, ViewItem |
61 | 61 |
|
@@ -96,7 +96,6 @@ def _walk_all_components_v2(components: list[Component]) -> Iterator[Component]: |
96 | 96 |
|
97 | 97 |
|
98 | 98 | def _component_to_item(component: Component) -> ViewItem[V]: |
99 | | - |
100 | 99 | if isinstance(component, ButtonComponent): |
101 | 100 | from .button import Button |
102 | 101 |
|
@@ -309,7 +308,8 @@ async def on_timeout(self) -> None: |
309 | 308 | message = self.message |
310 | 309 |
|
311 | 310 | if message: |
312 | | - m = await message.edit(view=self) |
| 311 | + async with contextlib.suppress(discord.HTTPException): |
| 312 | + m = await message.edit(view=self) |
313 | 313 | if m: |
314 | 314 | self._message = m |
315 | 315 |
|
@@ -681,7 +681,7 @@ def add_item(self, item: ViewItem[V]) -> Self: |
681 | 681 |
|
682 | 682 | if item._underlying.is_v2(): |
683 | 683 | raise ValueError( |
684 | | - f"cannot use V2 components in View. Use DesignerView instead." |
| 684 | + "cannot use V2 components in View. Use DesignerView instead." |
685 | 685 | ) |
686 | 686 | if isinstance(item._underlying, ActionRowComponent): |
687 | 687 | for i in item.children: |
@@ -718,7 +718,9 @@ def clear_items(self) -> None: |
718 | 718 | def refresh(self, components: list[Component]): |
719 | 719 | # This is pretty hacky at the moment |
720 | 720 | old_state: dict[tuple[int, str], ViewItem[V]] = { |
721 | | - (item.type.value, item.custom_id): item for item in self.children if item.is_dispatchable() # type: ignore |
| 721 | + (item.type.value, item.custom_id): item |
| 722 | + for item in self.children |
| 723 | + if item.is_dispatchable() # type: ignore |
722 | 724 | } |
723 | 725 | children: list[ViewItem[V]] = [ |
724 | 726 | item for item in self.children if not item.is_dispatchable() |
@@ -878,7 +880,7 @@ def add_item(self, item: ViewItem[V]) -> Self: |
878 | 880 |
|
879 | 881 | if isinstance(item._underlying, (SelectComponent, ButtonComponent)): |
880 | 882 | raise ValueError( |
881 | | - f"cannot add Select or Button to DesignerView directly. Use ActionRow instead." |
| 883 | + "cannot add Select or Button to DesignerView directly. Use ActionRow instead." |
882 | 884 | ) |
883 | 885 |
|
884 | 886 | super().add_item(item) |
@@ -909,9 +911,9 @@ def is_components_v2(self) -> bool: |
909 | 911 | class ViewStore: |
910 | 912 | def __init__(self, state: ConnectionState): |
911 | 913 | # (component_type, message_id, custom_id): (BaseView, ViewItem) |
912 | | - self._views: dict[tuple[int, int | None, str], tuple[BaseView, ViewItem[V]]] = ( |
913 | | - {} |
914 | | - ) |
| 914 | + self._views: dict[ |
| 915 | + tuple[int, int | None, str], tuple[BaseView, ViewItem[V]] |
| 916 | + ] = {} |
915 | 917 | # message_id: View |
916 | 918 | self._synced_message_views: dict[int, BaseView] = {} |
917 | 919 | self._state: ConnectionState = state |
@@ -942,7 +944,10 @@ def add_view(self, view: BaseView, message_id: int | None = None): |
942 | 944 | view._start_listening_from_store(self) |
943 | 945 | for item in view.walk_children(): |
944 | 946 | if item.is_storable(): |
945 | | - self._views[(item.type.value, message_id, item.custom_id)] = (view, item) # type: ignore |
| 947 | + self._views[(item.type.value, message_id, item.custom_id)] = ( |
| 948 | + view, |
| 949 | + item, |
| 950 | + ) # type: ignore |
946 | 951 |
|
947 | 952 | if message_id is not None: |
948 | 953 | self._synced_message_views[message_id] = view |
|
0 commit comments