1- import { ssbu_character_names } from "@grindcord/characters" ;
1+ import { ssbu_characters } from "@grindcord/characters" ;
22import type { SSBUCharEnum } from "@grindcord/types" ;
33import { getLogger } from "@logtape/logtape" ;
44import {
@@ -25,7 +25,7 @@ const log = getLogger(["bot", "component"]);
2525type ReportMatchPlayer = {
2626 name : string ;
2727 win_count ?: number ;
28- character ? : SSBUCharEnum [ ] ;
28+ character : SSBUCharEnum [ ] ;
2929} ;
3030
3131export async function initializeReportMatchInterface ( interaction : CommandInteraction ) {
@@ -74,6 +74,7 @@ async function selectUsersPage(
7474 for ( const [ user_id , user ] of i . users ) {
7575 selected_users . set ( user_id , {
7676 name : i . members . get ( user_id ) ?. nickname ?? user . displayName ,
77+ character : [ ] ,
7778 } ) ;
7879 }
7980 await i . deferUpdate ( ) ;
@@ -130,7 +131,7 @@ async function selectWinCountPage(
130131 . setPlaceholder ( `How many sets did ${ match_player . name } win?` )
131132 . setCustomId ( user_id )
132133 . setOptions (
133- [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] . map ( ( x ) => {
134+ [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] . map ( ( x ) => {
134135 const wins_choice = new StringSelectMenuOptionBuilder ( )
135136 . setLabel ( x . toString ( ) )
136137 . setValue ( x . toString ( ) ) ;
@@ -202,6 +203,8 @@ async function selectCharactersPage(
202203 interaction : MessageComponentInteraction ,
203204 match_players : Collection < string , ReportMatchPlayer > ,
204205) {
206+ const characterPagination = new Collection < string , number > ( ) ;
207+
205208 const component = new ContainerBuilder ( ) . addTextDisplayComponents ( ( title ) =>
206209 title . setContent ( "# Report a Set" ) ,
207210 ) ;
@@ -216,31 +219,23 @@ async function selectCharactersPage(
216219 . setPlaceholder ( `Which characters did ${ match_player . name } use?` )
217220 . setCustomId ( user_id )
218221 . setOptions (
219- ssbu_character_names . map ( ( x ) => {
222+ ssbu_characters . map ( ( x : SSBUCharEnum ) => {
220223 const character_choice = new StringSelectMenuOptionBuilder ( )
221224 . setLabel ( x )
222225 . setValue ( x ) ;
223- if ( match_player . character && x in match_player . character ) {
226+ if ( x in match_player . character ) {
224227 character_choice . setDefault ( true ) ;
225228 }
226229 return character_choice ;
227230 } ) ,
228231 ) ,
232+ new ButtonBuilder ( )
233+ . setCustomId ( `more${ user_id } ` )
234+ . setLabel ( "More characters" )
235+ . setStyle ( ButtonStyle . Secondary ) ,
229236 ) ,
230237 ) ;
231238 }
232- component . addActionRowComponents ( ( actionRow ) =>
233- actionRow . setComponents (
234- new ButtonBuilder ( )
235- . setCustomId ( "previous" )
236- . setLabel ( "Previous" )
237- . setStyle ( ButtonStyle . Primary ) ,
238- new ButtonBuilder ( )
239- . setCustomId ( "next" )
240- . setLabel ( "Next" )
241- . setStyle ( ButtonStyle . Primary ) ,
242- ) ,
243- ) ;
244239 async function collect ( interactable_message : Message < true > ) : Promise < void > {
245240 const selectCharactersCollector =
246241 interactable_message . createMessageComponentCollector ( {
@@ -255,17 +250,24 @@ async function selectCharactersPage(
255250 selectCharactersCollector ?. on ( "collect" , async ( i ) => {
256251 const player = match_players . get ( i . customId ) ;
257252 if ( player ) {
258- player . character = z
259- . array ( z . enum ( ssbu_character_names ) )
260- . parse ( i . values ) ;
253+ player . character = z . array ( z . enum ( ssbu_characters ) ) . parse ( i . values ) ;
261254 }
262255 await i . deferUpdate ( ) ;
263256 } ) ;
264257 pagingCollector ?. on ( "collect" , async ( i ) => {
265258 selectCharactersCollector . stop ( ) ;
266259 pagingCollector . stop ( ) ;
267260
268- if ( i . customId === "next" ) {
261+ if ( i . customId . slice ( 0 , 4 ) === "more" ) {
262+ const user_id = i . customId . slice ( 4 ) ;
263+ const pagination_index = characterPagination . get ( user_id ) ;
264+ const match_player = match_players . get ( user_id ) ;
265+ if ( pagination_index && match_player ) {
266+ const new_pagination_index =
267+ 25 - ( match_player . character ?. length % ssbu_characters . length ) ;
268+ characterPagination . set ( user_id , new_pagination_index ) ;
269+ }
270+ } else if ( i . customId === "next" ) {
269271 selectWinCountPage ( i , match_players ) ;
270272 } else if ( i . customId === "previous" ) {
271273 selectUsersPage ( i , match_players ) ;
0 commit comments