scurrypy 0.4.2__py3-none-any.whl → 0.5.3__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.

Potentially problematic release.


This version of scurrypy might be problematic. Click here for more details.

Files changed (65) hide show
  1. scurrypy/__init__.py +376 -0
  2. {discord → scurrypy}/client_like.py +1 -1
  3. {discord → scurrypy}/dispatch/command_dispatcher.py +13 -5
  4. {discord → scurrypy}/dispatch/event_dispatcher.py +15 -15
  5. {discord → scurrypy}/events/channel_events.py +1 -1
  6. {discord → scurrypy}/events/interaction_events.py +21 -9
  7. {discord → scurrypy}/events/message_events.py +4 -4
  8. {discord → scurrypy}/http.py +1 -1
  9. {discord → scurrypy}/intents.py +1 -1
  10. scurrypy/model.py +71 -0
  11. {discord → scurrypy}/models/emoji.py +17 -1
  12. {discord → scurrypy}/models/interaction.py +5 -0
  13. scurrypy/parts/channel.py +42 -0
  14. scurrypy/parts/command.py +90 -0
  15. scurrypy/parts/components.py +224 -0
  16. scurrypy/parts/components_v2.py +144 -0
  17. scurrypy/parts/embed.py +83 -0
  18. scurrypy/parts/message.py +137 -0
  19. scurrypy/parts/modal.py +16 -0
  20. {discord → scurrypy}/parts/role.py +1 -13
  21. {discord → scurrypy}/resources/channel.py +6 -6
  22. {discord → scurrypy}/resources/guild.py +3 -4
  23. {discord → scurrypy}/resources/interaction.py +23 -22
  24. {discord → scurrypy}/resources/message.py +13 -13
  25. {scurrypy-0.4.2.dist-info → scurrypy-0.5.3.dist-info}/METADATA +19 -25
  26. scurrypy-0.5.3.dist-info/RECORD +54 -0
  27. scurrypy-0.5.3.dist-info/top_level.txt +1 -0
  28. discord/__init__.py +0 -223
  29. discord/model.py +0 -90
  30. discord/parts/action_row.py +0 -208
  31. discord/parts/channel.py +0 -20
  32. discord/parts/command.py +0 -102
  33. discord/parts/components_v2.py +0 -353
  34. discord/parts/embed.py +0 -154
  35. discord/parts/message.py +0 -194
  36. discord/parts/modal.py +0 -21
  37. scurrypy-0.4.2.dist-info/RECORD +0 -54
  38. scurrypy-0.4.2.dist-info/top_level.txt +0 -1
  39. {discord → scurrypy}/client.py +0 -0
  40. {discord → scurrypy}/config.py +0 -0
  41. {discord → scurrypy}/dispatch/__init__.py +0 -0
  42. {discord → scurrypy}/dispatch/prefix_dispatcher.py +0 -0
  43. {discord → scurrypy}/error.py +0 -0
  44. {discord → scurrypy}/events/__init__.py +0 -0
  45. {discord → scurrypy}/events/guild_events.py +0 -0
  46. {discord → scurrypy}/events/hello_event.py +0 -0
  47. {discord → scurrypy}/events/reaction_events.py +0 -0
  48. {discord → scurrypy}/events/ready_event.py +0 -0
  49. {discord → scurrypy}/gateway.py +0 -0
  50. {discord → scurrypy}/logger.py +0 -0
  51. {discord → scurrypy}/models/__init__.py +0 -0
  52. {discord → scurrypy}/models/application.py +0 -0
  53. {discord → scurrypy}/models/guild.py +0 -0
  54. {discord → scurrypy}/models/integration.py +0 -0
  55. {discord → scurrypy}/models/member.py +0 -0
  56. {discord → scurrypy}/models/role.py +0 -0
  57. {discord → scurrypy}/models/user.py +0 -0
  58. {discord → scurrypy}/parts/__init__.py +0 -0
  59. {discord → scurrypy}/parts/component_types.py +0 -0
  60. {discord → scurrypy}/resources/__init__.py +0 -0
  61. {discord → scurrypy}/resources/application.py +0 -0
  62. {discord → scurrypy}/resources/bot_emojis.py +0 -0
  63. {discord → scurrypy}/resources/user.py +0 -0
  64. {scurrypy-0.4.2.dist-info → scurrypy-0.5.3.dist-info}/WHEEL +0 -0
  65. {scurrypy-0.4.2.dist-info → scurrypy-0.5.3.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,54 @@
1
+ scurrypy/__init__.py,sha256=yQ2NLNMJ6jZ51IpNxV9pOHm6sRCMOCRDErPa9JA3y54,10329
2
+ scurrypy/client.py,sha256=feTk5CXgYEMeV9bd3ahz2TcrjqtjRElVRBGU6wwzaoY,14225
3
+ scurrypy/client_like.py,sha256=1wTcHJIGQAPLJ5m4N_wsdxAq-6lGLifkBCZc0Rq9aSc,474
4
+ scurrypy/config.py,sha256=OH1A2mNKhDlGvQYASEsVUx2pNxP1YQ2a7a7z-IM5xFg,200
5
+ scurrypy/error.py,sha256=AlislRTna554cM6KC0KrwKugzYDYtx_9C8_3QFe4XDc,2070
6
+ scurrypy/gateway.py,sha256=L0SE7N29rg02JtNv670JMbw8LMLvtEsLF4LPM33OlHM,5110
7
+ scurrypy/http.py,sha256=ynpfECHEXtJSGz6RE3ZwGjD33ErD6WkqkEUHmP5kl_o,7894
8
+ scurrypy/intents.py,sha256=syJIGibRI3j42ykxiOyzvG9VjIvla9AIqInkqmxVkUY,2867
9
+ scurrypy/logger.py,sha256=7lks8VyU538nUr_OfiUXRFOtXlpOLZSLvLoDRxJ8loY,4929
10
+ scurrypy/model.py,sha256=vJS2pxJ9yS1zxypWNUnbkqzNqBDaytTUDiXfLM0k364,2372
11
+ scurrypy/dispatch/__init__.py,sha256=m7ixrbNhOV9QRORXPw6LSwxofQMAvLmPFBweBZu9ACc,20
12
+ scurrypy/dispatch/command_dispatcher.py,sha256=5uux7xaIUVyMhAbh3DOdwCxXxINFihcS1Di5UhDHdl4,6291
13
+ scurrypy/dispatch/event_dispatcher.py,sha256=A6FFKLBL_WFh1NVaWUkDZmbYBqus2SCI4PMC7wZLSpE,3784
14
+ scurrypy/dispatch/prefix_dispatcher.py,sha256=HXgL5XqrQK08iJ4G_SgsLuC-s0YoH3FlqPY_bR6JLlQ,2115
15
+ scurrypy/events/__init__.py,sha256=xE8YtJ7NKZkm7MLnohDQIbezh3ColmLR-3BMiZabt3k,18
16
+ scurrypy/events/channel_events.py,sha256=EnhrdcuS6ZgmAD2czZGP3q77ghaAB12JyUi6ZeTQGlY,1567
17
+ scurrypy/events/guild_events.py,sha256=Ok9tW3tjcwtbiqJgbe-42d9-R3-2RzqmIgBHEP-2Pcc,896
18
+ scurrypy/events/hello_event.py,sha256=O8Ketu_N943cnGaFkGsAHfWhgKXFQCYCqSD3EqdsXjA,225
19
+ scurrypy/events/interaction_events.py,sha256=GU17i7HCNYCkggu9oktFdqG9ofZKvmSe0pXaZrtg3oY,4733
20
+ scurrypy/events/message_events.py,sha256=ZZK5aK_6wlRt8_6QrQk9jlcf57tFPFg6wap2SilvCPY,1479
21
+ scurrypy/events/reaction_events.py,sha256=xx7GD-fqakhJmS-X-HbuAUg9pg6Gqo_KRtLTdPJu7UE,2643
22
+ scurrypy/events/ready_event.py,sha256=c3Pf4ndNYV2byuliADi8pUxpuvKXa9FLKNz_uzIWGso,794
23
+ scurrypy/models/__init__.py,sha256=ZKhFO5eX4GbTRdvi4CU4z2hO-HQU29WZw2x4DujvARY,18
24
+ scurrypy/models/application.py,sha256=2sXtRysUc2TJ40FjdcrWgosmwMrp_h3ybddubQMixKM,924
25
+ scurrypy/models/emoji.py,sha256=M9u7Cab68_NIsPGYmO8jxR2Tmd8EW7BdgvrVa-dJHEM,1402
26
+ scurrypy/models/guild.py,sha256=aXUByOUUIGt9d2qIGC6_X_vh0Nyib8Iqj5ZElBeNV_I,819
27
+ scurrypy/models/integration.py,sha256=V29RO2925mQbVXPAMt665cML3m8mJACYmdJLWwbbUyE,612
28
+ scurrypy/models/interaction.py,sha256=arej3iBcgUn6X--mXe0s91xs22v2NBLlI5bEqdRrbOU,899
29
+ scurrypy/models/member.py,sha256=pkI-NVRMb3hUBkxI26FSYZxzx2mRNGXOeWWCw3BGGsY,705
30
+ scurrypy/models/role.py,sha256=erlERmK-IZz4YzSNY-XLNvCc-Z5PoVlClxPOX67dQJg,1169
31
+ scurrypy/models/user.py,sha256=lgG6GoU_7L68oHt6PGTzTkU1vrbsclRQzGjKzsLBeKA,298
32
+ scurrypy/parts/__init__.py,sha256=yROb-BqEw-FKXqq_-0WbP33U-Arm_9NpJuEamXpvjeA,19
33
+ scurrypy/parts/channel.py,sha256=iyYUq3swQkGeOkR4aM7tpvaiP2xtOJ69Asuf4G3nuIg,1194
34
+ scurrypy/parts/command.py,sha256=PtgGqh-5qjvKuDkVgLJh5Cw0GP1T55g4DgzMvFivnJw,2321
35
+ scurrypy/parts/component_types.py,sha256=qr1R0jzXpE_h9Xv4P5DyYRSuhxS0Qnm9aag-JKrJvBA,131
36
+ scurrypy/parts/components.py,sha256=Ln4bVfhlfVcVeiKHDP4mjBLwr4VNpW495Gf8YL-93bE,7766
37
+ scurrypy/parts/components_v2.py,sha256=lHcq_F25uHoS-ZkhtetFsrRD0ser6sROHu0F8X-68h4,5481
38
+ scurrypy/parts/embed.py,sha256=-K6MqBB0r1GlGHJQtAVIQ6FcTnncYccIGY6sRPHuVsc,2056
39
+ scurrypy/parts/message.py,sha256=Y6Vjb4Bz752mtVGikRsHkfWBMlqEPeuiwB_4Sz3GZ8k,4142
40
+ scurrypy/parts/modal.py,sha256=u7M01oLMkBJP1P6QUvciYWVMEXHvmLw1AnG_jHxbg-w,417
41
+ scurrypy/parts/role.py,sha256=X4snTtLgluhvt10nUM9j5MveVpn9fh5AIgsIgImA_U4,627
42
+ scurrypy/resources/__init__.py,sha256=EdzYKftSLqqr3Bpzc0_90kfozJXOtp9jNTIHhCTt_-0,21
43
+ scurrypy/resources/application.py,sha256=vYMTli_FSbC7venMepsJ9bkzdEQVkKYpnxCJ9K2XDho,2765
44
+ scurrypy/resources/bot_emojis.py,sha256=RvGCSOBkjS39P2aab0FzYUOTzBOiHX99RLrJZzAYNiU,1701
45
+ scurrypy/resources/channel.py,sha256=AqL_qwdh-rd4AbR5pe3sxJ0YU-mIFijNyKW4sw-QLKc,6903
46
+ scurrypy/resources/guild.py,sha256=LSSdphq5_D5kCTK3bC1SOUYNUMrW7XFv_JMtpK2i140,8195
47
+ scurrypy/resources/interaction.py,sha256=9fjpP33HaPKp_tA6FN26Z6JC12OkhAabv6kaoGhm8oE,6007
48
+ scurrypy/resources/message.py,sha256=NdJ0ShZDd-6hpBQMZ4fUpeXW5IHYmfaZoIsQ-xv4q-s,7503
49
+ scurrypy/resources/user.py,sha256=vk89TnCVi-6ZgbDs_TZTCXrx_NfFS5Q9Wi_itYoaoyg,3085
50
+ scurrypy-0.5.3.dist-info/licenses/LICENSE,sha256=qIlBETYpSEU8glbiwiJbuDxVl-2WIuf1PDqJemMjKkc,792
51
+ scurrypy-0.5.3.dist-info/METADATA,sha256=UpEzPF1fT7QpwKa0LGRWRurFg8ecgDuuJiw7rapuGwI,4801
52
+ scurrypy-0.5.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
53
+ scurrypy-0.5.3.dist-info/top_level.txt,sha256=cP1rrlCOPlavqRZ3JbawO-xKi4QcIWa2VHz2DBf3po4,9
54
+ scurrypy-0.5.3.dist-info/RECORD,,
@@ -0,0 +1 @@
1
+ scurrypy
discord/__init__.py DELETED
@@ -1,223 +0,0 @@
1
- # discord
2
-
3
- import importlib
4
- from typing import TYPE_CHECKING
5
-
6
- __all__ = [
7
- # top-level
8
- "Logger",
9
- "Client",
10
- "Intents",
11
- "set_intents",
12
- "BaseConfig",
13
-
14
- # events
15
- "ReadyEvent",
16
- "ReactionAddEvent",
17
- "ReactionRemoveEvent",
18
- "ReactionRemoveEmojiEvent",
19
- "ReactionRemoveAllEvent",
20
- "GuildCreateEvent",
21
- "GuildUpdateEvent",
22
- "GuildDeleteEvent",
23
- "MessageCreateEvent",
24
- "MessageUpdateEvent",
25
- "MessageDeleteEvent",
26
- "GuildChannelCreateEvent",
27
- "GuildChannelUpdateEvent",
28
- "GuildChannelDeleteEvent",
29
- "ChannelPinsUpdateEvent",
30
- "InteractionEvent",
31
-
32
- # models
33
- "ApplicationModel",
34
- "EmojiModel",
35
- "GuildModel",
36
- "MemberModel",
37
- "UserModel",
38
- "RoleModel",
39
-
40
- # parts
41
- "GuildChannel",
42
- "Role",
43
- "MessageBuilder",
44
- "ModalBuilder",
45
- "EmbedBuilder",
46
- "ActionRow",
47
- "StringSelect",
48
- "UserSelect",
49
- "RoleSelect",
50
- "ChannelSelect",
51
- "MentionableSelect",
52
- "SlashCommand",
53
- "MessageCommand",
54
- "UserCommand",
55
- "Container",
56
- "Section",
57
- "MediaGalleryItem",
58
- "Label",
59
-
60
- # resources
61
- "Guild",
62
- "Channel",
63
- "Message",
64
- "BotEmojis",
65
- "User",
66
- "Interaction",
67
- "Application",
68
- ]
69
-
70
- # For editor support / autocomplete
71
- if TYPE_CHECKING:
72
- from .logger import Logger
73
- from .client import Client
74
- from .intents import Intents, set_intents
75
- from .config import BaseConfig
76
-
77
- # events
78
- from .events.ready_event import ReadyEvent
79
- from .events.reaction_events import (
80
- ReactionAddEvent,
81
- ReactionRemoveEvent,
82
- ReactionRemoveEmojiEvent,
83
- ReactionRemoveAllEvent,
84
- )
85
- from .events.guild_events import (
86
- GuildCreateEvent,
87
- GuildUpdateEvent,
88
- GuildDeleteEvent,
89
- )
90
- from .events.message_events import (
91
- MessageCreateEvent,
92
- MessageUpdateEvent,
93
- MessageDeleteEvent,
94
- )
95
- from .events.channel_events import (
96
- GuildChannelCreateEvent,
97
- GuildChannelUpdateEvent,
98
- GuildChannelDeleteEvent,
99
- ChannelPinsUpdateEvent,
100
- )
101
- from .events.interaction_events import InteractionEvent
102
-
103
- # models
104
- from .models.application import ApplicationModel
105
- from .models.emoji import EmojiModel
106
- from .models.guild import GuildModel
107
- from .models.member import MemberModel
108
- from .models.user import UserModel
109
- from .models.role import RoleModel
110
-
111
- # parts
112
- from .parts.channel import GuildChannel
113
- from .parts.role import Role
114
- from .parts.message import MessageBuilder
115
- from .parts.modal import ModalBuilder
116
- from .parts.embed import EmbedBuilder
117
- from .parts.action_row import (
118
- ActionRow,
119
- StringSelect,
120
- UserSelect,
121
- RoleSelect,
122
- ChannelSelect,
123
- MentionableSelect
124
- )
125
-
126
- from .parts.command import (
127
- SlashCommand,
128
- MessageCommand,
129
- UserCommand
130
- )
131
-
132
- from .parts.components_v2 import (
133
- Container,
134
- Section,
135
- MediaGalleryItem,
136
- Label
137
- )
138
-
139
- # resources
140
- from .resources.guild import Guild
141
- from .resources.channel import Channel
142
- from .resources.message import Message
143
- from .resources.bot_emojis import BotEmojis
144
- from .resources.user import User
145
- from .resources.interaction import Interaction
146
- from .resources.application import Application
147
-
148
- # Lazy loader
149
- def __getattr__(name: str):
150
- if name not in __all__:
151
- raise AttributeError(f"module {__name__} has no attribute {name}")
152
-
153
- mapping = {
154
- # top-level
155
- "Logger": "discord.logger",
156
- "Client": "discord.client",
157
- "Intents": "discord.intents",
158
- "set_intents": "discord.intents",
159
- "BaseConfig": "discord.config",
160
-
161
- # events
162
- "ReadyEvent": "discord.events.ready_event",
163
- "ReactionAddEvent": "discord.events.reaction_events",
164
- "ReactionRemoveEvent": "discord.events.reaction_events",
165
- "ReactionRemoveEmojiEvent": "discord.events.reaction_events",
166
- "ReactionRemoveAllEvent": "discord.events.reaction_events",
167
- "GuildCreateEvent": "discord.events.guild_events",
168
- "GuildUpdateEvent": "discord.events.guild_events",
169
- "GuildDeleteEvent": "discord.events.guild_events",
170
- "MessageCreateEvent": "discord.events.message_events",
171
- "MessageUpdateEvent": "discord.events.message_events",
172
- "MessageDeleteEvent": "discord.events.message_events",
173
- "GuildChannelCreateEvent": "discord.events.channel_events",
174
- "GuildChannelUpdateEvent": "discord.events.channel_events",
175
- "GuildChannelDeleteEvent": "discord.events.channel_events",
176
- "ChannelPinsUpdateEvent": "discord.events.channel_events",
177
- "InteractionEvent": "discord.events.interaction_events",
178
-
179
- # models
180
- 'ApplicationModel': "discord.models.application",
181
- 'EmojiModel': "discord.models.emoji",
182
- 'GuildModel': "discord.models.guild",
183
- 'MemberModel': "discord.models.member",
184
- 'UserModel': "discord.models.user",
185
- 'RoleModel': "discord.models.role",
186
-
187
- # parts
188
- 'GuildChannel': "discord.parts.channel",
189
- 'Role': "discord.parts.role",
190
- 'MessageBuilder': "discord.parts.message",
191
- 'ModalBuilder': "discord.parts.modal",
192
- 'EmbedBuilder': "discord.parts.embed",
193
- 'ActionRow': "discord.parts.action_row",
194
- 'StringSelect': "discord.parts.action_row",
195
- 'UserSelect': "discord.parts.action_row",
196
- 'RoleSelect': "discord.parts.action_row",
197
- 'ChannelSelect': "discord.parts.action_row",
198
- 'MentionableSelect': "discord.parts.action_row",
199
- 'SlashCommand': "discord.parts.command",
200
- 'MessageCommand': "discord.parts.command",
201
- 'UserCommand': "discord.parts.command",
202
- 'Container': "discord.parts.components_v2",
203
- 'Section': "discord.parts.components_v2",
204
- 'MediaGalleryItem': "discord.parts.components_v2",
205
- 'Label': "discord.parts.components_v2",
206
-
207
- # resources
208
- 'Guild': "discord.resources.guild",
209
- 'Channel': "discord.resources.channel",
210
- 'Message': "discord.resources.message",
211
- 'BotEmojis': "discord.resources.bot_emojis",
212
- 'User': "discord.resources.user",
213
- 'Interaction': "discord.resources.interaction",
214
- 'Application': "discord.resources.application"
215
- }
216
-
217
- module = importlib.import_module(mapping[name])
218
- attr = getattr(module, name)
219
- globals()[name] = attr # cache it for future lookups
220
- return attr
221
-
222
- def __dir__():
223
- return sorted(list(globals().keys()) + __all__)
discord/model.py DELETED
@@ -1,90 +0,0 @@
1
- from dataclasses import dataclass, fields, is_dataclass
2
- from typing import get_args, get_origin, Union
3
-
4
- from .http import HTTPClient
5
-
6
- @dataclass
7
- class DataModel:
8
- """DataModel is a base class for Discord JSONs that provides hydration from raw dicts,
9
- optional field defaults, and access to HTTP-bound methods.
10
- """
11
-
12
- @classmethod
13
- def from_dict(cls, data: dict, http: HTTPClient = None):
14
- """Hydrates the given data into the dataclass child.
15
-
16
- Args:
17
- data (dict): JSON data
18
- http (HTTPClient, optional): HTTP session for requests
19
-
20
- Returns:
21
- (dataclass): hydrated dataclass
22
- """
23
- kwargs = {}
24
-
25
- def unwrap_optional(typ):
26
- """Remove NoneType from Optional or leave Union as-is."""
27
- if get_origin(typ) is Union:
28
- args = tuple(a for a in get_args(typ) if a is not type(None))
29
- if len(args) == 1:
30
- return args[0] # single type left
31
- else:
32
- return Union[args] # multi-type union remains
33
- return typ
34
-
35
- for field in fields(cls):
36
- # property must be in given json!
37
- value = data.get(field.name)
38
-
39
- inner_type = unwrap_optional(field.type)
40
-
41
- # Handle None
42
- if value is None:
43
- kwargs[field.name] = None
44
- # Integers stored as strings
45
- elif isinstance(value, str) and value.isdigit():
46
- kwargs[field.name] = int(value)
47
- # Nested dataclass
48
- elif is_dataclass(inner_type):
49
- kwargs[field.name] = inner_type.from_dict(value, http)
50
- # List type
51
- elif get_origin(inner_type) is list:
52
- list_type = get_args(inner_type)[0]
53
- kwargs[field.name] = [
54
- list_type.from_dict(v, http) if is_dataclass(list_type) else v
55
- for v in value
56
- ]
57
- # Everything else (primitive, Union of primitives)
58
- else:
59
- kwargs[field.name] = value
60
-
61
- instance = cls(**kwargs)
62
-
63
- # attach HTTP if given
64
- if http:
65
- instance._http = http
66
-
67
- return instance
68
-
69
- def _to_dict(self):
70
- """Recursively turns the dataclass into a dictionary and drops empty fields.
71
-
72
- Returns:
73
- (dict): serialized dataclasss
74
- """
75
- def serialize(value):
76
- if isinstance(value, list):
77
- return [serialize(v) for v in value]
78
- if isinstance(value, DataModel):
79
- return value._to_dict()
80
- return value
81
-
82
- result = {}
83
- for f in fields(self):
84
- if f.name.startswith('_'): # ignore private fields
85
- continue
86
- value = getattr(self, f.name)
87
- if value not in (None, [], {}, "", 0):
88
- result[f.name] = serialize(value)
89
-
90
- return result
@@ -1,208 +0,0 @@
1
- from dataclasses import dataclass, field
2
- from typing import Literal, Optional
3
- from ..model import DataModel
4
-
5
- from .component_types import *
6
-
7
- from ..models.emoji import EmojiModel
8
-
9
- class _ButtonStyles:
10
- """Represents button styles for a Button component."""
11
- PRIMARY = 1
12
- SECONDARY = 2
13
- SUCCESS = 3
14
- DANGER = 4
15
- LINK = 5
16
-
17
- @dataclass
18
- class _Button(DataModel, ActionRowChild, SectionAccessory):
19
- """Represents the Button component."""
20
- style: int
21
- custom_id: str
22
- label: Optional[str] = None
23
- emoji: EmojiModel = None
24
- url: Optional[str] = None
25
- disabled: Optional[bool] = False
26
- type: Literal[2] = field(init=False, default=2)
27
-
28
- @dataclass
29
- class _SelectOption(DataModel):
30
- """Represents the Select Option component"""
31
- label: str
32
- value: str
33
- description: Optional[str] = None # appears below the label
34
- emoji: Optional[EmojiModel] = None
35
- default: Optional[bool] = False
36
-
37
- @dataclass
38
- class StringSelect(DataModel, ActionRowChild, LabelChild):
39
- """Represents the String Select component."""
40
- custom_id: str
41
- options: list[_SelectOption] = field(default_factory=list)
42
- placeholder: Optional[str] = None
43
- min_values: Optional[int] = 0
44
- max_values: Optional[int] = 1
45
- required: Optional[bool] = False
46
- disabled: Optional[bool] = False # does not work on Modals!
47
- type: Literal[3] = field(init=False, default=3)
48
-
49
- def add_option(self,
50
- *,
51
- label: str,
52
- value: str,
53
- description: str = None,
54
- emoji: str | EmojiModel = None,
55
- default: bool = False
56
- ):
57
- """Add an option to this string select component.
58
-
59
- Args:
60
- label (str): option text
61
- value (str): analogous to button's custom ID
62
- description (str, optional): option subtext
63
- emoji (str | EmojiModel, optional): string if unicode emoji, EmojiModel if custom
64
- default (bool, optional): if this option should be the default option. Defaults to False.
65
-
66
- Returns:
67
- (StringSelect): self
68
- """
69
- if isinstance(emoji, str):
70
- emoji = EmojiModel(name=emoji)
71
-
72
- self.options.append(
73
- _SelectOption(
74
- label=label,
75
- value=value,
76
- description=description,
77
- emoji=emoji,
78
- default=default
79
- )
80
- )
81
- return self
82
-
83
- @dataclass
84
- class _DefaultValue(DataModel):
85
- """Represents the Default Value for Select components."""
86
- id: int # ID of role, user, or channel
87
- type: Literal["role", "user", "channel"]
88
-
89
- @dataclass
90
- class UserSelect(DataModel, ActionRowChild, LabelChild):
91
- """Represents the User Select component."""
92
- custom_id: str
93
- placeholder: Optional[str] = None
94
- default_values: list[_DefaultValue] = field(default_factory=list)
95
- min_values: Optional[int] = 0
96
- max_values: Optional[int] = 1
97
- disabled: Optional[bool] = False
98
- type: Literal[5] = field(init=False, default=5)
99
-
100
- def add_default_value(self, user_id: int):
101
- self.default_values.append(_DefaultValue(user_id, 'user'))
102
- return self
103
-
104
- @dataclass
105
- class RoleSelect(DataModel, ActionRowChild, LabelChild):
106
- """Represents the Role Select component."""
107
- custom_id: str
108
- placeholder: Optional[str] = None
109
- default_values: list[_DefaultValue] = field(default_factory=list)
110
- min_values: Optional[int] = 0
111
- max_values: Optional[int] = 1
112
- disabled: Optional[bool] = False
113
- type: Literal[6] = field(init=False, default=6)
114
-
115
- def add_default_value(self, role_id: int):
116
- self.default_values.append(_DefaultValue(role_id, 'role'))
117
- return self
118
-
119
- @dataclass
120
- class MentionableSelect(DataModel, ActionRowChild, LabelChild):
121
- """Represents the Mentionable Select component."""
122
- custom_id: str
123
- placeholder: Optional[str] = None
124
- default_values: list[_DefaultValue] = field(default_factory=list)
125
- min_values: Optional[int] = 0
126
- max_values: Optional[int] = 1
127
- disabled: Optional[bool] = False
128
- type: Literal[7] = field(init=False, default=7)
129
-
130
- def add_default_value(self, role_or_user_id: int, role_or_user: Literal['user', 'role']):
131
- self.default_values.append(_DefaultValue(role_or_user_id, role_or_user))
132
- return self
133
-
134
- @dataclass
135
- class ChannelSelect(DataModel, ActionRowChild, LabelChild):
136
- """Represents the Channel Select component."""
137
- custom_id: str
138
- placeholder: Optional[str] = None
139
- default_values: list[_DefaultValue] = field(default_factory=list)
140
- min_values: Optional[int] = 0
141
- max_values: Optional[int] = 1
142
- disabled: Optional[bool] = False
143
- type: Literal[8] = field(init=False, default=8)
144
-
145
- def add_default_value(self, channel_id: int):
146
- self.default_values.append(_DefaultValue(channel_id, 'channel'))
147
- return self
148
-
149
- @dataclass
150
- class ActionRow(DataModel, ContainerChild):
151
- """Represents a container of interactable components."""
152
- type: Literal[1] = field(init=False, default=1)
153
- components: list[ActionRowChild] = field(default_factory=list)
154
-
155
- def add_button(self,
156
- *,
157
- style: Literal['Primary', 'Secondary', 'Success', 'Danger', 'Link'],
158
- label: str,
159
- custom_id: str,
160
- emoji: str | EmojiModel = None,
161
- disable: bool = False
162
- ):
163
- """Add a button to this action row. (5 per row)
164
-
165
- Args:
166
- style (Literal['Primary', 'Secondary', 'Success', 'Danger', 'Link']):
167
- button style as a string
168
- label (str): button text
169
- custom_id (str): developer-defined button ID
170
- emoji (str | EmojiModel, Optional): str if unicode emoji, EmojiModal if custom
171
- disable (bool, Optional): if this button should be pressable. Defaults to False.
172
-
173
- Returns:
174
- (ActionRow): self
175
- """
176
- _styles = {
177
- 'PRIMARY': _ButtonStyles.PRIMARY,
178
- 'SECONDARY': _ButtonStyles.SECONDARY,
179
- 'SUCCESS': _ButtonStyles.SUCCESS,
180
- 'DANGER': _ButtonStyles.DANGER,
181
- 'LINK': _ButtonStyles.LINK
182
- }
183
-
184
- if isinstance(emoji, str):
185
- emoji = EmojiModel(name=emoji)
186
-
187
- self.components.append(
188
- _Button(
189
- style=_styles.get(style.upper()),
190
- label=label,
191
- custom_id=custom_id,
192
- emoji=emoji,
193
- disabled=disable
194
- )
195
- )
196
- return self
197
-
198
- def set_select_menu(self, select: StringSelect | UserSelect | RoleSelect | ChannelSelect | MentionableSelect):
199
- """Add a select menu component to this action row. (1 per row)
200
-
201
- Args:
202
- select (StringSelect | UserSelect | RoleSelect | ChannelSelect | MentionableSelect): the select menu component
203
-
204
- Returns:
205
- (ActionRow): self
206
- """
207
- self.components.append(select)
208
- return self
discord/parts/channel.py DELETED
@@ -1,20 +0,0 @@
1
- from dataclasses import dataclass
2
- from typing import Optional
3
- from ..model import DataModel
4
-
5
- # NOTE: Supported Channel Types listed here
6
- class ChannelTypes:
7
- """Constants for channel types."""
8
- GUILD_TEXT = 0
9
- GUILD_CATEGORY = 4
10
- GUILD_ANNOUNCEMENT = 5
11
-
12
- @dataclass
13
- class GuildChannel(DataModel):
14
- """Parameters for creating/editing a guild channel."""
15
- name: Optional[str] = None
16
- type: Optional[int] = None
17
- topic: Optional[str] = None
18
- position: Optional[int] = None
19
- parent_id: Optional[int] = None
20
- nsfw: Optional[bool] = None