Skip to content

Commit c3391d7

Browse files
committed
Fix(config): Automatically add new plugins to user configs
The configuration migration logic has been updated to be more robust. Previously, the migration only handled renaming specific, hardcoded plugin keys. It did not add entirely new plugins to existing user configuration files, which could cause issues when new features are introduced. This change modifies the logic to iterate through the default plugin list and add any missing plugins to a user's configuration with their default status. This ensures that all user configs are kept up-to-date and compatible with the latest version. The project version has been bumped to 1.0.8 to reflect this fix. ```.
1 parent 0aa0bd8 commit c3391d7

2 files changed

Lines changed: 4 additions & 14 deletions

File tree

config.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,6 @@ def load_all_configs(self):
193193
if not os.path.exists(CONFIG_DIR):
194194
return
195195

196-
# 定义旧键名到新键名的映射关系 old_key -> new_key
197-
key_mapping = {
198-
"SEARCH": "get_search_results",
199-
"URL": "get_url_content",
200-
"ARXIV": "download_read_arxiv_pdf",
201-
"CODE": "run_python_script",
202-
"IMAGE": "generate_image",
203-
"get_date_time_weekday": "get_time"
204-
}
205-
206196
for filename in os.listdir(CONFIG_DIR):
207197
if filename.endswith('.json'):
208198
user_id = filename[:-5] # 移除 '.json' 后缀
@@ -211,9 +201,9 @@ def load_all_configs(self):
211201

212202
# 检查并进行键名映射转换
213203
updated_config = False
214-
for old_key, new_key in key_mapping.items():
215-
if old_key in user_config:
216-
user_config[new_key] = user_config.pop(old_key)
204+
for new_plugin, status in self.plugins.items():
205+
if new_plugin not in user_config:
206+
user_config[new_plugin] = status
217207
updated_config = True
218208

219209
# 如果配置有更新,保存回文件

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "chatgpt-telegram-bot"
3-
version = "1.0.7"
3+
version = "1.0.8"
44
description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.11"

0 commit comments

Comments
 (0)