@@ -28,8 +28,10 @@ export class Attachments {
28
28
29
29
const attachmentFields : string [ ] = [ ] ;
30
30
31
- const parsedAttachments = (
32
- attachments . map ( ( { type, photo, video, link, doc, audio, poll, album, textlive, market } ) => {
31
+ const parsedAttachments = attachments
32
+ . reduce < string [ ] > ( ( parsedAttachments , {
33
+ type, photo, video, link, doc, audio, poll, album, textlive, market
34
+ } ) => {
33
35
switch ( type ) {
34
36
case PHOTO : {
35
37
const { sizes } = photo ;
@@ -63,19 +65,23 @@ export class Attachments {
63
65
title += ` - ${ name } ` ;
64
66
}
65
67
66
- return `[${ prefix } : ${ title } ](${ LINK_PREFIX } ${ this . generateAttachmentContext ( video ) } ?z=${ VIDEO } ${ owner_id } _${ id } )` ;
68
+ parsedAttachments . push (
69
+ `[${ prefix } : ${ title } ](${ LINK_PREFIX } ${ this . generateAttachmentContext ( video ) } ?z=${ VIDEO } ${ owner_id } _${ id } )`
70
+ ) ;
71
+ break ;
67
72
}
68
73
case LINK : {
69
74
const { button_text = 'Ссылка' , description, title, url } = link ;
70
75
71
- return `[🔗 ${ description || button_text } : ${ title } ](${ url } )` ;
76
+ parsedAttachments . push ( `[🔗 ${ description || button_text } : ${ title } ](${ url } )` ) ;
77
+ break ;
72
78
}
73
79
case DOCUMENT : {
74
80
const { ext, url, title } = doc ;
75
81
76
82
if ( ext === 'gif' ) {
77
83
const filename = `${ generateRandomString ( 6 ) } .${ ext } ` ;
78
-
84
+
79
85
if ( ! embed . image ) {
80
86
files . push (
81
87
new MessageAttachment ( url , filename )
@@ -92,44 +98,62 @@ export class Attachments {
92
98
) ;
93
99
}
94
100
} else {
95
- return `[📄 Файл: ${ title } ](${ url } )` ;
101
+ parsedAttachments . push ( `[📄 Файл: ${ title } ](${ url } )` ) ;
96
102
}
97
103
break ;
98
104
}
99
105
case AUDIO : {
100
106
const { owner_id, id, artist, title } = audio ;
101
107
102
- return `[🎵 Аудиозапись: ${ artist } - ${ title } ](${ LINK_PREFIX } ${ AUDIO } ${ owner_id } _${ id } )` ;
108
+ parsedAttachments . push (
109
+ `[🎵 Аудиозапись: ${ artist } - ${ title } ](${ LINK_PREFIX } ${ AUDIO } ${ owner_id } _${ id } )`
110
+ ) ;
111
+ break ;
103
112
}
104
113
case POLL : {
105
114
const { owner_id, id, question } = poll ;
106
115
107
- return `[📊 Опрос: ${ question } ](${ LINK_PREFIX } ${ this . generateAttachmentContext ( poll ) } ?w=${ POLL } ${ owner_id } _${ id } )` ;
116
+ parsedAttachments . push (
117
+ `[📊 Опрос: ${ question } ](${ LINK_PREFIX } ${ this . generateAttachmentContext ( poll ) } ?w=${ POLL } ${ owner_id } _${ id } )`
118
+ ) ;
119
+ break ;
108
120
}
109
121
case ALBUM : {
110
122
const { owner_id, id, title } = album ;
111
123
112
- return `[🖼️ Альбом: ${ title } ](${ LINK_PREFIX } ${ ALBUM } ${ owner_id } _${ id } )` ;
124
+ parsedAttachments . push (
125
+ `[🖼️ Альбом: ${ title } ](${ LINK_PREFIX } ${ ALBUM } ${ owner_id } _${ id } )`
126
+ ) ;
127
+ break ;
113
128
}
114
129
case MARKET : {
115
130
const { owner_id, id, title } = market ;
116
131
117
- return `[🛍️ Товар: ${ title } ](${ LINK_PREFIX } ${ MARKET } ${ owner_id } ?w=product${ owner_id } _${ id } )` ;
132
+ parsedAttachments . push (
133
+ `[🛍️ Товар: ${ title } ](${ LINK_PREFIX } ${ MARKET } ${ owner_id } ?w=product${ owner_id } _${ id } )`
134
+ ) ;
135
+ break ;
118
136
}
119
137
case MARKET_ALBUM : {
120
138
const { owner_id, id, title } = market ;
121
139
122
- return `[🛍️ Подборка товаров: ${ title } ](${ LINK_PREFIX } ${ MARKET } ${ owner_id } ?section=${ ALBUM } _${ id } )` ;
140
+ parsedAttachments . push (
141
+ `[🛍️ Подборка товаров: ${ title } ](${ LINK_PREFIX } ${ MARKET } ${ owner_id } ?section=${ ALBUM } _${ id } )`
142
+ ) ;
143
+ break ;
123
144
}
124
145
case 'textlive' : {
125
146
const { textlive_id, title } = textlive ;
126
147
127
- return `[📣 Репортаж: ${ title } ](${ LINK_PREFIX } textlive${ textlive_id } )` ;
148
+ parsedAttachments . push (
149
+ `[📣 Репортаж: ${ title } ](${ LINK_PREFIX } textlive${ textlive_id } )`
150
+ ) ;
151
+ break ;
128
152
}
129
153
}
130
- } )
131
- . filter ( ( attachment ) => attachment ) as string [ ]
132
- )
154
+
155
+ return parsedAttachments ;
156
+ } , [ ] )
133
157
. sort ( ( a , b ) => a . localeCompare ( b ) )
134
158
. map ( ( attachment ) => `\n${ attachment } ` ) ;
135
159
0 commit comments