瀏覽代碼

fix(server): Convert to string 'false' to True sometime

huangrunheng 2 年之前
父節點
當前提交
eb31c17a20
共有 2 個文件被更改,包括 8 次插入 和 2 次删除
  1. 2 2
      module/config/config_model.py
  2. 6 0
      module/server/script_router.py

+ 2 - 2
module/config/config_model.py

@@ -365,8 +365,8 @@ class ConfigModel(ConfigBase):
         task_object = getattr(self, task, None)
         group_object = getattr(task_object, group, None)
         argument_object = getattr(group_object, argument, None)
-        print(group_object)
-        print(argument_object)
+        # print(group_object)
+        # print(argument_object)
 
         if argument_object is None:
             logger.error(f'Set arg {task}.{group}.{argument}.{value} failed')

+ 6 - 0
module/server/script_router.py

@@ -79,6 +79,12 @@ async def script_task(script_name: str, task: str, group: str, argument: str, ty
             case 'number':
                 value = float(value)
             case 'boolean':
+                if isinstance(value, str):
+                    logger.warning(f'[{script_name}] script argument {argument} value is string, try to convert to bool')
+                    if value.lower() in ['true', '1']:
+                        value = True
+                    elif value.lower() in ['false', '0']:
+                        value = False
                 value = bool(value)
             case 'string':
                 pass