style: introduce ruff as linter and formatter (#1356)

* style: remove necessary imports

* style: fix F841

* style: fix F401

* style: fix F811

* style: fix E402

* style: fix E721

* style: fix E722

* style: fix E722

* style: fix F541

* style: ruff format

* style: all passed

* style: add ruff in deps

* style: more ignores in ruff.toml

* style: add pre-commit
This commit is contained in:
Junyan Qin (Chin)
2025-04-29 17:24:07 +08:00
committed by GitHub
parent 09e70d70e9
commit 209f16af76
240 changed files with 5307 additions and 4689 deletions

View File

@@ -1,15 +1,13 @@
from __future__ import annotations
import re
from .. import stage, entities
from ...core import entities as core_entities
from ...config import manager as cfg_mgr
@stage.stage_class('BanSessionCheckStage')
class BanSessionCheckStage(stage.PipelineStage):
"""访问控制处理阶段
仅检查query中群号或个人号是否在访问控制列表中。
"""
@@ -17,26 +15,24 @@ class BanSessionCheckStage(stage.PipelineStage):
pass
async def process(
self,
query: core_entities.Query,
stage_inst_name: str
self, query: core_entities.Query, stage_inst_name: str
) -> entities.StageProcessResult:
found = False
mode = query.pipeline_config['trigger']['access-control']['mode']
sess_list = query.pipeline_config['trigger']['access-control'][mode]
if (query.launcher_type.value == 'group' and 'group_*' in sess_list) \
or (query.launcher_type.value == 'person' and 'person_*' in sess_list):
if (query.launcher_type.value == 'group' and 'group_*' in sess_list) or (
query.launcher_type.value == 'person' and 'person_*' in sess_list
):
found = True
else:
for sess in sess_list:
if sess == f"{query.launcher_type.value}_{query.launcher_id}":
if sess == f'{query.launcher_type.value}_{query.launcher_id}':
found = True
break
ctn = False
if mode == 'whitelist':
@@ -45,7 +41,11 @@ class BanSessionCheckStage(stage.PipelineStage):
ctn = not found
return entities.StageProcessResult(
result_type=entities.ResultType.CONTINUE if ctn else entities.ResultType.INTERRUPT,
result_type=entities.ResultType.CONTINUE
if ctn
else entities.ResultType.INTERRUPT,
new_query=query,
console_notice=f'根据访问控制忽略消息: {query.launcher_type.value}_{query.launcher_id}' if not ctn else ''
console_notice=f'根据访问控制忽略消息: {query.launcher_type.value}_{query.launcher_id}'
if not ctn
else '',
)