From bc8e3ce6bdb565653852f5dedd524864384f53da Mon Sep 17 00:00:00 2001 From: lunispang <95270420+lunispang@users.noreply.github.com> Date: Tue, 15 Oct 2024 01:08:46 +0200 Subject: [PATCH] auto reset on game end tic tac toe (#49) * rebase * rebase stuff * rebase stuff again * fix chat formatting * auto reset on win or tie --- twitch/bot/src/commands/tictactoe.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/twitch/bot/src/commands/tictactoe.rs b/twitch/bot/src/commands/tictactoe.rs index 2cad35a..2b4b164 100644 --- a/twitch/bot/src/commands/tictactoe.rs +++ b/twitch/bot/src/commands/tictactoe.rs @@ -199,6 +199,14 @@ impl ChatCommand for TicTacToe { ctx: &twitcheventsub::MessageData, ) -> anyhow::Result<()> { let arg = ctx.message.text.split_whitespace().nth(1); + if let Some(board) = self.players.get(&ctx.chatter.id) { + match board.get_state() { + State::Turn(_) => {} + _ => { + self.players.remove(&ctx.chatter.id); + } + } + } match arg { None => { let _ = api.send_chat_message(self.help()); @@ -224,9 +232,8 @@ impl ChatCommand for TicTacToe { for row in board.print() { let _ = api.send_chat_message(row); } - } - else { - api.send_chat_message("Invalid move!"); + } else { + let _ = api.send_chat_message("Invalid move!"); } } _ => {