mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-02 03:55:55 +00:00
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:
committed by
GitHub
parent
09e70d70e9
commit
209f16af76
@@ -1,16 +1,18 @@
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
from ...core import app
|
||||
from . import entities as rule_entities, rule
|
||||
from .rules import atbot, prefix, regexp, random
|
||||
from . import rule
|
||||
|
||||
from .. import stage, entities
|
||||
from ...core import entities as core_entities
|
||||
from ...config import manager as cfg_mgr
|
||||
from ...utils import importutil
|
||||
|
||||
from . import rules
|
||||
|
||||
importutil.import_modules_in_pkg(rules)
|
||||
|
||||
|
||||
@stage.stage_class("GroupRespondRuleCheckStage")
|
||||
@stage.stage_class('GroupRespondRuleCheckStage')
|
||||
class GroupRespondRuleCheckStage(stage.PipelineStage):
|
||||
"""群组响应规则检查器
|
||||
|
||||
@@ -21,8 +23,7 @@ class GroupRespondRuleCheckStage(stage.PipelineStage):
|
||||
"""检查器实例"""
|
||||
|
||||
async def initialize(self, pipeline_config: dict):
|
||||
"""初始化检查器
|
||||
"""
|
||||
"""初始化检查器"""
|
||||
|
||||
self.rule_matchers = []
|
||||
|
||||
@@ -31,12 +32,12 @@ class GroupRespondRuleCheckStage(stage.PipelineStage):
|
||||
await rule_inst.initialize()
|
||||
self.rule_matchers.append(rule_inst)
|
||||
|
||||
async def process(self, query: core_entities.Query, stage_inst_name: str) -> entities.StageProcessResult:
|
||||
|
||||
async def process(
|
||||
self, query: core_entities.Query, stage_inst_name: str
|
||||
) -> entities.StageProcessResult:
|
||||
if query.launcher_type.value != 'group': # 只处理群消息
|
||||
return entities.StageProcessResult(
|
||||
result_type=entities.ResultType.CONTINUE,
|
||||
new_query=query
|
||||
result_type=entities.ResultType.CONTINUE, new_query=query
|
||||
)
|
||||
|
||||
rules = query.pipeline_config['trigger']['group-respond-rules']
|
||||
@@ -48,7 +49,9 @@ class GroupRespondRuleCheckStage(stage.PipelineStage):
|
||||
# use_rule = rules[str(query.launcher_id)]
|
||||
|
||||
for rule_matcher in self.rule_matchers: # 任意一个匹配就放行
|
||||
res = await rule_matcher.match(str(query.message_chain), query.message_chain, use_rule, query)
|
||||
res = await rule_matcher.match(
|
||||
str(query.message_chain), query.message_chain, use_rule, query
|
||||
)
|
||||
if res.matching:
|
||||
query.message_chain = res.replacement
|
||||
|
||||
@@ -56,8 +59,7 @@ class GroupRespondRuleCheckStage(stage.PipelineStage):
|
||||
result_type=entities.ResultType.CONTINUE,
|
||||
new_query=query,
|
||||
)
|
||||
|
||||
|
||||
return entities.StageProcessResult(
|
||||
result_type=entities.ResultType.INTERRUPT,
|
||||
new_query=query
|
||||
result_type=entities.ResultType.INTERRUPT, new_query=query
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user