diff options
Diffstat (limited to 'bot/exts/fun/tic_tac_toe.py')
-rw-r--r-- | bot/exts/fun/tic_tac_toe.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/bot/exts/fun/tic_tac_toe.py b/bot/exts/fun/tic_tac_toe.py index fa2a7531..d4ae7107 100644 --- a/bot/exts/fun/tic_tac_toe.py +++ b/bot/exts/fun/tic_tac_toe.py @@ -1,6 +1,6 @@ import asyncio import random -from typing import Callable, Optional, Union +from collections.abc import Callable import discord from discord.ext.commands import Cog, Context, check, group @@ -42,7 +42,7 @@ class Player: self.ctx = ctx self.symbol = symbol - async def get_move(self, board: dict[int, str], msg: discord.Message) -> tuple[bool, Optional[int]]: + async def get_move(self, board: dict[int, str], msg: discord.Message) -> tuple[bool, int | None]: """ Get move from user. @@ -106,7 +106,7 @@ class AI: class Game: """Class that contains information and functions about Tic Tac Toe game.""" - def __init__(self, players: list[Union[Player, AI]], ctx: Context): + def __init__(self, players: list[Player | AI], ctx: Context): self.players = players self.ctx = ctx self.channel = ctx.channel @@ -125,13 +125,13 @@ class Game: self.current = self.players[0] self.next = self.players[1] - self.winner: Optional[Union[Player, AI]] = None - self.loser: Optional[Union[Player, AI]] = None + self.winner: Player | AI | None = None + self.loser: Player | AI | None = None self.over = False self.canceled = False self.draw = False - async def get_confirmation(self) -> tuple[bool, Optional[str]]: + async def get_confirmation(self) -> tuple[bool, str | None]: """ Ask does user want to play TicTacToe against requester. First player is always requester. @@ -171,10 +171,10 @@ class Game: await confirm_message.delete() if reaction.emoji == Emojis.confirmation: return True, None - else: - self.over = True - self.canceled = True - return False, "User declined" + + self.over = True + self.canceled = True + return False, "User declined" @staticmethod async def add_reactions(msg: discord.Message) -> None: @@ -186,7 +186,8 @@ class Game: """Get formatted tic-tac-toe board for message.""" board = list(self.board.values()) return "\n".join( - (f"{board[line]} {board[line + 1]} {board[line + 2]}" for line in range(0, len(board), 3)) + f"{board[line]} {board[line + 1]} {board[line + 2]}" + for line in range(0, len(board), 3) ) async def play(self) -> None: @@ -256,7 +257,7 @@ class TicTacToe(Cog): @is_channel_free() @is_requester_free() @group(name="tictactoe", aliases=("ttt", "tic"), invoke_without_command=True) - async def tic_tac_toe(self, ctx: Context, opponent: Optional[discord.User]) -> None: + async def tic_tac_toe(self, ctx: Context, opponent: discord.User | None) -> None: """Tic Tac Toe game. Play against friends or AI. Use reactions to add your mark to field.""" if opponent == ctx.author: await ctx.send("You can't play against yourself.") |