Attempting to add fen memory

This commit is contained in:
AllfatherHatt 2025-02-22 01:47:08 +01:00
parent f680dcae17
commit 9823284a31

View File

@ -8,11 +8,15 @@ class ChessHandler:
def __init__(self): def __init__(self):
self.active_games = {} # {user_id: FEN string} self.active_games = {} # {user_id: FEN string}
def set_board(self, user_id: str, fen: str): async def set_board(self, user_id: str, fen: str):
"""Sets a board to a given FEN string for a user.""" """Sets a board to a given FEN string for a user and saves it in long-term memory."""
try: try:
board = chess.Board(fen) # Validate FEN board = chess.Board(fen) # Validate FEN
self.active_games[user_id] = fen self.active_games[user_id] = fen
async with self.config.guild(ctx.guild).long_term_profiles() as long_memory:
long_memory[user_id] = {"fen": fen} # Store in long-term memory
return f"Board state updated successfully:\n```{fen}```" return f"Board state updated successfully:\n```{fen}```"
except ValueError: except ValueError:
return "⚠️ Invalid FEN format. Please provide a valid board state." return "⚠️ Invalid FEN format. Please provide a valid board state."
@ -27,9 +31,10 @@ class ChessHandler:
fen = self.active_games.get(user_id, chess.STARTING_FEN) fen = self.active_games.get(user_id, chess.STARTING_FEN)
return chess.Board(fen) return chess.Board(fen)
def get_fen(self, user_id: str): async def get_fen(self, user_id: str):
"""Returns the current FEN of the user's board.""" """Returns the current FEN of the user's board, using long-term memory."""
return self.active_games.get(user_id, chess.STARTING_FEN) async with self.config.guild(ctx.guild).long_term_profiles() as long_memory:
return long_memory.get(user_id, {}).get("fen", chess.STARTING_FEN)
def make_move(self, user_id: str, move: str): def make_move(self, user_id: str, move: str):
"""Attempts to execute a move and checks if the game is over.""" """Attempts to execute a move and checks if the game is over."""