fix mixuebingcheng matcher and file router

This commit is contained in:
tamakyi
2026-09-11 18:34:51 +08:00
parent 102bb070bb
commit f05ae46caf
2 changed files with 23 additions and 2 deletions
+20
View File
@@ -0,0 +1,20 @@
import secrets
from pathlib import Path
from typing import Literal
from .config import config
def random_pic(menu_type: Literal["drink", "eat", "me"]) -> tuple[Path, str]:
"""
随机获取一张图片
"""
if menu_type not in ["drink", "eat", "me"]:
raise ValueError("menu_type must be 'drink' or 'eat'")
menu_dir = Path(config.whatpic_res_path) / f"{menu_type}_pic"
pic_list = [entry.name for entry in menu_dir.iterdir() if entry.is_file()]
pic_name = secrets.choice(pic_list)
pic_path = Path(config.whatpic_res_path) / f"{menu_type}_pic" / pic_name
return pic_path, pic_name.split(".")[0]