discordcn 0.0.1a2__py3-none-any.whl → 0.0.1a3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,286 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright: 2026 plun1331, NiceBots.xyz, DiscordCN Contributors
3
+ # Source (modified): https://gist.github.com/plun1331/d8f375922ee7a98c2961530f946ae8ef
4
+
5
+ """Paginator interface module."""
6
+
7
+ # pyright: reportUnknownMemberType=false
8
+
9
+ from abc import ABC, abstractmethod
10
+ from collections.abc import Sequence
11
+ from typing import Any, Generic, TypeVar
12
+
13
+ import discord
14
+ from typing_extensions import Self, override
15
+
16
+ from discordcn.pycord._utils import maybe_awaitable
17
+
18
+ from ._types import EmojiType
19
+
20
+ T = TypeVar("T", bound="PaginatorInterfaceBase")
21
+
22
+
23
+ class PaginatorInterfaceBase(ABC, discord.ui.DesignerView):
24
+ """ABC defining the interface for paginator views.
25
+
26
+ This ABC specifies the minimum requirements for a view to be
27
+ compatible with paginator controls, ensuring consistent behavior across
28
+ different paginator implementations.
29
+
30
+ Attributes:
31
+ page: The current page index (0-based).
32
+ """
33
+
34
+ page: int
35
+
36
+ @property
37
+ @abstractmethod
38
+ def max_page(self) -> int:
39
+ """The maximum page index (0-based)."""
40
+ ...
41
+
42
+ @abstractmethod
43
+ def update(self) -> None:
44
+ """Update the view to reflect the current page state."""
45
+ ...
46
+
47
+
48
+ class PaginatorControlsBase(ABC, discord.ui.ActionRow[T], Generic[T]):
49
+ """ABC defining the interface for paginator controls.
50
+
51
+ This ABC specifies the minimum requirements for a paginator controls
52
+ component, ensuring consistent behavior across different implementations.
53
+ """
54
+
55
+ @abstractmethod
56
+ def __init__(self, view: PaginatorInterfaceBase) -> None:
57
+ """Initialize paginator controls.
58
+
59
+ Args:
60
+ view: The parent paginator view implementing PaginatorInterfaceBase.
61
+ """
62
+ ...
63
+
64
+
65
+ class PageButton(discord.ui.Button[PaginatorInterfaceBase]):
66
+ """Navigation button for jumping to a specific page.
67
+
68
+ This button updates the parent view's page index and refreshes the UI
69
+ when clicked. It is designed to work with any view implementing
70
+ PaginatorInterfaceBase.
71
+
72
+ Attributes:
73
+ page: The target page index this button navigates to.
74
+ """
75
+
76
+ def __init__(self, page: int, **kwargs: Any) -> None:
77
+ """Initialize a page navigation button.
78
+
79
+ Args:
80
+ page: The target page index (0-based) to navigate to when clicked.
81
+ **kwargs: Additional keyword arguments passed to the parent
82
+ discord.ui.Button constructor (e.g., ``emoji``, ``style``,
83
+ ``disabled``).
84
+ """
85
+ super().__init__(**kwargs)
86
+ self.page: int = page
87
+
88
+ @override
89
+ async def callback(self, interaction: discord.Interaction) -> None:
90
+ """Handle button click interactions.
91
+
92
+ Updates the parent view's page index, triggers a view update, and
93
+ edits the message to reflect the new page state.
94
+
95
+ Args:
96
+ interaction: The interaction object from the button click.
97
+ """
98
+ if self.view is None:
99
+ msg = "This button is not attached to a view."
100
+ raise TypeError(msg)
101
+ v = self.view
102
+ v.page = self.page
103
+ await maybe_awaitable(v.update())
104
+ if interaction.response.is_done():
105
+ await interaction.edit_original_response(view=v)
106
+ else:
107
+ await interaction.response.edit_message(view=v)
108
+
109
+
110
+ class PageIndicatorButton(discord.ui.Button[PaginatorInterfaceBase]):
111
+ """Non-interactive button displaying the current page number.
112
+
113
+ This button serves as a visual indicator of the current page position
114
+ and is always disabled to prevent interaction. It displays text in the
115
+ format "Page X/Y".
116
+ """
117
+
118
+ def __init__(self, *, label: str) -> None:
119
+ """Initialize a page indicator button.
120
+
121
+ Args:
122
+ label: The text to display on the button (typically "Page X/Y").
123
+ """
124
+ super().__init__(style=discord.ButtonStyle.secondary, label=label)
125
+ self.disabled: bool = True
126
+
127
+ @override
128
+ async def callback(self, interaction: discord.Interaction) -> None:
129
+ """Handle button click interactions (no-op).
130
+
131
+ This callback defers the interaction invisibly since the button is
132
+ disabled and should never be clicked.
133
+
134
+ Args:
135
+ interaction: The interaction object from the button click.
136
+ """
137
+ await interaction.response.defer(invisible=True)
138
+
139
+
140
+ class PaginatorControls(PaginatorControlsBase[T], Generic[T]):
141
+ """Navigation controls row for paginator interfaces.
142
+
143
+ This action row contains five elements:
144
+ - First page button (⏮️): Jump to page 0
145
+ - Previous page button (◀️): Go back one page
146
+ - Page indicator: Display current page position (non-interactive)
147
+ - Next page button (▶️): Advance one page
148
+ - Last page button (⏭️): Jump to the final page
149
+
150
+ Buttons are automatically disabled when they would navigate beyond valid
151
+ page boundaries (e.g., previous/first buttons on page 0).
152
+
153
+ Attributes:
154
+ FIRST_EMOJI: The emoji to use for the "first page" button.
155
+ LEFT_EMOJI: The emoji to use for the "previous page" button.
156
+ RIGHT_EMOJI: The emoji to use for the "next page" button.
157
+ LAST_EMOJI: The emoji to use for the "last page" button.
158
+ """
159
+
160
+ FIRST_EMOJI: EmojiType = discord.PartialEmoji(name="⏮️")
161
+ LEFT_EMOJI: EmojiType = discord.PartialEmoji(name="◀️")
162
+ RIGHT_EMOJI: EmojiType = discord.PartialEmoji(name="▶️")
163
+ LAST_EMOJI: EmojiType = discord.PartialEmoji(name="⏭️")
164
+
165
+ def __init__(
166
+ self,
167
+ view: T,
168
+ ) -> None:
169
+ """Initialize paginator navigation controls.
170
+
171
+ Creates a row of navigation buttons with appropriate enabled/disabled
172
+ states based on the current page position.
173
+
174
+ Args:
175
+ view: The parent paginator view implementing PaginatorInterfaceBase.
176
+ """
177
+ discord.ui.ActionRow.__init__(self)
178
+ self.add_item(
179
+ PageButton(
180
+ 0,
181
+ emoji=self.FIRST_EMOJI,
182
+ style=discord.ButtonStyle.primary,
183
+ disabled=view.page == 0,
184
+ ),
185
+ )
186
+ self.add_item(
187
+ PageButton(
188
+ view.page - 1,
189
+ emoji=self.LEFT_EMOJI,
190
+ style=discord.ButtonStyle.secondary,
191
+ disabled=view.page == 0,
192
+ )
193
+ )
194
+ self.add_item(
195
+ PageIndicatorButton(
196
+ label=f"{view.page + 1}/{view.max_page + 1}",
197
+ ),
198
+ )
199
+ self.add_item(
200
+ PageButton(
201
+ view.page + 1,
202
+ emoji=self.RIGHT_EMOJI,
203
+ style=discord.ButtonStyle.secondary,
204
+ disabled=view.page == view.max_page,
205
+ )
206
+ )
207
+ self.add_item(
208
+ PageButton(
209
+ view.max_page,
210
+ emoji=self.LAST_EMOJI,
211
+ style=discord.ButtonStyle.primary,
212
+ disabled=view.page == view.max_page,
213
+ )
214
+ )
215
+
216
+
217
+ class PaginatorInterface(PaginatorInterfaceBase):
218
+ """Multi-page view with automatic navigation controls.
219
+
220
+ This view manages navigation between multiple pages of UI components,
221
+ automatically displaying the appropriate page content and navigation
222
+ controls. Each page is defined as a sequence of view items (buttons,
223
+ selects, etc.) that are dynamically loaded when navigating between pages.
224
+
225
+ The paginator automatically appends navigation controls to the bottom of
226
+ each page, allowing users to move between pages using first/previous/next/last
227
+ buttons and see their current position.
228
+
229
+ Attributes:
230
+ pages: The sequence of pages, where each page is a sequence of view items.
231
+ page: The current page index (0-based).
232
+ controls: The paginator controls class to use for navigation.
233
+ """
234
+
235
+ def __init__(
236
+ self,
237
+ pages: Sequence[Sequence[discord.ui.ViewItem[discord.ui.DesignerView]]],
238
+ controls: type[PaginatorControlsBase[Self]] = PaginatorControls,
239
+ ) -> None:
240
+ """Initialize a paginator view.
241
+
242
+ Args:
243
+ pages: A sequence of pages, where each page is a sequence of view items
244
+ (buttons, selects, etc.) to display on that page. Navigation controls
245
+ are automatically added to each page.
246
+ controls: The paginator controls class to use for navigation. Defaults
247
+ to PaginatorControls.
248
+ """
249
+ super().__init__(timeout=300)
250
+ self.pages: Sequence[Sequence[discord.ui.ViewItem[discord.ui.DesignerView]]] = pages
251
+ self.page: int = 0
252
+ self.controls: type[PaginatorControlsBase[Self]] = controls
253
+ self.update()
254
+
255
+ @property
256
+ @override
257
+ def max_page(self) -> int:
258
+ """The maximum page index (0-based).
259
+
260
+ Returns:
261
+ The index of the last page, equal to ``len(pages) - 1``.
262
+ """
263
+ return len(self.pages) - 1
264
+
265
+ @override
266
+ def update(self) -> None:
267
+ """Update the view to display the current page.
268
+
269
+ Clears all existing items, adds items from the current page, and
270
+ appends navigation controls. This method is called automatically
271
+ when navigating between pages.
272
+ """
273
+ self.clear_items()
274
+ for item in self.pages[self.page]:
275
+ self.add_item(item)
276
+ self.add_item(self.controls(self))
277
+
278
+
279
+ __all__ = (
280
+ "PageButton",
281
+ "PageIndicatorButton",
282
+ "PaginatorControls",
283
+ "PaginatorControlsBase",
284
+ "PaginatorInterface",
285
+ "PaginatorInterfaceBase",
286
+ )
@@ -0,0 +1,93 @@
1
+ Metadata-Version: 2.4
2
+ Name: discordcn
3
+ Version: 0.0.1a3
4
+ Summary: An unofficial, community-driven implementation for Discord app interface patterns.
5
+ Project-URL: Homepage, https://github.com/nicebots-xyz/discordcn-py
6
+ Project-URL: source_archive, https://github.com/nicebots-xyz/discordcn-py/archive/3d2717cc3b78e67dfbbef52df1bc92f0406e734d.zip
7
+ Author-email: Paillat-dev <me@paillat.dev>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: discord
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: <3.15,>=3.10
23
+ Requires-Dist: typing-extensions>=4.15.0
24
+ Provides-Extra: dpy
25
+ Requires-Dist: discord-py==2.6.4; extra == 'dpy'
26
+ Provides-Extra: pycord
27
+ Requires-Dist: py-cord==2.7; extra == 'pycord'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # discordcn-py
31
+
32
+ Python library implementations for [DiscordCN](https://discordcn.dev) - an unofficial, community-driven reference for
33
+ Discord app interface patterns.
34
+
35
+ > \**NOTE**:
36
+ > This project is NOT made by Discord and does NOT represent official Discord UI guidelines. For official resources, see
37
+ > the [Discord Developer Docs](https://discord.com/developers/docs/components/overview).
38
+
39
+ ## Installation
40
+
41
+ ```bash
42
+ pip install discordcn
43
+ ```
44
+
45
+ ### With Optional Dependencies
46
+
47
+ For Pycord:
48
+
49
+ ```bash
50
+ pip install discordcn[pycord]
51
+ ```
52
+
53
+ For discord.py:
54
+
55
+ ```bash
56
+ pip install discordcn[dpy]
57
+ ```
58
+
59
+ ## Requirements
60
+
61
+ * Python >=3.10, <3.15
62
+ * typing-extensions >=4.15.0
63
+
64
+ ## Status
65
+
66
+ This project is currently in alpha development. Features and API may change.
67
+
68
+ ## Related Projects
69
+
70
+ * [discordcn](https://github.com/nicebots-xyz/discordcn) - Main project with documentation and examples
71
+ * [discord.builders](https://github.com/StartITBot/discord.builders) - Code generation engine and SDK
72
+
73
+ ## Community & Support
74
+
75
+ * **Website:** [discordcn.dev](https://discordcn.dev)
76
+ * **Issues:** [GitHub Issues](https://github.com/nicebots-xyz/discordcn-py/issues)
77
+ * **Discord:** [NiceBots Discord](https://discord.gg/4Rj2bcZ7MD)
78
+
79
+ ## Contributing & Governance
80
+
81
+ For contributing guidelines, security policies, and code of conduct, please refer to the
82
+ main [discordcn repository](https://github.com/nicebots-xyz/discordcn):
83
+
84
+ * [CONTRIBUTING.md](https://github.com/nicebots-xyz/discordcn/blob/master/CONTRIBUTING.md)
85
+ * [SECURITY.md](https://github.com/nicebots-xyz/discordcn/blob/master/SECURITY.md)
86
+ * [CODE\_OF\_CONDUCT.md](https://github.com/nicebots-xyz/discordcn/blob/master/CODE_OF_CONDUCT.md)
87
+ * [SUPPORT.md](https://github.com/nicebots-xyz/discordcn/blob/master/SUPPORT.md)
88
+
89
+ ## License
90
+
91
+ MIT License - see [LICENSE](https://github.com/nicebots-xyz/discordcn-py/tree/masterLICENSE) file for details.
92
+
93
+ Discord is a trademark of Discord Inc. and is not affiliated with DiscordCN or NiceBots.
@@ -0,0 +1,17 @@
1
+ discordcn/__init__.py,sha256=M-tPvQrNqMrw6MX2TX2v8XMEc_nnaF_PUdkjAUEnWEA,30
2
+ discordcn/_version.py,sha256=feGu-ZJF6DzSJ8aupwdzLU1-Im73F2UGHqiwKcRkDOM,712
3
+ discordcn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ discordcn/_utils/__init__.py,sha256=Kjk4SSBNj8W1tez3WFgBGcCXiOCF_k5rUw_u42hzkyk,70
5
+ discordcn/_utils/dependencies.py,sha256=ipGc1DYJfbV7zgLwWN9sZnWjJseh0zqHPm-OabGFEKM,5932
6
+ discordcn/pycord/__init__.py,sha256=wxoDZMpCXKBWCk7v1t8YaRUM6T86YgWiF4GN8yrfzX8,605
7
+ discordcn/pycord/_utils/__init__.py,sha256=qdiz75w8BWBe3Hx_pEjRjLOVIXCLqAesHsf0jERIUQI,228
8
+ discordcn/pycord/_utils/_asyncio.py,sha256=C1mvWsaysEcI-r_c8rVPq-Xqm5vFxjIRaH5o8mNOHyc,756
9
+ discordcn/pycord/interfaces/__init__.py,sha256=C1YKw_k_5TeCK7hlwHaw25TCyKrhmCY10W5UVA5wLho,510
10
+ discordcn/pycord/interfaces/_types.py,sha256=wC30UtEU81qk5_PnVJb8tZIwpQ5LhpoSknlETeuAWmU,353
11
+ discordcn/pycord/interfaces/accordion.py,sha256=VbXM56rmJZvSP4Tg4iG3v2T9rVgxUuHzHVsO9_ZPK6g,17799
12
+ discordcn/pycord/interfaces/confirm.py,sha256=LIXZRVk9wnhv8PDzTY34U3AiwZgOdKG2bnlxS8rfdqs,8194
13
+ discordcn/pycord/interfaces/paginator.py,sha256=E7xhcW6vjzmc-R130JHDXlGQY6XfftfsFfZM_kxqeKY,9588
14
+ discordcn-0.0.1a3.dist-info/METADATA,sha256=1wvlBW_hxtbrKjcZwFqvqNY4AtH3WjVtT-f7frlfSrc,3187
15
+ discordcn-0.0.1a3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
16
+ discordcn-0.0.1a3.dist-info/licenses/LICENSE,sha256=GtM5nF4RszKjPj7YvDquoqanaubrF0KhbD8-k6t_648,1069
17
+ discordcn-0.0.1a3.dist-info/RECORD,,
@@ -1,26 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: discordcn
3
- Version: 0.0.1a2
4
- Dynamic: Project-URL
5
- Summary: TBD
6
- Author-email: Paillat-dev <me@paillat.dev>
7
- License-Expression: MIT
8
- License-File: LICENSE
9
- Keywords: discord
10
- Classifier: Development Status :: 3 - Alpha
11
- Classifier: Intended Audience :: Developers
12
- Classifier: License :: OSI Approved :: MIT License
13
- Classifier: Operating System :: OS Independent
14
- Classifier: Programming Language :: Python :: 3 :: Only
15
- Classifier: Programming Language :: Python :: 3.10
16
- Classifier: Programming Language :: Python :: 3.11
17
- Classifier: Programming Language :: Python :: 3.12
18
- Classifier: Programming Language :: Python :: 3.13
19
- Classifier: Programming Language :: Python :: 3.14
20
- Classifier: Typing :: Typed
21
- Requires-Python: <3.15,>=3.10
22
- Description-Content-Type: text/markdown
23
-
24
- # discordcn (Python)
25
-
26
- Reserved for future use by [nicebots.xyz](https://nicebots.xyz/). Please contact me@paillat.dev for more information.
@@ -1,7 +0,0 @@
1
- discordcn/__init__.py,sha256=1Ol9uOvBq1H9Hw4UIwV1CCw6vEaAaYEDnuCqMa7MrpM,63
2
- discordcn/_version.py,sha256=cJu3a6F6LwSc1cJz18IpVaxyDouCVdfx5VAGQZd4tFY,712
3
- discordcn/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- discordcn-0.0.1a2.dist-info/METADATA,sha256=66UYQaB3Gl34FuP69wIXvUHlhXQFDkfEUecYlqlXZO0,932
5
- discordcn-0.0.1a2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
6
- discordcn-0.0.1a2.dist-info/licenses/LICENSE,sha256=GtM5nF4RszKjPj7YvDquoqanaubrF0KhbD8-k6t_648,1069
7
- discordcn-0.0.1a2.dist-info/RECORD,,