summaryrefslogtreecommitdiff
path: root/ATRI
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2021-12-16 23:31:09 +0800
committerKyomotoi <[email protected]>2021-12-16 23:31:09 +0800
commit8fa1bd7c01c3f284324a6623be4bed47510522f1 (patch)
tree2b57304c0e795672def48964c0283a576c65f907 /ATRI
parente5f382cdd51cd519445ebdc18b386ff98f6e9cfd (diff)
downloadATRI-8fa1bd7c01c3f284324a6623be4bed47510522f1.tar.gz
ATRI-8fa1bd7c01c3f284324a6623be4bed47510522f1.tar.bz2
ATRI-8fa1bd7c01c3f284324a6623be4bed47510522f1.zip
🚸⚡️ 优化帮助菜单
Diffstat (limited to 'ATRI')
-rw-r--r--ATRI/plugins/chat/__init__.py4
-rw-r--r--ATRI/plugins/essential.py13
-rw-r--r--ATRI/plugins/help/__init__.py6
-rw-r--r--ATRI/plugins/help/data_source.py6
-rw-r--r--ATRI/plugins/rich/__init__.py4
-rw-r--r--ATRI/plugins/setu/__init__.py2
-rw-r--r--ATRI/plugins/wife/__init__.py6
-rw-r--r--ATRI/service.py78
8 files changed, 55 insertions, 64 deletions
diff --git a/ATRI/plugins/chat/__init__.py b/ATRI/plugins/chat/__init__.py
index 723ee25..f401f3f 100644
--- a/ATRI/plugins/chat/__init__.py
+++ b/ATRI/plugins/chat/__init__.py
@@ -12,7 +12,7 @@ _chat_flmt = FreqLimiter(3)
_chat_flmt_notice = choice(["慢...慢一..点❤", "冷静1下", "歇会歇会~~", "我开始为你以后的伴侣担心了..."])
-chat = Chat().on_message("闲聊(文爱")
+chat = Chat().on_message("文爱", "闲聊(文爱")
@chat.handle()
@@ -31,7 +31,7 @@ async def _chat(bot: Bot, event: MessageEvent):
return
-my_name_is = Chat().on_command("叫我", "更改闲聊(划掉 文爱)时的称呼", aliases={"我是"}, priority=1)
+my_name_is = Chat().on_command("叫我", "更改闲聊(文爱)时的称呼", aliases={"我是"}, priority=1)
@my_name_is.args_parser # type: ignore
diff --git a/ATRI/plugins/essential.py b/ATRI/plugins/essential.py
index 09107d5..fb493a9 100644
--- a/ATRI/plugins/essential.py
+++ b/ATRI/plugins/essential.py
@@ -48,6 +48,7 @@ os.makedirs(TEMP_PATH, exist_ok=True)
@driver.on_startup
async def startup():
+ log.info(f"Now running: {ATRI.__version__}")
log.info("アトリは、高性能ですから!")
@@ -116,7 +117,7 @@ class Essential(Service):
Service.__init__(self, "基础部件", __doc__)
-friend_add_event = Essential().on_request("好友添加")
+friend_add_event = Essential().on_request("好友添加", "好友添加检测")
@friend_add_event.handle()
@@ -162,7 +163,7 @@ async def _friend_add(bot: Bot, event: FriendRequestEvent):
await bot.send_private_msg(user_id=superuser, message=repo)
-group_invite_event = Essential().on_request("邀请入群")
+group_invite_event = Essential().on_request("邀请入群", "被邀请入群检测")
@group_invite_event.handle()
@@ -208,7 +209,7 @@ async def _group_invite(bot: Bot, event: GroupRequestEvent):
await bot.send_private_msg(user_id=superuser, message=repo)
-group_member_event = Essential().on_notice("群成员变动")
+group_member_event = Essential().on_notice("群成员变动", "群成员变动检测")
@group_member_event.handle()
@@ -224,7 +225,7 @@ async def _group_member_left(bot: Bot, event: GroupDecreaseNoticeEvent):
await group_member_event.finish("呜——有人跑了...")
-group_admin_event = Essential().on_notice("群管理变动")
+group_admin_event = Essential().on_notice("群管理变动", "群管理变动检测")
@group_admin_event.handle()
@@ -238,7 +239,7 @@ async def _group_admin_event(bot: Bot, event: GroupAdminNoticeEvent):
)
-group_ban_event = Essential().on_notice("群禁言变动")
+group_ban_event = Essential().on_notice("群禁言变动", "群禁言变动检测")
@group_ban_event.handle()
@@ -260,7 +261,7 @@ async def _group_ban_event(bot: Bot, event: GroupBanNoticeEvent):
await bot.send_private_msg(user_id=int(superuser), message=msg)
-recall_event = Essential().on_notice("撤回事件")
+recall_event = Essential().on_notice("撤回事件", "撤回事件检测")
@recall_event.handle()
diff --git a/ATRI/plugins/help/__init__.py b/ATRI/plugins/help/__init__.py
index 339ffa2..1d1102e 100644
--- a/ATRI/plugins/help/__init__.py
+++ b/ATRI/plugins/help/__init__.py
@@ -5,9 +5,7 @@ from ATRI.rule import to_bot
from .data_source import Helper
-main_help = Helper().on_command(
- "菜单", "获取食用bot的方法", rule=to_bot(), aliases={"/help", "menu"}
-)
+main_help = Helper().on_command("菜单", "获取食用bot的方法", rule=to_bot(), aliases={"menu"})
@main_help.handle()
@@ -34,7 +32,7 @@ async def _service_list(bot: Bot, event: MessageEvent):
await service_list.finish(repo)
-service_info = Helper().on_command("帮助", "获取服务详细帮助", rule=to_bot())
+service_info = Helper().on_command("帮助", "获取服务详细帮助", aliases={"help"}, rule=to_bot())
@service_info.handle()
diff --git a/ATRI/plugins/help/data_source.py b/ATRI/plugins/help/data_source.py
index 638bee2..7b2f6f8 100644
--- a/ATRI/plugins/help/data_source.py
+++ b/ATRI/plugins/help/data_source.py
@@ -9,7 +9,7 @@ from ATRI.exceptions import ReadFileError
SERVICE_INFO_FORMAT = """
服务名:{service}
说明:{docs}
-可用命令:\n{cmd_list}
+可用命令:\n {cmd_list}
是否全局启用:{enabled}
Tip: 帮助 [服务] [命令] 以查看对应命令详细信息
""".strip()
@@ -60,7 +60,7 @@ class Helper(Service):
temp_list.append(service)
msg0 = "咱搭载了以下服务~\n"
- services = " | ".join(map(str, temp_list))
+ services = "、".join(map(str, temp_list))
msg0 = msg0 + services
repo = msg0 + "\n@ 帮助 [服务] -以查看对应服务帮助"
return repo
@@ -77,7 +77,7 @@ class Helper(Service):
service_enabled = data.get("enabled", True)
_service_cmd_list = list(data.get("cmd_list", {"error"}))
- service_cmd_list = "\n".join(map(str, _service_cmd_list))
+ service_cmd_list = "、".join(map(str, _service_cmd_list))
repo = SERVICE_INFO_FORMAT.format(
service=service_name,
diff --git a/ATRI/plugins/rich/__init__.py b/ATRI/plugins/rich/__init__.py
index b18ae51..bcd58f7 100644
--- a/ATRI/plugins/rich/__init__.py
+++ b/ATRI/plugins/rich/__init__.py
@@ -6,7 +6,7 @@ from .data_source import Rich
_rich_flmt = FreqLimiter(3)
-bili_rich = Rich().on_message("小程序爪巴", block=False)
+bili_rich = Rich().on_message("小程序检测", "小程序爪巴", block=False)
@bili_rich.handle()
@@ -18,7 +18,7 @@ async def _fk_bili(bot: Bot, event: MessageEvent):
msg = str(event.message)
try:
result, is_ok = await Rich().fk_bili(msg)
- except BaseException:
+ except Exception:
return
log.debug(result, is_ok)
if not is_ok:
diff --git a/ATRI/plugins/setu/__init__.py b/ATRI/plugins/setu/__init__.py
index d252416..244e030 100644
--- a/ATRI/plugins/setu/__init__.py
+++ b/ATRI/plugins/setu/__init__.py
@@ -81,7 +81,7 @@ async def _tag_setu(bot: Bot, event: MessageEvent):
_catcher_max_file_size = 128
-setu_catcher = Setu().on_message("涩图嗅探", block=False)
+setu_catcher = Setu().on_message("涩图嗅探", "涩图嗅探器", block=False)
@setu_catcher.handle()
diff --git a/ATRI/plugins/wife/__init__.py b/ATRI/plugins/wife/__init__.py
index 493c9ca..57a5af2 100644
--- a/ATRI/plugins/wife/__init__.py
+++ b/ATRI/plugins/wife/__init__.py
@@ -16,7 +16,11 @@ _is_tietie = True
tietie_superuser = Wife().on_message(
- "只与维护者贴贴w,‘不可以贴’以拒绝贴贴~,‘来贴贴’以接受贴贴~", rule=Rule(), permission=SUPERUSER, block=False
+ "贴贴",
+ "只与维护者贴贴w,‘不可以贴’以拒绝贴贴~,‘来贴贴’以接受贴贴~",
+ rule=Rule(),
+ permission=SUPERUSER,
+ block=False,
)
diff --git a/ATRI/service.py b/ATRI/service.py
index 0501fca..d127431 100644
--- a/ATRI/service.py
+++ b/ATRI/service.py
@@ -10,7 +10,7 @@ from nonebot.permission import Permission
from nonebot.typing import T_State, T_Handler, T_RuleChecker
from nonebot.rule import Rule, command, keyword, regex
-from ATRI.exceptions import ReadFileError, WriteError
+from ATRI.exceptions import ReadFileError, ServiceRegisterError, WriteError
if TYPE_CHECKING:
from nonebot.adapters import Bot, Event
@@ -35,7 +35,7 @@ class ServiceInfo(BaseModel):
class CommandInfo(BaseModel):
type: str
docs: str
- aliases: list
+ aliases: list or set
class Service:
@@ -147,7 +147,9 @@ class Service:
def on_message(
self,
+ name: str = None,
docs: str = None,
+ _from: str = str(), # 供类似 on_command 的方法,提供更直观的 log 中 matcher 触发来源
rule: Optional[Union[Rule, T_RuleChecker]] = None,
permission: Optional[Permission] = None,
handlers: Optional[List[T_Handler]] = None,
@@ -166,48 +168,43 @@ class Service:
if not state:
state = self.state
- if docs:
- a = 0
+ if name:
cmd_list = self._load_cmds()
- while True:
- _type = "message" + str(a)
- if _type not in cmd_list:
- break
- else:
- a += 1
-
- cmd_list[_type] = CommandInfo(type=_type, docs=docs, aliases=list()).dict()
+
+ name = name + "-onmsg"
+
+ cmd_list[name] = CommandInfo(
+ type="message", docs=docs, aliases=list()
+ ).dict()
self._save_cmds(cmd_list)
matcher = Matcher.new(
"message",
Rule() & rule,
permission or Permission(),
+ module=self.service+"-"+_from,
temp=self.temp,
priority=priority,
block=block,
handlers=handlers,
default_state=state,
)
+ matcher.module = self.service
return matcher
- def on_notice(self, docs: str, block: bool = True) -> Type[Matcher]:
- a = 0
+ def on_notice(self, name: str, docs: str, block: bool = True) -> Type[Matcher]:
cmd_list = self._load_cmds()
- while True:
- _type = "notice" + str(a)
- if _type not in cmd_list:
- break
- else:
- a += 1
- cmd_list[_type] = CommandInfo(type=_type, docs=docs, aliases=list()).dict()
+ name = name + "-onntc"
+
+ cmd_list[name] = CommandInfo(type="notice", docs=docs, aliases=list()).dict()
self._save_cmds(cmd_list)
matcher = Matcher.new(
"notice",
Rule() & self.rule,
Permission(),
+ module=self.service+"-"+name,
temp=self.temp,
priority=self.priority,
block=block,
@@ -216,23 +213,19 @@ class Service:
)
return matcher
- def on_request(self, docs: str, block: bool = True) -> Type[Matcher]:
- a = 0
+ def on_request(self, name: str, docs: str, block: bool = True) -> Type[Matcher]:
cmd_list = self._load_cmds()
- while True:
- _type = "request" + str(a)
- if _type not in cmd_list:
- break
- else:
- a += 1
- cmd_list[_type] = CommandInfo(type=_type, docs=docs, aliases=list()).dict()
+ name = name + "-onreq"
+
+ cmd_list[name] = CommandInfo(type="request", docs=docs, aliases=list()).dict()
self._save_cmds(cmd_list)
matcher = Matcher.new(
"request",
Rule() & self.rule,
Permission(),
+ module=self.service+"-"+name,
temp=self.temp,
priority=self.priority,
block=block,
@@ -249,14 +242,15 @@ class Service:
aliases: Optional[Set[Union[str, Tuple[str, ...]]]] = None,
**kwargs,
) -> Type[Matcher]:
- _type = "command"
cmd_list = self._load_cmds()
if not rule:
rule = self.rule
if not aliases:
aliases = set()
- cmd_list[cmd] = CommandInfo(type=_type, docs=docs, aliases=list(aliases)).dict()
+ cmd_list[cmd] = CommandInfo(
+ type="command", docs=docs, aliases=list(aliases)
+ ).dict()
self._save_cmds(cmd_list)
async def _strip_cmd(bot: "Bot", event: "Event", state: T_State):
@@ -273,7 +267,7 @@ class Service:
commands = set([cmd]) | (aliases or set())
return self.on_message(
- rule=command(*commands) & rule, handlers=handlers, **kwargs
+ _from=str(cmd), rule=command(*commands) & rule, handlers=handlers, **kwargs
)
def on_keyword(
@@ -286,19 +280,14 @@ class Service:
if not rule:
rule = self.rule
- a = 0
+ name = list(keywords)[0] + "-onkw"
+
cmd_list = self._load_cmds()
- while True:
- _type = "keyword" + str(a)
- if _type not in cmd_list:
- break
- else:
- a += 1
- cmd_list[_type] = CommandInfo(type=_type, docs=docs, aliases=list()).dict()
+ cmd_list[name] = CommandInfo(type="keyword", docs=docs, aliases=keywords).dict()
self._save_cmds(cmd_list)
- return self.on_message(rule=keyword(*keywords) & rule, **kwargs)
+ return self.on_message(_from=name, rule=keyword(*keywords) & rule, **kwargs)
def on_regex(
self,
@@ -308,15 +297,14 @@ class Service:
rule: Optional[Union[Rule, T_RuleChecker]] = None,
**kwargs,
) -> Type[Matcher]:
- _type = "regex"
if not rule:
rule = self.rule
cmd_list = self._load_cmds()
- cmd_list[pattern] = CommandInfo(type=_type, docs=docs, aliases=list()).dict()
+ cmd_list[pattern] = CommandInfo(type="regex", docs=docs, aliases=list()).dict()
self._save_cmds(cmd_list)
- return self.on_message(rule=regex(pattern, flags) & rule, **kwargs)
+ return self.on_message(_from=pattern, rule=regex(pattern, flags) & rule, **kwargs)
class ServiceTools(object):