feat: 运行时原动态引入config的地方现在均使用初始化时导入的config对象

This commit is contained in:
Rock Chin
2023-01-04 17:09:57 +08:00
parent b318f6d4f0
commit 95ad911a6c
8 changed files with 59 additions and 20 deletions
+3 -1
View File
@@ -5,7 +5,6 @@ import logging
import pkg.database.manager
import pkg.qqbot.manager
import pkg.utils.context
import config
class KeysManager:
@@ -34,6 +33,8 @@ class KeysManager:
def __init__(self, api_key):
# if hasattr(config, 'api_key_usage_threshold'):
# self.api_key_usage_threshold = config.api_key_usage_threshold
config = pkg.utils.context.get_config()
if hasattr(config, 'api_key_fee_threshold'):
self.api_key_fee_threshold = config.api_key_fee_threshold
self.load_fee()
@@ -108,6 +109,7 @@ class KeysManager:
self.fee[md5] += fee
config = pkg.utils.context.get_config()
if self.fee[md5] >= self.api_key_fee_threshold and \
hasattr(config, 'auto_switch_api_key') and config.auto_switch_api_key:
switch_result, key_name = self.auto_switch()