Skip to content

Commit

Permalink
auto reset on game end tic tac toe (#49)
Browse files Browse the repository at this point in the history
* rebase

* rebase stuff

* rebase stuff again

* fix chat formatting

* auto reset on win or tie
  • Loading branch information
lunispang authored Oct 14, 2024
1 parent 7fab1ad commit bc8e3ce
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions twitch/bot/src/commands/tictactoe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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!");
}
}
_ => {
Expand Down

0 comments on commit bc8e3ce

Please sign in to comment.