This commit is contained in:
@ -97,7 +97,9 @@ class TryStopState(Enum):
|
||||
class TryVerifyState(Enum):
|
||||
VERIFIED = 0
|
||||
NOT_ORACLE = 1
|
||||
GAME_END = 2
|
||||
HINT_ONE = 2
|
||||
HINT_TWO = 3
|
||||
GAME_END = 4
|
||||
|
||||
class oracleGame:
|
||||
ALL_ORACLES = {}
|
||||
@ -115,6 +117,7 @@ class oracleGame:
|
||||
self.lock = asynkio.Lock()
|
||||
self.remain_rounds = 0 # 剩余回合数
|
||||
self.current_oracle_id = ""
|
||||
self.wrong_attempts = 0
|
||||
oracleGame.INSTANCE_LIST[group_id] = self
|
||||
|
||||
def be_able_to_play(self) -> bool:
|
||||
@ -208,10 +211,17 @@ class oracleGame:
|
||||
async def _verify_oracle(self, oracle: str, user_id: str) -> list[TryVerifyState]:
|
||||
state = []
|
||||
if oracle.strip() not in self.ALL_ORACLES[self.current_oracle_id].get("oracle", ""):
|
||||
return [TryVerifyState.NOT_ORACLE]
|
||||
state.append(TryVerifyState.NOT_ORACLE)
|
||||
self.wrong_attempts += 1
|
||||
if self.wrong_attempts == 5:
|
||||
state.append(TryVerifyState.HINT_ONE)
|
||||
elif self.wrong_attempts == 10:
|
||||
state.append(TryVerifyState.HINT_TWO)
|
||||
return state
|
||||
if oracle.strip() == "":
|
||||
return [TryVerifyState.NOT_ORACLE]
|
||||
# 甲骨文合法,更新状态
|
||||
self.wrong_attempts = 0
|
||||
state.append(TryVerifyState.VERIFIED)
|
||||
self.add_score(user_id, 1) # 加 1 分
|
||||
self.remain_rounds -= 1
|
||||
@ -239,6 +249,12 @@ class oracleGame:
|
||||
|
||||
def get_playing_state(self) -> bool:
|
||||
return self.now_playing
|
||||
|
||||
def get_pinyin_hint(self) -> str:
|
||||
return self.ALL_ORACLES[self.current_oracle_id].get("pinyin", "无")
|
||||
|
||||
def get_meaning_hint(self) -> str:
|
||||
return self.ALL_ORACLES[self.current_oracle_id].get("meaning", "无")
|
||||
|
||||
@classmethod
|
||||
async def init_lexicon(cls):
|
||||
@ -259,6 +275,8 @@ class oracleGame:
|
||||
cls.ALL_ORACLES[char] = {
|
||||
"oracle": oracle,
|
||||
"image": img_path,
|
||||
"pinyin": row.get("拼音", "").strip(),
|
||||
"meaning": row.get("含义", "").strip(),
|
||||
}
|
||||
|
||||
logger.info(f"加载甲骨文字典,共计 {len(cls.ALL_ORACLES)} 条记录")
|
||||
@ -455,8 +473,25 @@ async def _(event: BaseEvent, msg: UniMsg, target: DepLongTaskTarget):
|
||||
if not instance or not instance.get_playing_state():
|
||||
return
|
||||
user_oracle = msg.extract_plain_text().strip()
|
||||
# 甲骨文应该是单个汉字
|
||||
if len(user_oracle) != 1:
|
||||
return
|
||||
user_id, user_name = get_user_info(event)
|
||||
state = await instance.try_verify_oracle(user_oracle, user_id)
|
||||
if TryVerifyState.HINT_ONE in state:
|
||||
hint_pinyin = instance.get_pinyin_hint()
|
||||
await evt.send(
|
||||
await UniMessage()
|
||||
.text(f"提示:这个甲骨文的拼音是「{hint_pinyin}」")
|
||||
.export()
|
||||
)
|
||||
if TryVerifyState.HINT_TWO in state:
|
||||
hint_meaning = instance.get_meaning_hint()
|
||||
await evt.send(
|
||||
await UniMessage()
|
||||
.text(f"提示:这个甲骨文的含义是「{hint_meaning}」")
|
||||
.export()
|
||||
)
|
||||
if TryVerifyState.NOT_ORACLE in state:
|
||||
return
|
||||
if TryVerifyState.VERIFIED in state:
|
||||
|
||||
0
konabot/plugins/oracle_game/hanzi_info.py
Normal file
0
konabot/plugins/oracle_game/hanzi_info.py
Normal file
Reference in New Issue
Block a user