@@ -228,7 +228,7 @@ async def send(
228228 """
229229 if not self ._client :
230230 raise AttributeError ("HTTPClient not found!" )
231- from ...models .component import ActionRow , Button , SelectMenu
231+ from ...models .component import _build_components
232232 from .message import Message
233233
234234 _content : str = "" if content is MISSING else content
@@ -243,106 +243,10 @@ async def send(
243243 else :
244244 _embeds = [embeds ._json ]
245245
246- # TODO: Break this obfuscation pattern down to a "builder" method.
247246 if not components or components is MISSING :
248247 _components = []
249248 else :
250- _components : List [dict ] = [{"type" : 1 , "components" : []}]
251- if isinstance (components , list ) and all (
252- isinstance (action_row , ActionRow ) for action_row in components
253- ):
254- _components = [
255- {
256- "type" : 1 ,
257- "components" : [
258- (
259- component ._json
260- if component ._json .get ("custom_id" ) or component ._json .get ("url" )
261- else []
262- )
263- for component in action_row .components
264- ],
265- }
266- for action_row in components
267- ]
268- elif isinstance (components , list ) and all (
269- isinstance (component , (Button , SelectMenu )) for component in components
270- ):
271- for component in components :
272- if isinstance (component , SelectMenu ):
273- component ._json ["options" ] = [
274- options ._json if not isinstance (options , dict ) else options
275- for options in component ._json ["options" ]
276- ]
277- _components = [
278- {
279- "type" : 1 ,
280- "components" : [
281- (
282- component ._json
283- if component ._json .get ("custom_id" ) or component ._json .get ("url" )
284- else []
285- )
286- for component in components
287- ],
288- }
289- ]
290- elif isinstance (components , list ) and all (
291- isinstance (action_row , (list , ActionRow )) for action_row in components
292- ):
293- _components = []
294- for action_row in components :
295- for component in (
296- action_row if isinstance (action_row , list ) else action_row .components
297- ):
298- if isinstance (component , SelectMenu ):
299- component ._json ["options" ] = [
300- option ._json if not isinstance (option , dict ) else option
301- for option in component .options
302- ]
303- _components .append (
304- {
305- "type" : 1 ,
306- "components" : [
307- (
308- component ._json
309- if component ._json .get ("custom_id" )
310- or component ._json .get ("url" )
311- else []
312- )
313- for component in (
314- action_row
315- if isinstance (action_row , list )
316- else action_row .components
317- )
318- ],
319- }
320- )
321- elif isinstance (components , ActionRow ):
322- _components [0 ]["components" ] = [
323- (
324- component ._json
325- if component ._json .get ("custom_id" ) or component ._json .get ("url" )
326- else []
327- )
328- for component in components .components
329- ]
330- elif isinstance (components , Button ):
331- _components [0 ]["components" ] = (
332- [components ._json ]
333- if components ._json .get ("custom_id" ) or components ._json .get ("url" )
334- else []
335- )
336- elif isinstance (components , SelectMenu ):
337- components ._json ["options" ] = [
338- options ._json if not isinstance (options , dict ) else options
339- for options in components ._json ["options" ]
340- ]
341- _components [0 ]["components" ] = (
342- [components ._json ]
343- if components ._json .get ("custom_id" ) or components ._json .get ("url" )
344- else []
345- )
249+ _components = _build_components (components = components )
346250
347251 # TODO: post-v4: Add attachments into Message obj.
348252 payload = Message (
0 commit comments