Recovery modules & bugfix
This commit is contained in:
parent
eef465408d
commit
5ca0bb56ce
14 changed files with 390 additions and 396 deletions
|
@ -11,6 +11,7 @@ from tenacity import retry, stop_after_attempt
|
|||
|
||||
from core.builtins import Bot
|
||||
from core.builtins import Image, Plain
|
||||
from core.component import module
|
||||
from core.logger import Logger
|
||||
from core.utils.cache import random_cache_path
|
||||
from core.utils.http import get_url, download_to_cache
|
||||
|
@ -85,21 +86,63 @@ async def search_csr(id=None): # 根据 ChemSpider 的 ID 查询 ChemSpider 的
|
|||
'length': value,
|
||||
'elements': elements}
|
||||
|
||||
async def chemical_code(msg: Bot.MessageSession, play_state, id=None, captcha_mode=False):
|
||||
|
||||
ccode = module('chemical_code', alias={'cc': 'chemical_code',
|
||||
'chemicalcode': 'chemical_code',
|
||||
'chemical_captcha': 'chemical_code captcha',
|
||||
'chemicalcaptcha': 'chemical_code captcha',
|
||||
'ccode': 'chemical_code',
|
||||
'ccaptcha': 'chemical_code captcha'},
|
||||
desc='{chemical_code.help.desc}', developers=['OasisAkari'])
|
||||
play_state = {} # 创建一个空字典用于存放游戏状态
|
||||
|
||||
|
||||
@ccode.command('{{chemical_code.help}}') # 直接使用 ccode 命令将触发此装饰器
|
||||
async def chemical_code_by_random(msg: Bot.MessageSession):
|
||||
await chemical_code(msg) # 将消息会话传入 chemical_code 函数
|
||||
|
||||
|
||||
@ccode.command('captcha {{chemical_code.help.captcha}}')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
await chemical_code(msg, captcha_mode=True)
|
||||
|
||||
|
||||
@ccode.command('stop {{chemical_code.stop.help}}')
|
||||
async def s(msg: Bot.MessageSession):
|
||||
state = play_state.get(msg.target.targetId, False) # 尝试获取 play_state 中是否有此对象的游戏状态
|
||||
if state: # 若有
|
||||
if state['active']: # 检查是否为活跃状态
|
||||
play_state[msg.target.targetId]['active'] = False # 标记为非活跃状态
|
||||
await msg.finish(
|
||||
msg.locale.t('chemical_code.stop.message', answer=play_state[msg.target.targetId]["answer"]),
|
||||
quote=False) # 发送存储于 play_state 中的答案
|
||||
else:
|
||||
await msg.finish(msg.locale.t('chemical_code.stop.message.none'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('chemical_code.stop.message.none'))
|
||||
|
||||
|
||||
@ccode.command('<csid> {{chemical_code.help.csid}}')
|
||||
async def chemical_code_by_id(msg: Bot.MessageSession):
|
||||
id = msg.parsed_msg['<csid>'] # 从已解析的消息中获取 ChemSpider ID
|
||||
if (id.isdigit() and int(id) > 0): # 如果 ID 为纯数字
|
||||
await chemical_code(msg, id) # 将消息会话和 ID 一并传入 chemical_code 函数
|
||||
else:
|
||||
await msg.finish(msg.locale.t('chemical_code.message.csid.invalid'))
|
||||
|
||||
|
||||
async def chemical_code(msg: Bot.MessageSession, id=None, captcha_mode=False):
|
||||
# 要求传入消息会话和 ChemSpider ID,ID 留空将会使用缺省值 None
|
||||
# 检查对象(群组或私聊)是否在 play_state 中有记录及是否为活跃状态
|
||||
if msg.target.targetId in play_state and play_state[msg.target.targetId]['active']:
|
||||
if play_state[msg.target.targetId]['game'] == 'ccode':
|
||||
await msg.finish(msg.locale.t('game.message.running'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.message.running.others'))
|
||||
play_state.update({msg.target.targetId: {'game': 'ccode', 'active': True}}) # 若无,则创建一个新的记录并标记为活跃状态
|
||||
await msg.finish(msg.locale.t('chemical_code.message.running'))
|
||||
play_state.update({msg.target.targetId: {'active': True}}) # 若无,则创建一个新的记录并标记为活跃状态
|
||||
try:
|
||||
csr = await search_csr(id) # 尝试获取 ChemSpider ID 对应的化学式列表
|
||||
except Exception as e: # 意外情况
|
||||
traceback.print_exc() # 打印错误信息
|
||||
play_state[msg.target.targetId]['active'] = False # 将对象标记为非活跃状态
|
||||
return await msg.finish(msg.locale.t('game.chemical_code.message.error.get_failed'))
|
||||
return await msg.finish(msg.locale.t('chemical_code.message.error'))
|
||||
# print(csr)
|
||||
play_state[msg.target.targetId]['answer'] = csr['name'] # 将正确答案标记于 play_state 中存储的对象中
|
||||
Logger.info(f'Answer: {csr["name"]}') # 在日志中输出正确答案
|
||||
|
@ -127,7 +170,7 @@ async def chemical_code(msg: Bot.MessageSession, play_state, id=None, captcha_mo
|
|||
|
||||
async def ans(msg: Bot.MessageSession, answer): # 定义回答函数的功能
|
||||
wait = await msg.waitAnyone() # 等待对象内的任意人回答
|
||||
if play_state[msg.target.targetId]['active'] and play_state[msg.target.targetId]['game'] == 'ccode': # 检查对象是否为活跃状态
|
||||
if play_state[msg.target.targetId]['active']: # 检查对象是否为活跃状态
|
||||
if (wait_text := wait.asDisplay(text_only=True)) != answer: # 如果回答不正确
|
||||
if re.match(r'^[A-Za-z0-9]+$', wait_text):
|
||||
try:
|
||||
|
@ -139,20 +182,20 @@ async def chemical_code(msg: Bot.MessageSession, play_state, id=None, captcha_mo
|
|||
if v_ < 0:
|
||||
v_ = -v_
|
||||
if v_ > 6:
|
||||
await wait.sendMessage(wait.locale.t('game.chemical_code.message.incorrect.remind1'))
|
||||
await wait.sendMessage(wait.locale.t('chemical_code.message.incorrect.remind1'))
|
||||
else:
|
||||
if csr['elements'] == parse_:
|
||||
await wait.sendMessage(wait.locale.t('game.chemical_code.message.incorrect.remind5'))
|
||||
await wait.sendMessage(wait.locale.t('chemical_code.message.incorrect.remind5'))
|
||||
elif v_ <= 2:
|
||||
missing_something = False
|
||||
for i in csr['elements']:
|
||||
if i not in parse_:
|
||||
await wait.sendMessage(
|
||||
wait.locale.t('game.chemical_code.message.incorrect.remind4'))
|
||||
wait.locale.t('chemical_code.message.incorrect.remind4'))
|
||||
missing_something = True
|
||||
break
|
||||
if not missing_something:
|
||||
await wait.sendMessage(wait.locale.t('game.chemical_code.message.incorrect.remind3'))
|
||||
await wait.sendMessage(wait.locale.t('chemical_code.message.incorrect.remind3'))
|
||||
else:
|
||||
incorrect_list = []
|
||||
for i in csr['elements']:
|
||||
|
@ -161,12 +204,12 @@ async def chemical_code(msg: Bot.MessageSession, play_state, id=None, captcha_mo
|
|||
incorrect_list.append(i)
|
||||
else:
|
||||
await wait.sendMessage(
|
||||
wait.locale.t('game.chemical_code.message.incorrect.remind4'))
|
||||
wait.locale.t('chemical_code.message.incorrect.remind4'))
|
||||
incorrect_list = []
|
||||
break
|
||||
|
||||
if incorrect_list:
|
||||
await wait.sendMessage(wait.locale.t('game.chemical_code.message.incorrect.remind2',
|
||||
await wait.sendMessage(wait.locale.t('chemical_code.message.incorrect.remind2',
|
||||
elements=', '.join(incorrect_list)))
|
||||
|
||||
except ValueError:
|
||||
|
@ -175,14 +218,14 @@ async def chemical_code(msg: Bot.MessageSession, play_state, id=None, captcha_mo
|
|||
Logger.info(f'{wait_text} != {answer}') # 输出日志
|
||||
return await ans(wait, answer) # 进行下一轮检查
|
||||
else:
|
||||
await wait.sendMessage(wait.locale.t('game.message.correct'))
|
||||
await wait.sendMessage(wait.locale.t('chemical_code.message.correct'))
|
||||
play_state[msg.target.targetId]['active'] = False # 将对象标记为非活跃状态
|
||||
|
||||
async def timer(start): # 计时器函数
|
||||
if play_state[msg.target.targetId]['active'] and play_state[msg.target.targetId]['game'] == 'ccode': # 检查对象是否为活跃状态
|
||||
if play_state[msg.target.targetId]['active']: # 检查对象是否为活跃状态
|
||||
if datetime.now().timestamp() - start > 60 * set_timeout: # 如果超过2分钟
|
||||
await msg.sendMessage(
|
||||
msg.locale.t('game.chemical_code.message.timeup', answer=play_state[msg.target.targetId]["answer"]))
|
||||
msg.locale.t('chemical_code.message.timeup', answer=play_state[msg.target.targetId]["answer"]))
|
||||
play_state[msg.target.targetId]['active'] = False
|
||||
else: # 如果未超时
|
||||
await asyncio.sleep(1) # 等待1秒
|
||||
|
@ -190,17 +233,17 @@ async def chemical_code(msg: Bot.MessageSession, play_state, id=None, captcha_mo
|
|||
|
||||
if not captcha_mode:
|
||||
await msg.sendMessage([Image(newpath),
|
||||
Plain(msg.locale.t('game.chemical_code.message', times=set_timeout))])
|
||||
Plain(msg.locale.t('chemical_code.message', times=set_timeout))])
|
||||
time_start = datetime.now().timestamp() # 记录开始时间
|
||||
|
||||
await asyncio.gather(ans(msg, csr['name']), timer(time_start)) # 同时启动回答函数和计时器函数
|
||||
else:
|
||||
result = await msg.waitNextMessage(
|
||||
[Image(newpath), Plain(msg.locale.t('game.chemical_code.message.captcha', times=set_timeout))])
|
||||
if play_state[msg.target.targetId]['active'] and play_state[msg.target.targetId]['game'] == 'ccode': # 检查对象是否为活跃状态
|
||||
[Image(newpath), Plain(msg.locale.t('chemical_code.message.captcha', times=set_timeout))])
|
||||
if play_state[msg.target.targetId]['active']: # 检查对象是否为活跃状态
|
||||
if result.asDisplay(text_only=True) == csr['name']:
|
||||
await result.sendMessage(msg.locale.t('game.message.correct'))
|
||||
await result.sendMessage(msg.locale.t('chemical_code.message.correct'))
|
||||
else:
|
||||
await result.sendMessage(
|
||||
msg.locale.t('game.chemical_code.message.incorrect', answer=play_state[msg.target.targetId]["answer"]))
|
||||
msg.locale.t('chemical_code.message.incorrect', answer=play_state[msg.target.targetId]["answer"]))
|
||||
play_state[msg.target.targetId]['active'] = False
|
23
modules/chemical_code/locales/en_us.json
Normal file
23
modules/chemical_code/locales/en_us.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"chemical_code.help": "Default mode (Time limits, multiple)",
|
||||
"chemical_code.help.captcha": "Captcha mode (Only once, single)",
|
||||
"chemical_code.help.csid": "Start a game by ChemSpider ID",
|
||||
"chemical_code.help.desc": "A game about chemical formulas.",
|
||||
"chemical_code.message": "Please answer the chemical formula of this compound within ${times} minutes. (Alphabetical order except C, H. e.g. CHBrClF)",
|
||||
"chemical_code.message.captcha": "Please answer the chemical formula of this compound. (Alphabetical order except C, H. e.g. CHBrClF)",
|
||||
"chemical_code.message.correct": "Correct.",
|
||||
"chemical_code.message.csid.invalid": "An error occurred: Invalid ID!",
|
||||
"chemical_code.message.csid.invalid.num": "An error occurred: ID must be purely numeric!",
|
||||
"chemical_code.message.error": "An error occurred: Failed to start, maybe caused by request database timed out or the ID is invalid? Please restart the game.",
|
||||
"chemical_code.message.incorrect": "Incorrect. The correct answer is ${answer}.",
|
||||
"chemical_code.message.incorrect.remind1": "提示:不正确,请重试。",
|
||||
"chemical_code.message.incorrect.remind2": "提示:${elements} 的数量不正确,请检查。",
|
||||
"chemical_code.message.incorrect.remind3": "Almost there! Try again!",
|
||||
"chemical_code.message.incorrect.remind4": "提示:可能有元素遗漏,请检查。",
|
||||
"chemical_code.message.incorrect.remind5": "提示:元素顺序不正确,请检查。",
|
||||
"chemical_code.message.running": "There is currently a game in progress.",
|
||||
"chemical_code.message.timeup": "Timeout. The correct answer is ${answer}.",
|
||||
"chemical_code.stop.help": "Stop the current game.",
|
||||
"chemical_code.stop.message": "Stopped. The correct answer is ${answer}.",
|
||||
"chemical_code.stop.message.none": "There is no game in progress."
|
||||
}
|
23
modules/chemical_code/locales/zh_cn.json
Normal file
23
modules/chemical_code/locales/zh_cn.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"chemical_code.help": "普通样式(时间限制,多人)",
|
||||
"chemical_code.help.captcha": "验证码样式(不支持指定ID,仅限一次,单人)",
|
||||
"chemical_code.help.csid": "根据 ChemSpider ID 出题。",
|
||||
"chemical_code.help.desc": "化学式回答小游戏。",
|
||||
"chemical_code.message": "请在 ${times} 分钟内回答这个化合物的分子式。(除 C、H 外使用字母表顺序,如:CHBrClF)",
|
||||
"chemical_code.message.captcha": "请回答这个化合物的分子式。(除 C、H 外使用字母表顺序,如:CHBrClF)",
|
||||
"chemical_code.message.correct": "回答正确。",
|
||||
"chemical_code.message.csid.invalid": "发生错误:请输入正确的 ID!",
|
||||
"chemical_code.message.csid.invalid.num": "发生错误:请输入数字 ID!",
|
||||
"chemical_code.message.error": "发生错误:拉取题目失败,可能是因为请求超时或 ID 无效,请重新发起游戏。",
|
||||
"chemical_code.message.incorrect": "回答错误,正确答案是 ${answer}。",
|
||||
"chemical_code.message.incorrect.remind1": "提示:不正确,请重试。",
|
||||
"chemical_code.message.incorrect.remind2": "提示:${elements} 的数量不正确,请检查。",
|
||||
"chemical_code.message.incorrect.remind3": "提示:已经很接近了,请重试。",
|
||||
"chemical_code.message.incorrect.remind4": "提示:可能有元素遗漏,请检查。",
|
||||
"chemical_code.message.incorrect.remind5": "提示:元素顺序不正确,请检查。",
|
||||
"chemical_code.message.running": "当前有游戏正在进行中。",
|
||||
"chemical_code.message.timeup": "已超时,正确答案是 ${answer}。",
|
||||
"chemical_code.stop.help": "停止当前的游戏。",
|
||||
"chemical_code.stop.message": "已停止,正确答案是 ${answer}。",
|
||||
"chemical_code.stop.message.none": "当前没有游戏正在进行。"
|
||||
}
|
23
modules/chemical_code/locales/zh_tw.json
Normal file
23
modules/chemical_code/locales/zh_tw.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"chemical_code.help": "普通樣式(時間限制,多人)",
|
||||
"chemical_code.help.captcha": "驗證碼樣式(不支援特定 ID,僅限一次,單人)",
|
||||
"chemical_code.help.csid": "依據 ChemSpider ID 出題。",
|
||||
"chemical_code.help.desc": "化學式回答小遊戲。",
|
||||
"chemical_code.message": "請在 ${times} 分鐘內回答這個化合物的分子式。(除 C、H 外使用字母表順序,如:CHBrClF)",
|
||||
"chemical_code.message.captcha": "請回答這個化合物的分子式。(除 C、H 外使用字母表順序,如:CHBrClF)",
|
||||
"chemical_code.message.correct": "回答正確。",
|
||||
"chemical_code.message.csid.invalid": "發生錯誤:請輸入正確的 ID!",
|
||||
"chemical_code.message.csid.invalid.num": "發生錯誤:請輸入數字 ID!",
|
||||
"chemical_code.message.error": "發生錯誤:無法取得題目,可能是因為請求逾時或是 ID 無效,請重新發起遊戲。",
|
||||
"chemical_code.message.incorrect": "回答錯誤,正確答案是 ${answer}。",
|
||||
"chemical_code.message.incorrect.remind1": "提示:不正确,请重试。",
|
||||
"chemical_code.message.incorrect.remind2": "提示:${elements} 的数量不正确,请检查。",
|
||||
"chemical_code.message.incorrect.remind3": "提示:已经很接近了,请重试。",
|
||||
"chemical_code.message.incorrect.remind4": "提示:可能有元素遗漏,请检查。",
|
||||
"chemical_code.message.incorrect.remind5": "提示:元素顺序不正确,请检查。",
|
||||
"chemical_code.message.running": "目前有遊戲正在進行。",
|
||||
"chemical_code.message.timeup": "回答逾時,正確答案是 ${answer}。",
|
||||
"chemical_code.stop.help": "停止目前的遊戲。",
|
||||
"chemical_code.stop.message": "已停止,正確答案是 ${answer}。",
|
||||
"chemical_code.stop.message.none": "目前沒有遊戲正在進行。"
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
from core.builtins import Bot
|
||||
from core.component import module
|
||||
from .chemical_code import chemical_code
|
||||
from .twenty_four import twenty_four
|
||||
|
||||
play_state = {} # 创建一个空字典用于存放游戏状态
|
||||
|
||||
|
||||
ccode = module('chemical_code', alias={'cc': 'chemical_code',
|
||||
'chemicalcode': 'chemical_code',
|
||||
'chemical_captcha': 'chemical_code captcha',
|
||||
'chemicalcaptcha': 'chemical_code captcha',
|
||||
'ccode': 'chemical_code',
|
||||
'ccaptcha': 'chemical_code captcha'},
|
||||
desc='{game.chemical_code.help.desc}', developers=['OasisAkari'])
|
||||
|
||||
|
||||
@ccode.command('{{game.chemical_code.help}}') # 直接使用 ccode 命令将触发此装饰器
|
||||
async def chemical_code_by_random(msg: Bot.MessageSession):
|
||||
await chemical_code(msg, play_state) # 将消息会话传入 chemical_code 函数
|
||||
|
||||
|
||||
@ccode.command('captcha {{game.chemical_code.help.captcha}}')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
await chemical_code(msg, play_state, captcha_mode=True)
|
||||
|
||||
|
||||
@ccode.command('stop {{game.stop.help}}')
|
||||
async def stop(msg: Bot.MessageSession):
|
||||
state = play_state.get(msg.target.targetId, False) # 尝试获取 play_state 中是否有此对象的游戏状态
|
||||
if state: # 若有
|
||||
if state['active']: # 检查是否为活跃状态
|
||||
if state['game'] == 'ccode':
|
||||
play_state[msg.target.targetId]['active'] = False # 标记为非活跃状态
|
||||
await msg.finish(
|
||||
msg.locale.t('game.chemical_code.stop.message', answer=play_state[msg.target.targetId]["answer"]),
|
||||
quote=False) # 发送存储于 play_state 中的答案
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.stop.message.others'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.stop.message.none'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.stop.message.none'))
|
||||
|
||||
|
||||
@ccode.command('<csid> {{game.chemical_code.help.csid}}')
|
||||
async def chemical_code_by_id(msg: Bot.MessageSession):
|
||||
id = msg.parsed_msg['<csid>'] # 从已解析的消息中获取 ChemSpider ID
|
||||
if (id.isdigit() and int(id) > 0): # 如果 ID 为纯数字
|
||||
await chemical_code(msg, play_state, id) # 将消息会话和 ID 一并传入 chemical_code 函数
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.chemical_code.message.error.invalid'))
|
||||
|
||||
|
||||
|
||||
|
||||
tf = module('twenty_four', alias=['twentyfour', '24'],
|
||||
desc='{game.twenty_four.help.desc}', developers=['DoroWolf'])
|
||||
|
||||
|
||||
@tf.command('{{game.twenty_four.help}}')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
await twenty_four(msg, play_state) # 将消息会话传入 chemical_code 函数
|
||||
|
||||
|
||||
@tf.command('stop {{game.stop.help}}')
|
||||
async def stop(msg: Bot.MessageSession):
|
||||
state = play_state.get(msg.target.targetId, False)
|
||||
if state:
|
||||
if state['active']:
|
||||
if state['game'] == '24':
|
||||
play_state[msg.target.targetId]['active'] = False
|
||||
await msg.finish(msg.locale.t('game.stop.message', quote=False))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.stop.message.others'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.stop.message.none'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.stop.message.none'))
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
"game.chemical_code.help": "Default mode (Time limits, multiple)",
|
||||
"game.chemical_code.help.captcha": "Captcha mode (Only once, single)",
|
||||
"game.chemical_code.help.csid": "Start a game by ChemSpider ID",
|
||||
"game.chemical_code.help.desc": "A game about chemical formulas.",
|
||||
"game.chemical_code.message": "Please answer the chemical formula of this compound within ${times} minutes. (Alphabetical order except C, H. e.g. CHBrClF)",
|
||||
"game.chemical_code.message.captcha": "Please answer the chemical formula of this compound. (Alphabetical order except C, H. e.g. CHBrClF)",
|
||||
"game.chemical_code.message.error.get_failed": "An error occurred: Failed to start, maybe caused by request database timed out or the ID is invalid? Please restart the game.",
|
||||
"game.chemical_code.message.error.invalid": "An error occurred: Invalid ID!",
|
||||
"game.chemical_code.message.error.non_digital": "An error occurred: ID must be purely numeric!",
|
||||
"game.chemical_code.message.incorrect": "Incorrect. The correct answer is ${answer}.",
|
||||
"game.chemical_code.message.incorrect.remind1": "提示:不正确,请重试。",
|
||||
"game.chemical_code.message.incorrect.remind2": "提示:${elements} 的数量不正确,请检查。",
|
||||
"game.chemical_code.message.incorrect.remind3": "Almost there! Try again!",
|
||||
"game.chemical_code.message.incorrect.remind4": "提示:可能有元素遗漏,请检查。",
|
||||
"game.chemical_code.message.incorrect.remind5": "提示:元素顺序不正确,请检查。",
|
||||
"game.chemical_code.message.timeup": "Timeout. The correct answer is ${answer}.",
|
||||
"game.chemical_code.stop.message": "Stopped. The correct answer is ${answer}.",
|
||||
"game.message.correct": "Correct.",
|
||||
"game.message.incorrect": "Incorrect.",
|
||||
"game.message.running": "There is currently a game in progress.",
|
||||
"game.message.running.others": "当前有其他游戏正在进行中。",
|
||||
"game.stop.help": "Stop the current game.",
|
||||
"game.stop.message": "已停止。",
|
||||
"game.stop.message.none": "There is no game in progress.",
|
||||
"game.stop.message.others": "当前此游戏未在进行。",
|
||||
"game.twenty_four.help": "开始新游戏。",
|
||||
"game.twenty_four.help.desc": "24 点小游戏。",
|
||||
"game.twenty_four.message": "给出的数字组合:${numbers}\n请输入表达式使其结果为 24。(若无解,请输入“无解”)",
|
||||
"game.twenty_four.message.incorrect.expression_invalid": "回答错误:表达式无效。",
|
||||
"game.twenty_four.message.incorrect.have_solution": "回答错误:该组合存在解。"
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
"game.chemical_code.help": "普通样式(时间限制,多人)",
|
||||
"game.chemical_code.help.captcha": "验证码样式(不支持指定ID,仅限一次,单人)",
|
||||
"game.chemical_code.help.csid": "根据 ChemSpider ID 出题。",
|
||||
"game.chemical_code.help.desc": "化学式回答小游戏。",
|
||||
"game.chemical_code.message": "请在 ${times} 分钟内回答这个化合物的分子式。(除 C、H 外使用字母表顺序,如:CHBrClF)",
|
||||
"game.chemical_code.message.captcha": "请回答这个化合物的分子式。(除 C、H 外使用字母表顺序,如:CHBrClF)",
|
||||
"game.chemical_code.message.error.get_failed": "发生错误:拉取题目失败,可能是因为请求超时或 ID 无效,请重新发起游戏。",
|
||||
"game.chemical_code.message.error.invalid": "发生错误:请输入正确的 ID!",
|
||||
"game.chemical_code.message.error.non_digital": "发生错误:请输入数字 ID!",
|
||||
"game.chemical_code.message.incorrect": "回答错误,正确答案是 ${answer}。",
|
||||
"game.chemical_code.message.incorrect.remind1": "提示:不正确,请重试。",
|
||||
"game.chemical_code.message.incorrect.remind2": "提示:${elements} 的数量不正确,请检查。",
|
||||
"game.chemical_code.message.incorrect.remind3": "提示:已经很接近了,请重试。",
|
||||
"game.chemical_code.message.incorrect.remind4": "提示:可能有元素遗漏,请检查。",
|
||||
"game.chemical_code.message.incorrect.remind5": "提示:元素顺序不正确,请检查。",
|
||||
"game.chemical_code.message.timeup": "已超时,正确答案是 ${answer}。",
|
||||
"game.chemical_code.stop.message": "已停止,正确答案是 ${answer}。",
|
||||
"game.message.correct": "回答正确。",
|
||||
"game.message.incorrect": "回答错误。",
|
||||
"game.message.running": "当前有一局游戏正在进行中。",
|
||||
"game.message.running.others": "当前有其他游戏正在进行中。",
|
||||
"game.stop.help": "停止当前的游戏。",
|
||||
"game.stop.message": "已停止。",
|
||||
"game.stop.message.none": "当前没有游戏正在进行。",
|
||||
"game.stop.message.others": "当前此游戏未在进行。",
|
||||
"game.twenty_four.help": "开始新游戏。",
|
||||
"game.twenty_four.help.desc": "24 点小游戏。",
|
||||
"game.twenty_four.message": "给出的数字组合:${numbers}\n请输入表达式使其结果为 24。(若无解,请输入“无解”)",
|
||||
"game.twenty_four.message.incorrect.expression_invalid": "回答错误:表达式无效。",
|
||||
"game.twenty_four.message.incorrect.have_solution": "回答错误:该组合存在解。"
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
{
|
||||
"game.chemical_code.help": "普通樣式(時間限制,多人)",
|
||||
"game.chemical_code.help.captcha": "驗證碼樣式(不支援特定 ID,僅限一次,單人)",
|
||||
"game.chemical_code.help.csid": "依據 ChemSpider ID 出題。",
|
||||
"game.chemical_code.help.desc": "化學式回答小遊戲。",
|
||||
"game.chemical_code.message": "請在 ${times} 分鐘內回答這個化合物的分子式。(除 C、H 外使用字母表順序,如:CHBrClF)",
|
||||
"game.chemical_code.message.captcha": "請回答這個化合物的分子式。(除 C、H 外使用字母表順序,如:CHBrClF)",
|
||||
"game.chemical_code.message.error.get_failed": "發生錯誤:無法取得題目,可能是因為請求逾時或是 ID 無效,請重新發起遊戲。",
|
||||
"game.chemical_code.message.error.invalid": "發生錯誤:請輸入正確的 ID!",
|
||||
"game.chemical_code.message.error.non_digital": "發生錯誤:請輸入數字 ID!",
|
||||
"game.chemical_code.message.incorrect": "回答錯誤,正確答案是 ${answer}。",
|
||||
"game.chemical_code.message.incorrect.remind1": "提示:不正确,请重试。",
|
||||
"game.chemical_code.message.incorrect.remind2": "提示:${elements} 的数量不正确,请检查。",
|
||||
"game.chemical_code.message.incorrect.remind3": "提示:已经很接近了,请重试。",
|
||||
"game.chemical_code.message.incorrect.remind4": "提示:可能有元素遗漏,请检查。",
|
||||
"game.chemical_code.message.incorrect.remind5": "提示:元素顺序不正确,请检查。",
|
||||
"game.chemical_code.message.timeup": "回答逾時,正確答案是 ${answer}。",
|
||||
"game.chemical_code.stop.message": "已停止,正確答案是 ${answer}。",
|
||||
"game.message.correct": "回答正確。",
|
||||
"game.message.incorrect": "回答錯誤。",
|
||||
"game.message.running": "目前有遊戲正在進行。",
|
||||
"game.message.running.others": "目前有其他遊戲正在進行。",
|
||||
"game.stop.help": "停止目前的遊戲。",
|
||||
"game.stop.message": "已停止。",
|
||||
"game.stop.message.none": "目前沒有遊戲正在進行。",
|
||||
"game.stop.message.others": "目前此遊戲沒有在進行。",
|
||||
"game.twenty_four.help": "開始新遊戲。",
|
||||
"game.twenty_four.help.desc": "24 點小遊戲。",
|
||||
"game.twenty_four.message": "給出的數字組合:${numbers}\n請輸入運算式使其結果為 24。(若無解,請輸入「無解」)",
|
||||
"game.twenty_four.message.incorrect.expression_invalid": "回答錯誤:運算式無效。",
|
||||
"game.twenty_four.message.incorrect.have_solution": "回答錯誤:該組合存在解。"
|
||||
}
|
|
@ -352,7 +352,7 @@ async def _(msg: Bot.MessageSession, id_or_alias: str, diff: str = None):
|
|||
|
||||
if diff is not None:
|
||||
diff_index = get_diff(diff)
|
||||
if len(music['ds']) == 4 and diff_index == 4:
|
||||
if not diff_index or (len(music['ds']) == 4 and diff_index == 4):
|
||||
await msg.finish(msg.locale.t("maimai.message.chart_not_found"))
|
||||
chart = music['charts'][diff_index]
|
||||
ds = music['ds'][diff_index]
|
||||
|
|
|
@ -14,6 +14,7 @@ async def get_alias(input, get_music=False):
|
|||
if input in data:
|
||||
result = data[input]
|
||||
else:
|
||||
input = input.replace("_", " ")
|
||||
for alias, ids in data.items():
|
||||
if input in ids:
|
||||
result.append(alias)
|
||||
|
|
|
@ -87,31 +87,48 @@ def contains_all_numbers(expression, numbers):
|
|||
return len(used_numbers) == 0
|
||||
|
||||
|
||||
async def twenty_four(msg, play_state):
|
||||
tf = module('twenty_four', alias=['twentyfour', '24'],
|
||||
desc='{twenty_four.help.desc}', developers=['DoroWolf'])
|
||||
play_state = {}
|
||||
|
||||
|
||||
@tf.command('{{twenty_four.help}}')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
if msg.target.targetId in play_state and play_state[msg.target.targetId]['active']:
|
||||
if play_state[msg.target.targetId]['game'] == '24':
|
||||
await msg.finish(msg.locale.t('game.message.running'))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.message.running.others'))
|
||||
play_state.update({msg.target.targetId: {'game': '24', 'active': True}})
|
||||
await msg.finish(msg.locale.t('twenty_four.message.running'))
|
||||
play_state.update({msg.target.targetId: {'active': True}})
|
||||
|
||||
numbers = [random.randint(1, 13) for _ in range(4)]
|
||||
has_solution_flag = has_solution(numbers)
|
||||
|
||||
answer = await msg.waitNextMessage(msg.locale.t('game.twenty_four.message', numbers=numbers))
|
||||
answer = await msg.waitNextMessage(msg.locale.t('twenty_four.message', numbers=numbers))
|
||||
expression = answer.asDisplay(text_only=True)
|
||||
if play_state[msg.target.targetId]['active']:
|
||||
if expression.lower() in no_solution:
|
||||
if has_solution_flag:
|
||||
await answer.sendMessage(msg.locale.t('game.twenty_four.message.incorrect.have_solution'))
|
||||
await answer.sendMessage(msg.locale.t('twenty_four.message.incorrect.have_solution'))
|
||||
else:
|
||||
await answer.sendMessage(msg.locale.t('game.message.correct'))
|
||||
await answer.sendMessage(msg.locale.t('twenty_four.message.correct'))
|
||||
elif is_valid(expression):
|
||||
result = calc(expression)
|
||||
if result == 24 and contains_all_numbers(expression, numbers):
|
||||
await answer.sendMessage(msg.locale.t('game.message.correct'))
|
||||
await answer.sendMessage(msg.locale.t('twenty_four.message.correct'))
|
||||
else:
|
||||
await answer.sendMessage(msg.locale.t('game.message.incorrect'))
|
||||
await answer.sendMessage(msg.locale.t('twenty_four.message.incorrect'))
|
||||
else:
|
||||
await answer.sendMessage(msg.locale.t('game.twenty_four.message.incorrect.expression_invalid'))
|
||||
await answer.sendMessage(msg.locale.t('twenty_four.message.incorrect.error'))
|
||||
play_state[msg.target.targetId]['active'] = False
|
||||
|
||||
|
||||
|
||||
@tf.command('stop {{twenty_four.stop.help}}')
|
||||
async def s(msg: Bot.MessageSession):
|
||||
state = play_state.get(msg.target.targetId, False)
|
||||
if state:
|
||||
if state['active']:
|
||||
play_state[msg.target.targetId]['active'] = False
|
||||
await msg.sendMessage(msg.locale.t('twenty_four.stop.message'))
|
||||
else:
|
||||
await msg.sendMessage(msg.locale.t('twenty_four.stop.message.none'))
|
||||
else:
|
||||
await msg.sendMessage(msg.locale.t('twenty_four.stop.message.none'))
|
13
modules/twenty_four/locales/en_us.json
Normal file
13
modules/twenty_four/locales/en_us.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"twenty_four.help": "开始新游戏。",
|
||||
"twenty_four.help.desc": "24 点小游戏。",
|
||||
"twenty_four.message": "给出的数字组合:${numbers}\n请输入表达式使其结果为 24。(若无解,请输入“无解”)",
|
||||
"twenty_four.message.correct": "回答正确。",
|
||||
"twenty_four.message.incorrect.have_solution": "回答错误:该组合存在解。",
|
||||
"twenty_four.message.incorrect.error": "回答错误:表达式无效。",
|
||||
"twenty_four.message.incorrect": "回答错误。",
|
||||
"twenty_four.message.running": "当前有一局游戏正在进行中。",
|
||||
"twenty_four.stop.help": "停止当前的游戏。",
|
||||
"twenty_four.stop.message": "已停止。",
|
||||
"twenty_four.stop.message.none": "当前没有游戏正在进行。"
|
||||
}
|
13
modules/twenty_four/locales/zh_cn.json
Normal file
13
modules/twenty_four/locales/zh_cn.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"twenty_four.help": "开始新游戏。",
|
||||
"twenty_four.help.desc": "24 点小游戏。",
|
||||
"twenty_four.message": "给出的数字组合:${numbers}\n请输入表达式使其结果为 24。(若无解,请输入“无解”)",
|
||||
"twenty_four.message.correct": "回答正确。",
|
||||
"twenty_four.message.incorrect.have_solution": "回答错误:该组合存在解。",
|
||||
"twenty_four.message.incorrect.error": "回答错误:表达式无效。",
|
||||
"twenty_four.message.incorrect": "回答错误。",
|
||||
"twenty_four.message.running": "当前有一局游戏正在进行中。",
|
||||
"twenty_four.stop.help": "停止当前的游戏。",
|
||||
"twenty_four.stop.message": "已停止。",
|
||||
"twenty_four.stop.message.none": "当前没有游戏正在进行。"
|
||||
}
|
13
modules/twenty_four/locales/zh_tw.json
Normal file
13
modules/twenty_four/locales/zh_tw.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"twenty_four.help": "開始新遊戲。",
|
||||
"twenty_four.help.desc": "24 點小遊戲。",
|
||||
"twenty_four.message": "給出的數字組合:${numbers}\n請輸入運算式使其結果為 24。(若無解,請輸入「無解」)",
|
||||
"twenty_four.message.correct": "回答正確。",
|
||||
"twenty_four.message.incorrect.have_solution": "回答錯誤:該組合存在解。",
|
||||
"twenty_four.message.incorrect.error": "回答錯誤:運算式無效。",
|
||||
"twenty_four.message.incorrect": "回答錯誤。",
|
||||
"twenty_four.message.running": "目前有一局遊戲正在進行。",
|
||||
"twenty_four.stop.help": "停止目前的遊戲。",
|
||||
"twenty_four.stop.message": "已停止。",
|
||||
"twenty_four.stop.message.none": "目前沒有遊戲正在進行。"
|
||||
}
|
Reference in a new issue