chengyu update

This commit is contained in:
2025-10-14 01:23:49 +00:00
parent 4305548ab5
commit e9aac52200
3 changed files with 520 additions and 19 deletions

View File

@ -75,6 +75,25 @@ LAST_CHAR = ""
USER_NAME_CACHE = {} # 缓存用户名称,避免多次获取 USER_NAME_CACHE = {} # 缓存用户名称,避免多次获取
REMAIN_PLAYING_TIMES = 1
LAST_PLAY_DATE = ""
LOCK = False
ALL_BUFF_SCORE = 0 # 全体分数
import datetime
def be_able_to_play():
global REMAIN_PLAYING_TIMES, LAST_PLAY_DATE
if(LAST_PLAY_DATE != datetime.date.today()):
LAST_PLAY_DATE = datetime.date.today()
REMAIN_PLAYING_TIMES = 1
if(REMAIN_PLAYING_TIMES > 0):
REMAIN_PLAYING_TIMES -= 1
return True
return False
evt = on_alconna(Alconna( evt = on_alconna(Alconna(
"我要玩成语接龙" "我要玩成语接龙"
), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True) ), use_cmd_start=True, use_cmd_sep=False, skip_for_unmatch=True)
@ -82,6 +101,9 @@ evt = on_alconna(Alconna(
@evt.handle() @evt.handle()
async def _(event: BaseEvent): async def _(event: BaseEvent):
global NOW_PLAYING, LAST_CHAR, INITED global NOW_PLAYING, LAST_CHAR, INITED
if not be_able_to_play():
await evt.send(await UniMessage().text("玩玩玩,就知道玩,快去睡觉!").export())
return
if not INITED: if not INITED:
init_lexicon() init_lexicon()
INITED = True INITED = True
@ -102,7 +124,7 @@ evt = on_alconna(Alconna(
@evt.handle() @evt.handle()
async def _(event: BaseEvent): async def _(event: BaseEvent):
global NOW_PLAYING, SCORE_BOARD, LAST_CHAR global NOW_PLAYING, SCORE_BOARD, LAST_CHAR, ALL_BUFF_SCORE
if NOW_PLAYING: if NOW_PLAYING:
NOW_PLAYING = False NOW_PLAYING = False
# 发送好吧狗图片 # 发送好吧狗图片
@ -117,7 +139,7 @@ async def _(event: BaseEvent):
# 按分数排序,名字用 at 的方式 # 按分数排序,名字用 at 的方式
sorted_score = sorted(SCORE_BOARD.items(), key=lambda x: x[1]["score"], reverse=True) sorted_score = sorted(SCORE_BOARD.items(), key=lambda x: x[1]["score"], reverse=True)
for i, (user_id, info) in enumerate(sorted_score): for i, (user_id, info) in enumerate(sorted_score):
result_text += f"{i+1}. " + UniMessage().at(user_id) + f": {info['score']}\n" result_text += f"{i+1}. " + UniMessage().at(user_id) + f": {info['score'] + ALL_BUFF_SCORE}\n"
await evt.send(await result_text.export()) await evt.send(await result_text.export())
# 重置分数板 # 重置分数板
SCORE_BOARD = {} SCORE_BOARD = {}
@ -132,12 +154,11 @@ evt = on_alconna(Alconna(
@evt.handle() @evt.handle()
async def _(event: BaseEvent): async def _(event: BaseEvent):
global NOW_PLAYING, LAST_CHAR global NOW_PLAYING, LAST_CHAR, ALL_BUFF_SCORE
if not NOW_PLAYING: if not NOW_PLAYING:
return return
await evt.send(await UniMessage().text("你们太菜了全部扣100分").export()) await evt.send(await UniMessage().text("你们太菜了全部扣100分").export())
for user_id in SCORE_BOARD: ALL_BUFF_SCORE -= 100
SCORE_BOARD[user_id]["score"] -= 100
# 选择下一个成语 # 选择下一个成语
idiom = secrets.choice(ALL_IDIOMS) idiom = secrets.choice(ALL_IDIOMS)
LAST_CHAR = idiom[-1] LAST_CHAR = idiom[-1]
@ -148,12 +169,25 @@ evt = on_message()
@evt.handle() @evt.handle()
async def _(event: BaseEvent, msg: UniMsg): async def _(event: BaseEvent, msg: UniMsg):
global NOW_PLAYING, LAST_CHAR, SCORE_BOARD global NOW_PLAYING, LAST_CHAR, LOCK
if not NOW_PLAYING: if not NOW_PLAYING:
return return
user_idiom = msg.extract_plain_text().strip() user_idiom = msg.extract_plain_text().strip()
if(user_idiom[0] != LAST_CHAR): if(user_idiom[0] != LAST_CHAR):
return return
if LOCK:
return
LOCK = True
await handle_send_info(event, msg)
LOCK = False
async def handle_send_info(event: BaseEvent, msg: UniMsg):
global NOW_PLAYING, LAST_CHAR, SCORE_BOARD, ALL_BUFF_SCORE
if not NOW_PLAYING:
return
if LOCK:
return
user_idiom = msg.extract_plain_text().strip()
if(user_idiom not in ALL_IDIOMS and user_idiom not in ALL_WORDS): if(user_idiom not in ALL_IDIOMS and user_idiom not in ALL_WORDS):
await evt.send(await UniMessage().text("接不上!这个不一样!").export()) await evt.send(await UniMessage().text("接不上!这个不一样!").export())
return return
@ -172,6 +206,6 @@ async def _(event: BaseEvent, msg: UniMsg):
} }
SCORE_BOARD[user_id]["score"] += 1 SCORE_BOARD[user_id]["score"] += 1
# at 指定玩家 # at 指定玩家
await evt.send(await UniMessage().at(user_id).text(f"接对了!你有 {SCORE_BOARD[user_id]['score']} 分!").export()) await evt.send(await UniMessage().at(user_id).text(f"接对了!你有 {SCORE_BOARD[user_id]['score'] + ALL_BUFF_SCORE} 分!").export())
LAST_CHAR = user_idiom[-1] LAST_CHAR = user_idiom[-1]
await evt.send(await UniMessage().text(f"下一个成语请以「{LAST_CHAR}」开头!").export()) await evt.send(await UniMessage().text(f"下一个成语请以「{LAST_CHAR}」开头!").export())

486
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -37,5 +37,10 @@ name = "pt-gitea-pypi"
url = "https://gitea.service.jazzwhom.top/api/packages/Passthem/pypi/simple/" url = "https://gitea.service.jazzwhom.top/api/packages/Passthem/pypi/simple/"
priority = "supplemental" priority = "supplemental"
[[tool.poetry.source]]
name = "mirrors"
url = "https://pypi.tuna.tsinghua.edu.cn/simple/"
priority = "primary"
[tool.poetry.dependencies] [tool.poetry.dependencies]
ptimeparse = {source = "pt-gitea-pypi"} ptimeparse = {source = "pt-gitea-pypi"}