|
1 | 1 | import Command from '../Command.js'; |
2 | 2 | import GuildSettings from '../../settings/GuildSettings.js'; |
3 | 3 | import { |
4 | | - ActionRowBuilder, |
5 | 4 | ButtonBuilder, |
6 | 5 | ButtonStyle, |
7 | 6 | MessageFlags, |
@@ -165,54 +164,41 @@ export default class ArticleCommand extends Command { |
165 | 164 | const message = new MessageBuilder(); |
166 | 165 |
|
167 | 166 | if (mention) { |
168 | | - message.content = `${userMention(mention)} this article from our help center might help you:`; |
| 167 | + message.text(`${userMention(mention)} this article from our help center might help you:`) |
| 168 | + .separator(false); |
169 | 169 | } |
170 | 170 |
|
171 | | - const container = this.appendContent(message, results[index], article.body) |
172 | | - .endComponent() |
173 | | - .addSeparatorComponents() |
174 | | - .addActionRowComponents( |
175 | | - new ActionRowBuilder().addComponents( |
176 | | - new StringSelectMenuBuilder() |
177 | | - .setOptions(results) |
178 | | - .setCustomId(`article:${userId}` + (mention ? `:${mention}` : '')) |
179 | | - ), |
180 | | - new ActionRowBuilder().addComponents( |
181 | | - new ButtonBuilder() |
182 | | - .setStyle(ButtonStyle.Link) |
183 | | - .setURL(article.html_url) |
184 | | - .setLabel('View Article') |
185 | | - ), |
| 171 | + let string = this.#markdownConverter.generate(article.body); |
| 172 | + let shorten = string.length > ARTICLE_EMBED_PREVIEW_LENGTH; |
| 173 | + if (shorten) { |
| 174 | + string = string.substring(0, ARTICLE_EMBED_PREVIEW_LENGTH) |
| 175 | + .replace(/\n+[^\n]*$/, ''); |
| 176 | + } |
| 177 | + |
| 178 | + message |
| 179 | + .heading(article.title) |
| 180 | + .text(string) |
| 181 | + .separator() |
| 182 | + .select(new StringSelectMenuBuilder() |
| 183 | + .setOptions(results) |
| 184 | + .setCustomId(`article:${userId}` + (mention ? `:${mention}` : '')) |
186 | 185 | ) |
187 | | - .toJSON(); |
| 186 | + .separator(); |
188 | 187 |
|
189 | | - return { |
190 | | - components: [container], |
191 | | - flags: MessageFlags.IsComponentsV2, |
192 | | - }; |
193 | | - } |
194 | 188 |
|
195 | | - /** |
196 | | - * get a description from the HTML body of an article |
197 | | - * @param {MessageBuilder} message |
198 | | - * @param {import('discord.js').APISelectMenuOption} result |
199 | | - * @param {string} body website body |
200 | | - * @returns {MessageBuilder} |
201 | | - */ |
202 | | - appendContent(message, result, body) { |
203 | | - message.heading(result.label); |
204 | | - |
205 | | - let string = this.#markdownConverter.generate(body); |
206 | | - if (string.length > ARTICLE_EMBED_PREVIEW_LENGTH) { |
207 | | - string = string.substring(0, ARTICLE_EMBED_PREVIEW_LENGTH); |
208 | | - message.text(string.replace(/\.?\n+.*$/, '')) |
209 | | - .newLine() |
210 | | - .newLine() |
211 | | - .subtext('To read more, click \'View Article\' below.'); |
212 | | - } else { |
213 | | - message.text(string); |
| 189 | + if (shorten) { |
| 190 | + message.subtext('This is only a short preview of the article, Click \'View Article\' to read more.'); |
214 | 191 | } |
215 | 192 |
|
216 | | - return message; |
| 193 | + message.button(new ButtonBuilder() |
| 194 | + .setStyle(ButtonStyle.Link) |
| 195 | + .setURL(article.html_url) |
| 196 | + .setLabel('View Article') |
| 197 | + ); |
| 198 | + |
| 199 | + return { |
| 200 | + components: [message.endComponent()], |
| 201 | + flags: MessageFlags.IsComponentsV2, |
| 202 | + }; |
217 | 203 | } |
218 | 204 | } |
0 commit comments