Skip to content

Commit 06d7348

Browse files
feat: can collect and save win_count per user
1 parent fdaaaa9 commit 06d7348

2 files changed

Lines changed: 38 additions & 12 deletions

File tree

apps/bot/src/interaction/command/report/component.ts

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ async function inputWinCountPage(
115115
const component = new ContainerBuilder().addTextDisplayComponents((title) =>
116116
title.setContent("# Report a Set"),
117117
);
118-
// console.log(match_players)
119118
for (const [user_id, match_player] of match_players) {
120119
console.log(user_id);
121120
component.addTextDisplayComponents((title) =>
@@ -129,15 +128,36 @@ async function inputWinCountPage(
129128
)
130129
.setCustomId(user_id)
131130
.setOptions(
132-
[1, 2, 3, 4, 5, 6, 7].map((x) =>
133-
new StringSelectMenuOptionBuilder()
131+
[1, 2, 3, 4, 5, 6, 7].map((x) => {
132+
const wins = new StringSelectMenuOptionBuilder()
134133
.setLabel(x.toString())
135-
.setValue(x.toString()),
136-
),
134+
.setValue(x.toString());
135+
if (match_players.get(user_id)?.win_count === x) {
136+
wins.setDefault(true);
137+
}
138+
return wins;
139+
}),
137140
),
138141
),
139142
);
140143
}
144+
component
145+
.addActionRowComponents((actionRow) =>
146+
actionRow.setComponents(
147+
new ButtonBuilder()
148+
.setCustomId("previous")
149+
.setLabel("Previous")
150+
.setStyle(ButtonStyle.Primary),
151+
),
152+
)
153+
.addActionRowComponents((actionRow) =>
154+
actionRow.setComponents(
155+
new ButtonBuilder()
156+
.setCustomId("next")
157+
.setLabel("Next")
158+
.setStyle(ButtonStyle.Primary),
159+
),
160+
);
141161
async function collect(interactable_message: Message<true>): Promise<void> {
142162
const winCountCollector = interactable_message.createMessageComponentCollector({
143163
componentType: ComponentType.StringSelect,
@@ -148,17 +168,22 @@ async function inputWinCountPage(
148168
time: 60_000,
149169
});
150170

151-
winCountCollector?.on("collect", (i) => {
152-
console.log(i);
153-
i.deferUpdate();
171+
winCountCollector?.on("collect", async (i) => {
172+
const player = match_players.get(i.customId);
173+
if (player) {
174+
player.win_count = Number(i.values[0]);
175+
}
176+
await i.deferUpdate();
154177
});
155-
pagingCollector?.on("collect", (i) => {
156-
log.trace(`winCount interface received: ${JSON.stringify(i)}`);
157-
178+
pagingCollector?.on("collect", async (i) => {
158179
winCountCollector.stop();
159180
pagingCollector.stop();
160181

161-
inputWinCountPage(i, match_players);
182+
if (i.customId === "next") {
183+
inputWinCountPage(i, match_players);
184+
} else if (i.customId === "previous") {
185+
selectUsersPage(i, match_players);
186+
}
162187
});
163188
}
164189
const match_report_interactable = (await interaction.reply({

apps/bot/src/interaction/command/report/handler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const reportMatch: CommandHandler = {
1616

1717
async execute(interaction): Promise<void> {
1818
if (!interaction.inGuild) return;
19+
log.debug("/report was invoked")
1920

2021
await initializeReportMatchInterface(interaction);
2122
},

0 commit comments

Comments
 (0)