11import { ComponentInteraction , ComponentTypes , MessageFlags } from "oceanic.js" ;
22
33import { deleteMessage , sendMessage } from "../client.js" ;
4- import { CardColorSelect , PickCardSelect } from "../components.js" ;
4+ import { CardColorSelect , PickCardSelect , PlayerUserSelect } from "../components.js" ;
55import { cardEmotes , cards , colors , uniqueVariants , variants } from "../constants.js" ;
66import database from "../database.js" ;
77import { config } from "../index.js" ;
@@ -71,6 +71,8 @@ export function onColorPlayed(ctx: ComponentInteraction<ComponentTypes.STRING_SE
7171 game . cards [ ctx . member . id ] . splice ( game . cards [ ctx . member . id ] . indexOf ( variant ) , 1 ) ;
7272 game . currentPlayer = next ( game . players , game . players . indexOf ( game . currentPlayer ) ) ;
7373 ctx . deleteOriginal ( ) ;
74+ deleteMessage ( ctx . message . channel . messages . get ( ctx . message . messageReference ?. messageID ) ) ;
75+
7476 if ( game . cards [ ctx . member . id ] . length === 0 ) return ;
7577 sendMessage ( ctx . channel . id , `
7678 ${ `**${ getUsername ( ctx . member . id , true , ctx . guild ) } ** played ${ cardEmotes [ variant ] } ${ toTitleCase ( variant ) } , switching the color to ${ color } ` } \
@@ -97,6 +99,21 @@ export function onForceDrawPlayed(ctx: ComponentInteraction<ComponentTypes.STRIN
9799 else onCardPlayed ( ctx , game , true ) ;
98100}
99101
102+ export function onSevenPlayed ( ctx : ComponentInteraction < ComponentTypes . STRING_SELECT > , game : UnoGame < true > ) {
103+ if ( game . currentPlayer !== ctx . member . id ) return ;
104+ const id = ctx . data . values . raw [ 0 ] ;
105+
106+ [ game . cards [ ctx . member . id ] , game . cards [ id ] ] = [ game . cards [ id ] , game . cards [ ctx . member . id ] ] ;
107+ sendMessage ( ctx . channel . id , `**${ getUsername ( ctx . member . id , true , ctx . guild ) } ** played \
108+ ${ cardEmotes [ game . currentCard ] } ${ toTitleCase ( game . currentCard ) }
109+ **${ getUsername ( ctx . member . id , true , ctx . guild ) } ** switched cards with **${ getUsername ( id , true , ctx . guild ) } **` ) ;
110+
111+ game . currentPlayer = next ( game . players , game . players . indexOf ( game . currentPlayer ) ) ;
112+ ctx . deleteOriginal ( ) ;
113+ deleteMessage ( ctx . message . channel . messages . get ( ctx . message . messageReference ?. messageID ) ) ;
114+ sendGameMessage ( game ) ;
115+ }
116+
100117export function onCardPlayed ( ctx : ComponentInteraction < ComponentTypes . STRING_SELECT > , game : UnoGame < true > , ignoreDrawStack = false ) {
101118 if ( game . currentPlayer !== ctx . member . id ) return ;
102119 const cardPlayed = ctx . data . values . raw [ 0 ] as Card | "draw" | "skip" ;
@@ -122,9 +139,10 @@ export function onCardPlayed(ctx: ComponentInteraction<ComponentTypes.STRING_SEL
122139
123140 if ( uniqueVariants . includes ( color ) ) {
124141 return ctx . createFollowup ( {
125- content : "Choose a color" ,
126- components : CardColorSelect ( color as typeof uniqueVariants [ number ] )
127- } ) . then ( ( ) => ctx . deleteOriginal ( ) ) ;
142+ content : `<@${ ctx . member . id } > Choose a color` ,
143+ components : CardColorSelect ( color as typeof uniqueVariants [ number ] ) ,
144+ allowedMentions : { users : true }
145+ } ) ;
128146 }
129147
130148 if ( cardPlayed === "skip" && ( ! game . settings . allowSkipping || ( game . lastPlayer . id !== game . currentPlayer && ! wasLastTurnBlocked ( game ) ) ) )
@@ -200,9 +218,25 @@ You drew ${cardEmotes[newCards[0]]}`,
200218 extraInfo = `**${ getUsername ( game . currentPlayer , true , ctx . guild ) } ** was skipped` ;
201219 break ;
202220 }
203- case "7" :
221+ case "7" : {
222+ if ( ! game . settings . sevenAndZero ) break ;
223+
224+ return ctx . createFollowup ( {
225+ content : `<@${ ctx . member . id } > Choose a player` ,
226+ components : PlayerUserSelect ( game ) ,
227+ allowedMentions : { users : true }
228+ } ) ;
229+ }
204230 case "0" : {
205- // TODO
231+ if ( ! game . settings . sevenAndZero ) break ;
232+ extraInfo = "All players' cards have been switched!" ;
233+
234+ const keys = Object . keys ( game . cards ) ;
235+ keys . unshift ( keys . pop ( ) ) ;
236+ game . cards = Object . fromEntries ( Object . entries ( game . cards ) . map ( ( [ _ , value ] , i ) =>
237+ [ keys [ i ] , value ]
238+ ) ) ;
239+ break ;
206240 }
207241 }
208242
@@ -224,6 +258,7 @@ You drew ${cardEmotes[newCards[0]]}`,
224258 : `**${ getUsername ( ctx . member . id , true , ctx . guild ) } ** played ${ cardEmotes [ cardPlayed ] } ${ toTitleCase ( cardPlayed ) } ` } \
225259 ${ extraInfo . length ? `\n${ extraInfo } ` : "" } `
226260 ) ;
261+
227262 if ( cardPlayed !== "draw" || ! game . settings . allowSkipping ) {
228263 sendGameMessage ( game ) ;
229264 } else {
0 commit comments