|
1 | 1 | import { |
2 | | - type APIEmbed, |
| 2 | + ActionRowBuilder, |
| 3 | + ButtonBuilder, |
3 | 4 | ButtonStyle, |
4 | 5 | type CommandInteraction, |
5 | 6 | ComponentType, |
| 7 | + ContainerBuilder, |
| 8 | + MessageFlags, |
6 | 9 | SlashCommandBuilder, |
| 10 | + TextDisplayBuilder, |
7 | 11 | type User, |
8 | 12 | } from "discord.js"; |
9 | 13 |
|
@@ -52,59 +56,52 @@ export default class InventarCommand implements ApplicationCommand { |
52 | 56 | const firstItemIndex = pageIndex * pageSize; |
53 | 57 | const pageContents = contents.slice(firstItemIndex, firstItemIndex + pageSize); |
54 | 58 |
|
55 | | - const embed = { |
56 | | - title: `Inventar von ${user.displayName}`, |
57 | | - fields: pageContents.map(item => { |
58 | | - const rarityAttribute = lootDataService.extractRarityAttribute(item.attributes); |
59 | | - const rarity = |
60 | | - rarityAttribute && |
61 | | - rarityAttribute.attributeKindId !== LootAttributeKind.RARITY_NORMAL |
62 | | - ? ` (${rarityAttribute.displayName})` |
63 | | - : ""; |
64 | | - |
65 | | - const shortAttributeList = item.attributes.map(a => a.shortDisplay).join(""); |
66 | | - |
67 | | - return { |
68 | | - name: `${lootDataService.getEmote(context.guild, item)} ${item.displayName}${rarity} ${shortAttributeList}`.trim(), |
69 | | - value: "", |
70 | | - inline: false, |
71 | | - }; |
72 | | - }), |
73 | | - footer: { |
74 | | - text: `Seite ${pageIndex + 1} von ${lastPageIndex + 1}`, |
75 | | - }, |
76 | | - } satisfies APIEmbed; |
| 59 | + const list = pageContents.map(item => { |
| 60 | + const rarityAttribute = lootDataService.extractRarityAttribute(item.attributes); |
| 61 | + const rarity = |
| 62 | + rarityAttribute && |
| 63 | + rarityAttribute.attributeKindId !== LootAttributeKind.RARITY_NORMAL |
| 64 | + ? ` (${rarityAttribute.displayName})` |
| 65 | + : ""; |
| 66 | + |
| 67 | + const shortAttributeList = item.attributes.map(a => a.shortDisplay).join(""); |
| 68 | + |
| 69 | + return `${lootDataService.getEmote(context.guild, item)} ${item.displayName}${rarity} ${shortAttributeList}`.trim(); |
| 70 | + }); |
| 71 | + |
| 72 | + const listItems = list.length > 0 ? list.map(l => `- ${l}`) : ["_leer_"]; |
77 | 73 |
|
78 | 74 | return { |
79 | 75 | components: [ |
80 | | - { |
81 | | - type: ComponentType.ActionRow, |
82 | | - components: [ |
83 | | - { |
84 | | - type: ComponentType.Button, |
85 | | - label: "<<", |
86 | | - customId: "page-prev", |
87 | | - disabled: pageIndex <= 0, |
88 | | - style: ButtonStyle.Secondary, |
89 | | - }, |
90 | | - { |
91 | | - type: ComponentType.Button, |
92 | | - label: ">>", |
93 | | - customId: "page-next", |
94 | | - disabled: pageIndex >= lastPageIndex, |
95 | | - style: ButtonStyle.Secondary, |
96 | | - }, |
97 | | - ], |
98 | | - }, |
| 76 | + new ContainerBuilder() |
| 77 | + .addTextDisplayComponents(t => t.setContent(`## Inventar von ${user}`)) |
| 78 | + .addTextDisplayComponents( |
| 79 | + ...listItems.map(li => new TextDisplayBuilder().setContent(li)), |
| 80 | + ) |
| 81 | + .addTextDisplayComponents(t => |
| 82 | + t.setContent(`-# Seite ${pageIndex + 1} von ${lastPageIndex + 1}`), |
| 83 | + ), |
| 84 | + new ActionRowBuilder<ButtonBuilder>().addComponents( |
| 85 | + new ButtonBuilder() |
| 86 | + .setCustomId("page-prev") |
| 87 | + .setLabel("<<") |
| 88 | + .setStyle(ButtonStyle.Secondary) |
| 89 | + .setDisabled(pageIndex <= 0), |
| 90 | + new ButtonBuilder() |
| 91 | + .setCustomId("page-next") |
| 92 | + .setLabel(">>") |
| 93 | + .setStyle(ButtonStyle.Secondary) |
| 94 | + .setDisabled(pageIndex >= lastPageIndex), |
| 95 | + ), |
99 | 96 | ], |
100 | | - embeds: [embed], |
101 | 97 | } as const; |
102 | 98 | } |
103 | 99 |
|
104 | 100 | let pageIndex = 0; |
105 | 101 |
|
106 | 102 | const callbackResponse = await interaction.reply({ |
107 | 103 | ...buildMessageData(pageIndex), |
| 104 | + flags: MessageFlags.IsComponentsV2, |
108 | 105 | withResponse: true, |
109 | 106 | tts: false, |
110 | 107 | }); |
|
0 commit comments