Skip to content

Commit

Permalink
feat: config.json 支持更多配置选项
Browse files Browse the repository at this point in the history
  • Loading branch information
hanxi committed Jun 30, 2024
1 parent d6c2078 commit 2094595
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 5 additions & 1 deletion config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@
"use_music_api": false,
"log_file": "/tmp/xiaomusic.txt",
"fuzzy_match_cutoff": 0.6,
"enable_fuzzy_match": true
"enable_fuzzy_match": true,
"stop_tts_msg": "收到,再见",
"keywords_playlocal": "播放本地歌曲,本地播放歌曲",
"keywords_play": "播放歌曲,放歌曲",
"keywords_stop": "关机,暂停,停止,停止播放"
}
17 changes: 9 additions & 8 deletions xiaomusic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ class Config:
)
stop_tts_msg: str = os.getenv("XIAOMUSIC_STOP_TTS_MSG", "收到,再见")

keywords_playlocal: str = os.getenv(
"XIAOMUSIC_KEYWORDS_PLAYLOCAL", "播放本地歌曲,本地播放歌曲"
)
keywords_play: str = os.getenv("XIAOMUSIC_KEYWORDS_PLAY", "播放歌曲,放歌曲")
keywords_stop: str = os.getenv("XIAOMUSIC_KEYWORDS_STOP", "关机,暂停,停止,停止播放")

def append_keyword(self, keys, action):
for key in keys.split(","):
self.key_word_dict[key] = action
Expand All @@ -99,14 +105,9 @@ def append_keyword(self, keys, action):
def __post_init__(self) -> None:
if self.proxy:
validate_proxy(self.proxy)
keywords_playlocal = os.getenv(
"XIAOMUSIC_KEYWORDS_PLAYLOCAL", "播放本地歌曲,本地播放歌曲"
)
self.append_keyword(keywords_playlocal, "playlocal")
keywords_play = os.getenv("XIAOMUSIC_KEYWORDS_PLAY", "播放歌曲,放歌曲")
self.append_keyword(keywords_play, "play")
keywords_stop = os.getenv("XIAOMUSIC_KEYWORDS_STOP", "关机,暂停,停止,停止播放")
self.append_keyword(keywords_stop, "stop")
self.append_keyword(self.keywords_playlocal, "playlocal")
self.append_keyword(self.keywords_play, "play")
self.append_keyword(self.keywords_stop, "stop")

# 保存配置到 config-example.json 文件
# with open("config-example.json", "w") as f:
Expand Down

0 comments on commit 2094595

Please sign in to comment.