From af6077693e23b3c308fcf6a45ef79b8273e8d48a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B6=B5=E6=9B=A6?= Date: Thu, 18 Jul 2024 01:52:04 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E8=AF=AD=E9=9F=B3=E5=8F=A3=E4=BB=A4=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xiaomusic/config.py | 14 ++++++++------ xiaomusic/xiaomusic.py | 11 ++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/xiaomusic/config.py b/xiaomusic/config.py index 11ba665..0744369 100644 --- a/xiaomusic/config.py +++ b/xiaomusic/config.py @@ -145,16 +145,17 @@ class Config: self.key_word_dict[k] = v self.key_match_order.append(k) + def init_keyword(self): + self.append_keyword(self.keywords_playlocal, "playlocal") + self.append_keyword(self.keywords_play, "play") + self.append_keyword(self.keywords_stop, "stop") + self.append_user_keyword() + def __post_init__(self) -> None: if self.proxy: validate_proxy(self.proxy) - self.append_keyword(self.keywords_playlocal, "playlocal") - self.append_keyword(self.keywords_play, "play") - self.append_keyword(self.keywords_stop, "stop") - - self.append_user_keyword() - + self.init_keyword() # 保存配置到 config-example.json 文件 if self.enable_config_example: with open("config-example.json", "w") as f: @@ -211,3 +212,4 @@ class Config: converted_value = self.convert_value(k, v, type_hints) if converted_value is not None: setattr(self, k, converted_value) + self.init_keyword() diff --git a/xiaomusic/xiaomusic.py b/xiaomusic/xiaomusic.py index 3b9dc15..ba33793 100644 --- a/xiaomusic/xiaomusic.py +++ b/xiaomusic/xiaomusic.py @@ -468,13 +468,6 @@ class XiaoMusic: await self.init_all_data(session) task = asyncio.create_task(self.poll_latest_ask()) assert task is not None # to keep the reference to task, do not remove this - filtered_keywords = [ - keyword for keyword in self.config.key_match_order if "#" not in keyword - ] - joined_keywords = "/".join(filtered_keywords) - self.log.info(f"语音控制已启动, 用【{joined_keywords}】开头来控制") - self.log.debug(f"key_word_dict: {self.config.key_word_dict}") - while True: self.polling_event.set() await self.new_record_event.wait() @@ -761,6 +754,10 @@ class XiaoMusic: debug_config = deepcopy_data_no_sensitive_info(self.config) self.log.info(f"update_config_from_setting ok. data:{debug_config}") + joined_keywords = "/".join(self.config.key_match_order) + self.log.info(f"语音控制已启动, 用【{joined_keywords}】开头来控制") + self.log.debug(f"key_word_dict: {self.config.key_word_dict}") + # 重新初始化 async def reinit(self, **kwargs): self.setup_logger()