Skip to content

Commit e781c5e

Browse files
committed
chore: ruff check --fix --select ALL
1 parent 574e508 commit e781c5e

233 files changed

Lines changed: 1856 additions & 1839 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

astrbot/api/event/filter/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@
5555
"on_decorating_result",
5656
"on_llm_request",
5757
"on_llm_response",
58+
"on_llm_tool_respond",
59+
"on_platform_loaded",
5860
"on_plugin_error",
5961
"on_plugin_loaded",
6062
"on_plugin_unloaded",
61-
"on_platform_loaded",
63+
"on_using_llm_tool",
6264
"on_waiting_llm_request",
6365
"permission_type",
6466
"platform_adapter_type",
6567
"regex",
66-
"on_using_llm_tool",
67-
"on_llm_tool_respond",
6868
]

astrbot/builtin_stars/astrbot/long_term_memory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ def cfg(self, event: AstrMessageEvent):
3232
max_cnt = 300
3333
image_caption_prompt = cfg["provider_settings"]["image_caption_prompt"]
3434
image_caption_provider_id = cfg["provider_ltm_settings"].get(
35-
"image_caption_provider_id"
35+
"image_caption_provider_id",
3636
)
3737
image_caption = cfg["provider_ltm_settings"]["image_caption"] and bool(
38-
image_caption_provider_id
38+
image_caption_provider_id,
3939
)
4040
active_reply = cfg["provider_ltm_settings"]["active_reply"]
4141
enable_active_reply = active_reply.get("enable", False)
@@ -126,7 +126,7 @@ async def handle_message(self, event: AstrMessageEvent) -> None:
126126
elif isinstance(comp, Image):
127127
if cfg["image_caption"]:
128128
try:
129-
url = comp.url if comp.url else comp.file
129+
url = comp.url or comp.file
130130
if not url:
131131
raise Exception("图片 URL 为空")
132132
caption = await self.get_image_caption(
@@ -172,15 +172,15 @@ async def on_req_llm(self, event: AstrMessageEvent, req: ProviderRequest) -> Non
172172
req.system_prompt += chats_str
173173

174174
async def after_req_llm(
175-
self, event: AstrMessageEvent, llm_resp: LLMResponse
175+
self, event: AstrMessageEvent, llm_resp: LLMResponse,
176176
) -> None:
177177
if event.unified_msg_origin not in self.session_chats:
178178
return
179179

180180
if llm_resp.completion_text:
181181
final_message = f"[You/{datetime.datetime.now().strftime('%H:%M:%S')}]: {llm_resp.completion_text}"
182182
logger.debug(
183-
f"Recorded AI response: {event.unified_msg_origin} | {final_message}"
183+
f"Recorded AI response: {event.unified_msg_origin} | {final_message}",
184184
)
185185
self.session_chats[event.unified_msg_origin].append(final_message)
186186
cfg = self.cfg(event)

astrbot/builtin_stars/astrbot/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def on_message(self, event: AstrMessageEvent):
8686

8787
@filter.on_llm_request()
8888
async def decorate_llm_req(
89-
self, event: AstrMessageEvent, req: ProviderRequest
89+
self, event: AstrMessageEvent, req: ProviderRequest,
9090
) -> None:
9191
"""在请求 LLM 前注入人格信息、Identifier、时间、回复内容等 System Prompt"""
9292
if self.ltm and self.ltm_enabled(event):
@@ -97,7 +97,7 @@ async def decorate_llm_req(
9797

9898
@filter.on_llm_response()
9999
async def record_llm_resp_to_ltm(
100-
self, event: AstrMessageEvent, resp: LLMResponse
100+
self, event: AstrMessageEvent, resp: LLMResponse,
101101
) -> None:
102102
"""在 LLM 响应后记录对话"""
103103
if self.ltm and self.ltm_enabled(event):

astrbot/builtin_stars/builtin_commands/commands/conversation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ async def stop(self, message: AstrMessageEvent) -> None:
124124
if stopped_count > 0:
125125
message.set_result(
126126
MessageEventResult().message(
127-
f"已请求停止 {stopped_count} 个运行中的任务。"
128-
)
127+
f"已请求停止 {stopped_count} 个运行中的任务。",
128+
),
129129
)
130130
return
131131

@@ -207,7 +207,7 @@ async def convs(self, message: AstrMessageEvent, page: int = 1) -> None:
207207
"""生成所有对话的标题字典"""
208208
_titles = {}
209209
for conv in conversations_all:
210-
title = conv.title if conv.title else "新对话"
210+
title = conv.title or "新对话"
211211
_titles[conv.cid] = title
212212

213213
"""遍历分页后的对话生成列表显示"""
@@ -237,7 +237,7 @@ async def convs(self, message: AstrMessageEvent, page: int = 1) -> None:
237237

238238
title = _titles.get(conv.cid, "新对话")
239239
parts.append(
240-
f"{global_index}. {title}({conv.cid[:4]})\n 人格情景: {persona_name}\n 上次更新: {datetime.datetime.fromtimestamp(conv.updated_at).strftime('%m-%d %H:%M')}\n"
240+
f"{global_index}. {title}({conv.cid[:4]})\n 人格情景: {persona_name}\n 上次更新: {datetime.datetime.fromtimestamp(conv.updated_at).strftime('%m-%d %H:%M')}\n",
241241
)
242242
global_index += 1
243243

@@ -349,7 +349,7 @@ async def switch_conv(
349349
)
350350
else:
351351
conversation = conversations[index - 1]
352-
title = conversation.title if conversation.title else "新对话"
352+
title = conversation.title or "新对话"
353353
await self.context.conversation_manager.switch_conversation(
354354
message.unified_msg_origin,
355355
conversation.cid,

astrbot/builtin_stars/builtin_commands/commands/help.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ async def _query_astrbot_notice(self):
2323
return ""
2424

2525
async def _build_reserved_command_lines(self) -> list[str]:
26-
"""
27-
使用实时指令配置生成内置指令清单,确保重命名/禁用后与实际生效状态保持一致。
26+
"""使用实时指令配置生成内置指令清单,确保重命名/禁用后与实际生效状态保持一致。
2827
"""
2928
try:
3029
commands = await command_management.list_commands()

astrbot/builtin_stars/builtin_commands/commands/persona.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _build_tree_output(
4545
children,
4646
all_personas,
4747
depth + 1,
48-
)
48+
),
4949
)
5050

5151
return lines
@@ -100,7 +100,7 @@ async def persona(self, message: AstrMessageEvent) -> None:
100100
if force_applied_persona_id:
101101
curr_persona_name = f"{curr_persona_name} (自定义规则)"
102102

103-
curr_cid_title = conv.title if conv.title else "新对话"
103+
curr_cid_title = conv.title or "新对话"
104104
curr_cid_title += f"({cid[:4]})"
105105

106106
if len(l) == 1:

astrbot/builtin_stars/builtin_commands/commands/provider.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def get(self, provider_id: str, umo: str | None, ttl: float) -> list[str] | None
4848
return models
4949

5050
def set(
51-
self, provider_id: str, umo: str | None, models: list[str], ttl: float
51+
self, provider_id: str, umo: str | None, models: list[str], ttl: float,
5252
) -> None:
5353
if ttl <= 0:
5454
return
@@ -67,7 +67,7 @@ def _evict_if_needed(self) -> None:
6767
self._store.pop(key, None)
6868

6969
def invalidate(
70-
self, provider_id: str | None = None, *, umo: str | None = None
70+
self, provider_id: str | None = None, *, umo: str | None = None,
7171
) -> None:
7272
if provider_id is None:
7373
self._store.clear()
@@ -106,7 +106,7 @@ def _register_provider_change_hook(self) -> None:
106106
register_change_hook(self._on_provider_manager_changed)
107107

108108
def invalidate_provider_models_cache(
109-
self, provider_id: str | None = None, *, umo: str | None = None
109+
self, provider_id: str | None = None, *, umo: str | None = None,
110110
) -> None:
111111
"""Public hook for cache invalidation on external provider config changes."""
112112
self._model_cache.invalidate(provider_id, umo=umo)
@@ -198,14 +198,14 @@ def _resolve_model_name(
198198
for candidate in models:
199199
cand_norm = candidate.casefold()
200200
if cand_norm.endswith(f"/{requested_norm}") or cand_norm.endswith(
201-
f":{requested_norm}"
201+
f":{requested_norm}",
202202
):
203203
return candidate
204204

205205
return None
206206

207207
def _apply_model(
208-
self, prov: Provider, model_name: str, *, umo: str | None = None
208+
self, prov: Provider, model_name: str, *, umo: str | None = None,
209209
) -> str:
210210
prov.set_model(model_name)
211211
self.invalidate_provider_models_cache(prov.meta().id, umo=umo)
@@ -287,7 +287,7 @@ async def _test_provider_capability(self, provider):
287287
err_code = "TEST_FAILED"
288288
err_reason = safe_error("", e)
289289
self._log_reachability_failure(
290-
provider, provider_capability_type, err_code, err_reason
290+
provider, provider_capability_type, err_code, err_reason,
291291
)
292292
return False, err_code, err_reason
293293

@@ -339,7 +339,7 @@ async def fetch_models(
339339
return provider, None, err
340340

341341
results = await asyncio.gather(
342-
*(fetch_models(provider) for provider in all_providers)
342+
*(fetch_models(provider) for provider in all_providers),
343343
)
344344
failed_provider_errors: list[tuple[str, str]] = []
345345
for provider, models, err in results:
@@ -405,8 +405,8 @@ async def provider(
405405
if all_providers:
406406
await event.send(
407407
MessageEventResult().message(
408-
"正在进行提供商可达性测试,请稍候..."
409-
)
408+
"正在进行提供商可达性测试,请稍候...",
409+
),
410410
)
411411
check_results = await asyncio.gather(
412412
*[self._test_provider_capability(p) for p, _ in all_providers],
@@ -463,7 +463,7 @@ async def provider(
463463
"info": info,
464464
"mark": mark,
465465
"provider": p,
466-
}
466+
},
467467
)
468468

469469
# 分组输出
@@ -558,7 +558,7 @@ async def provider(
558558
event.set_result(MessageEventResult().message("无效的参数。"))
559559

560560
async def _switch_model_by_name(
561-
self, message: AstrMessageEvent, model_name: str, prov: Provider
561+
self, message: AstrMessageEvent, model_name: str, prov: Provider,
562562
) -> None:
563563
model_name = model_name.strip()
564564
if not model_name:
@@ -583,7 +583,7 @@ async def _switch_model_by_name(
583583
if matched_model_name is not None:
584584
message.set_result(
585585
MessageEventResult().message(
586-
self._apply_model(prov, matched_model_name, umo=umo)
586+
self._apply_model(prov, matched_model_name, umo=umo),
587587
),
588588
)
589589
return
@@ -620,7 +620,7 @@ async def _switch_model_by_name(
620620
except Exception as e:
621621
message.set_result(
622622
MessageEventResult().message(
623-
safe_error("跨提供商切换并设置模型失败: ", e)
623+
safe_error("跨提供商切换并设置模型失败: ", e),
624624
),
625625
)
626626

@@ -655,7 +655,7 @@ async def model_ls(
655655
curr_model = prov.get_model() or "无"
656656
parts.append(f"\n当前模型: [{curr_model}]")
657657
parts.append(
658-
"\nTips: 使用 /model <模型名/编号> 切换模型。输入模型名时可自动跨提供商查找并切换;跨提供商也可使用 /provider 切换。"
658+
"\nTips: 使用 /model <模型名/编号> 切换模型。输入模型名时可自动跨提供商查找并切换;跨提供商也可使用 /provider 切换。",
659659
)
660660

661661
ret = "".join(parts)
@@ -680,13 +680,13 @@ async def model_ls(
680680
prov,
681681
new_model,
682682
umo=message.unified_msg_origin,
683-
)
683+
),
684684
),
685685
)
686686
except Exception as e:
687687
message.set_result(
688688
MessageEventResult().message(
689-
safe_error("切换模型未知错误: ", e)
689+
safe_error("切换模型未知错误: ", e),
690690
),
691691
)
692692
return
@@ -730,7 +730,7 @@ async def key(self, message: AstrMessageEvent, index: int | None = None) -> None
730730
except Exception as e:
731731
message.set_result(
732732
MessageEventResult().message(
733-
safe_error("切换 Key 未知错误: ", e)
733+
safe_error("切换 Key 未知错误: ", e),
734734
),
735735
)
736736
return

astrbot/builtin_stars/builtin_commands/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ async def groupnew_conv(self, message: AstrMessageEvent, sid: str) -> None:
170170

171171
@filter.command("switch")
172172
async def switch_conv(
173-
self, message: AstrMessageEvent, index: int | None = None
173+
self, message: AstrMessageEvent, index: int | None = None,
174174
) -> None:
175175
"""通过 /ls 前面的序号切换对话"""
176176
await self.conversation_c.switch_conv(message, index)

astrbot/cli/commands/cmd_conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def _validate_timezone(value: str) -> str:
5050
zoneinfo.ZoneInfo(value)
5151
except Exception:
5252
raise click.ClickException(
53-
f"Invalid timezone: {value}. Please use a valid IANA timezone name"
53+
f"Invalid timezone: {value}. Please use a valid IANA timezone name",
5454
)
5555
return value
5656

@@ -59,7 +59,7 @@ def _validate_callback_api_base(value: str) -> str:
5959
"""Validate callback API base URL"""
6060
if not value.startswith("http://") and not value.startswith("https://"):
6161
raise click.ClickException(
62-
"Callback API base must start with http:// or https://"
62+
"Callback API base must start with http:// or https://",
6363
)
6464
return value
6565

astrbot/cli/commands/cmd_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def init() -> None:
4848
click.echo("Done! You can now run 'astrbot run' to start AstrBot")
4949
except Timeout:
5050
raise click.ClickException(
51-
"Cannot acquire lock file. Please check if another instance is running"
51+
"Cannot acquire lock file. Please check if another instance is running",
5252
)
5353

5454
except Exception as e:

0 commit comments

Comments
 (0)