fix wordle stop bug
This commit is contained in:
parent
521a471ea6
commit
c5154bf20d
4 changed files with 14 additions and 13 deletions
|
@ -90,7 +90,7 @@ async def get_target(target_id: str):
|
|||
'ban': ban,
|
||||
'typoCheck': typo_check,
|
||||
'diceDCReversed': dice_dc_reversed,
|
||||
'wordleDarkTheme': wordle_dark_theme
|
||||
'wordleDarkTheme': wordle_dark_theme,
|
||||
'wiki': {
|
||||
'fandomAddon': wiki_fandom_addon,
|
||||
'headers': wiki_headers,
|
||||
|
|
|
@ -213,7 +213,7 @@ async def config_modules(msg: Bot.MessageSession):
|
|||
modules='\n'.join(extra_reload_modules)), append_instruction=False)
|
||||
if not confirm:
|
||||
await msg.finish()
|
||||
unloaded_list = CFG.get('unloaded_modules')
|
||||
unloaded_list = Config('unloaded_modules')
|
||||
if unloaded_list and module_ in unloaded_list:
|
||||
unloaded_list.remove(module_)
|
||||
CFG.write('unloaded_modules', unloaded_list)
|
||||
|
@ -233,7 +233,7 @@ async def config_modules(msg: Bot.MessageSession):
|
|||
continue
|
||||
if ModulesManager.load_module(module_):
|
||||
msglist.append(msg.locale.t("core.message.module.load.success", module=module_))
|
||||
unloaded_list = CFG.get('unloaded_modules')
|
||||
unloaded_list = Config('unloaded_modules')
|
||||
if unloaded_list and module_ in unloaded_list:
|
||||
unloaded_list.remove(module_)
|
||||
CFG.write('unloaded_modules', unloaded_list)
|
||||
|
@ -250,7 +250,7 @@ async def config_modules(msg: Bot.MessageSession):
|
|||
if module_ not in modules_:
|
||||
if module_ in err_modules:
|
||||
if await msg.wait_confirm(msg.locale.t("core.message.module.unload.unavailable.confirm"), append_instruction=False):
|
||||
unloaded_list = CFG.get('unloaded_modules')
|
||||
unloaded_list = Config('unloaded_modules')
|
||||
if not unloaded_list:
|
||||
unloaded_list = []
|
||||
if module_ not in unloaded_list:
|
||||
|
@ -270,7 +270,7 @@ async def config_modules(msg: Bot.MessageSession):
|
|||
if await msg.wait_confirm(msg.locale.t("core.message.module.unload.confirm"), append_instruction=False):
|
||||
if ModulesManager.unload_module(module_):
|
||||
msglist.append(msg.locale.t("core.message.module.unload.success", module=module_))
|
||||
unloaded_list = CFG.get('unloaded_modules')
|
||||
unloaded_list = Config('unloaded_modules')
|
||||
if not unloaded_list:
|
||||
unloaded_list = []
|
||||
unloaded_list.append(module_)
|
||||
|
|
|
@ -489,6 +489,11 @@ def isint(num):
|
|||
return False
|
||||
|
||||
|
||||
@cfg_.command('get <k>')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
await msg.finish(Config(msg.parsed_msg['<k>']))
|
||||
|
||||
|
||||
@cfg_.command('write <k> <v> [-s]')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
value = msg.parsed_msg['<v>']
|
||||
|
|
|
@ -177,9 +177,6 @@ class WordleBoardImage:
|
|||
def save_image(self, filename):
|
||||
self.image.save(filename)
|
||||
|
||||
def create_wordle_board():
|
||||
wordle_board = WordleBoard.from_random_word()
|
||||
return wordle_board
|
||||
|
||||
@wordle.command('{{wordle.help}}')
|
||||
async def _(msg: Bot.MessageSession):
|
||||
|
@ -192,11 +189,12 @@ async def _(msg: Bot.MessageSession):
|
|||
c = qc.check(30)
|
||||
|
||||
if c == 0:
|
||||
play_state.update({msg.target.target_id: {'active': True}})
|
||||
board = create_wordle_board()
|
||||
board = WordleBoard.from_random_word()
|
||||
board_image = WordleBoardImage(msg.data.options.get('wordle_dark_theme'))
|
||||
path = os.path.join(Config('cache_path'), f'{msg.session.target}_wordle_board.png')
|
||||
board_image.save_image(path)
|
||||
play_state.update({msg.target.target_id: {'active': True}})
|
||||
play_state.update({msg.target.target_id: {'answer': board.word}})
|
||||
Logger.info(f'Answer: {board.word}')
|
||||
await msg.send_message([BImage(path), Plain(msg.locale.t('wordle.message.start'))])
|
||||
|
||||
|
@ -236,16 +234,14 @@ async def _(msg: Bot.MessageSession):
|
|||
|
||||
@wordle.command('stop {{game.help.stop}}')
|
||||
async def terminate(msg: Bot.MessageSession):
|
||||
board = create_wordle_board()
|
||||
qc = CoolDown('wordle', msg, all=True)
|
||||
state = play_state.get(msg.target.target_id, {}) # 尝试获取 play_state 中是否有此对象的游戏状态
|
||||
if state:
|
||||
if state['active']: # 检查是否为活跃状态
|
||||
play_state[msg.target.target_id]['active'] = False
|
||||
answer = board.word
|
||||
board.reset_board()
|
||||
qc.reset()
|
||||
await msg.finish(msg.locale.t('wordle.message.stop', answer=answer))
|
||||
await msg.finish(msg.locale.t('wordle.message.stop', answer=state['answer']))
|
||||
else:
|
||||
await msg.finish(msg.locale.t('game.message.stop.none'))
|
||||
else:
|
||||
|
|
Reference in a new issue