Skip to content

Commit fc5386f

Browse files
committed
✨ command config nickname
1 parent bdbb37b commit fc5386f

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎arclet/entari/command/provider.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import inspect
3+
import re
34
from typing import Any, Literal, Union, get_args
45

56
from arclet.alconna import Alconna, Arparma, Duplication, Empty, output_manager
@@ -36,10 +37,19 @@ def _is_optional(annotation: Any) -> bool:
3637

3738

3839
def _remove_config_prefix(message: MessageChain):
39-
if not (command_prefix := EntariConfig.instance.basic.prefix):
40+
command_prefix = EntariConfig.instance.basic.prefix
41+
nickname = EntariConfig.instance.basic.nickname
42+
if not command_prefix and not nickname:
4043
return message
4144
if message and isinstance(message[0], Text):
4245
text = message[0].text.lstrip()
46+
if nickname:
47+
if not (mat := re.match(rf"^@?{re.escape(nickname)}[,,:\s]+", text)):
48+
return MessageChain()
49+
text = text[mat.end() :]
50+
message[0] = Text(text)
51+
if not command_prefix:
52+
return message
4353
for prefix in command_prefix:
4454
if not prefix:
4555
return message

‎arclet/entari/config/model.py‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,15 @@ class BasicConfig(BasicConfModel):
6161
default=False, description="Whether skip Event Handler if requirement is missing"
6262
)
6363
log: LogInfo = model_field(default_factory=LogInfo, description="Log configuration")
64-
log_level: int | str | None = model_field(default=None, description="[Deprecated] Log level for the application")
65-
log_ignores: list[str] | None = model_field(
66-
default=None, description="[Deprecated] Log ignores for the application"
67-
)
6864
prefix: list[str] = model_field(default_factory=list, description="Command prefix for the application")
65+
nickname: str = model_field(default="", description="Bot nickname for the application (used in command matching)")
6966
cmd_count: int = model_field(default=4096, description="Command count limit for the application")
7067
external_dirs: list[str] = model_field(default_factory=list, description="External directories to look for plugins")
7168
schema: bool = model_field(
7269
default=False, description="Whether generate JSON schema for the configuration (after application start)"
7370
)
7471

7572
def __post_init__(self):
76-
if self.log_level is not None:
77-
self.log.level = self.log_level
78-
if self.log_ignores is not None:
79-
self.log.ignores = self.log_ignores
8073
if self.prefix.count(""):
8174
self.prefix = [p for p in self.prefix if p]
8275
self.prefix.append("")

‎arclet/entari/plugin/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import asyncio
22
import inspect
33
import itertools
4+
import os
45
import sys
56
from collections.abc import Awaitable, Callable
6-
from os import PathLike
77
from pathlib import Path
88
from typing import TYPE_CHECKING, Any, Literal, TypeVar, overload
99

@@ -214,7 +214,7 @@ def load_plugin(
214214
return
215215

216216

217-
def load_plugins(dir_: str | PathLike | Path):
217+
def load_plugins(dir_: str | os.PathLike | Path):
218218
"""加载指定目录下的所有插件"""
219219
path = dir_ if isinstance(dir_, Path) else Path(dir_)
220220
if not path.is_dir():

0 commit comments

Comments
 (0)