猜成语新增功能

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-05-09 16:17:07 +08:00
parent d8cfaede12
commit 064d9ec947
3 changed files with 30238 additions and 37 deletions
@@ -15,19 +15,19 @@ from pypinyin import Style, pinyin
resource_dir = Path(__file__).parent / "resources"
fonts_dir = resource_dir / "fonts"
data_dir = resource_dir / "data"
idiom_path = data_dir / "idioms.txt"
answer_path = data_dir / "answers.json"
answer_hard_path = data_dir / "answers_hard.json"
handle_idiom_path = data_dir / "idioms.json"
handle_answer_path = data_dir / "answers.json"
handle_answer_hard_path = data_dir / "answers_hard.json"
LEGAL_PHRASES = [
idiom.strip() for idiom in idiom_path.open("r", encoding="utf-8").readlines()
]
ANSWER_PHRASES: List[Dict[str, str]] = json.load(
answer_path.open("r", encoding="utf-8")
HANDLE_LEGAL_PHRASES: List[str] = json.load(
handle_idiom_path.open("r", encoding="utf-8")
)
HARD_ANSWER_PHRASES: List[Dict[str, str]] = json.load(
answer_hard_path.open("r", encoding="utf-8")
HANDLE_ANSWER_PHRASES: List[Dict[str, str]] = json.load(
handle_answer_path.open("r", encoding="utf-8")
)
HANDLE_HARD_ANSWER_PHRASES: List[Dict[str, str]] = json.load(
handle_answer_hard_path.open("r", encoding="utf-8")
)
# class LegalPhrasesModifiedHandler(FileSystemEventHandler):
@@ -59,11 +59,13 @@ HARD_ANSWER_PHRASES: List[Dict[str, str]] = json.load(
def legal_idiom(word: str) -> bool:
return word in LEGAL_PHRASES
return word in HANDLE_LEGAL_PHRASES
def random_idiom(is_hard: bool = False) -> Tuple[str, str]:
answer = random.choice(HARD_ANSWER_PHRASES if is_hard else ANSWER_PHRASES)
answer = random.choice(
HANDLE_HARD_ANSWER_PHRASES if is_hard else HANDLE_ANSWER_PHRASES
)
return answer["word"], answer["explanation"]