perf: 私聊下白名单不拦截管理员

This commit is contained in:
Soulter
2024-12-10 16:32:54 +08:00
parent bdfc77d349
commit f963194124
4 changed files with 13 additions and 11 deletions
@@ -15,6 +15,7 @@ class WakingCheckStage(Stage):
2. 机器人的消息被提到了
3. 以 wake_prefix 前缀开头
4. 插件(Star)的 handler filter 通过
5. 私聊情况下,位于 admins_id 列表中的管理员的消息
'''
async def initialize(self, ctx: PipelineContext) -> None:
@@ -14,6 +14,8 @@ class WhitelistCheckStage(Stage):
async def process(self, event: AstrMessageEvent) -> Union[None, AsyncGenerator[None, None]]:
# 检查是否在白名单
if event.role == 'admin' and event.get_message_type() == MessageType.FRIEND_MESSAGE:
return
if event.unified_msg_origin not in self.whitelist:
logger.info(f"会话 {event.unified_msg_origin} 不在会话白名单中,已终止事件传播。")
event.stop_event()
+5 -5
View File
@@ -13,8 +13,8 @@ class AuthRoute(Route):
self.register_routes()
async def login(self):
username = self.config.dashboard.username
password = self.config.dashboard.password
username = self.config['dashboard']['username']
password = self.config['dashboard']['password']
post_data = await request.json
if post_data["username"] == username and post_data["password"] == password:
return Response().ok({
@@ -25,7 +25,7 @@ class AuthRoute(Route):
return Response().error("用户名或密码错误").__dict__
async def edit_account(self):
password = self.config.dashboard.password
password = self.config['dashboard']['password']
post_data = await request.json
if post_data["password"] != password:
@@ -37,9 +37,9 @@ class AuthRoute(Route):
return Response().error("新用户名和新密码不能同时为空,你改了个寂寞").__dict__
if new_pwd:
self.config.dashboard.password = new_pwd
self.config['dashboard']['password'] = new_pwd
if new_username:
self.config.dashboard.username = new_username
self.config['dashboard']['username'] = new_username
self.config.save_config()
+5 -6
View File
@@ -51,9 +51,8 @@ class Main(star.Star):
@filter.command("plugin")
async def plugin(self, event: AstrMessageEvent):
plugin_list_info = "已加载的插件:\n"
for plugin in self.context.registered_plugins:
plugin_list_info += f"- `{plugin.metadata.plugin_name}` By {
plugin.metadata.author}: {plugin.metadata.desc}\n"
for plugin in self.context.get_all_stars():
plugin_list_info += f"- `{plugin.name}` By {plugin.author}: {plugin.desc}\n"
if plugin_list_info.strip() == "":
plugin_list_info = "没有加载任何插件。"
@@ -62,12 +61,12 @@ class Main(star.Star):
@filter.command("t2i")
async def t2i(self, event: AstrMessageEvent):
config = self.context.get_config()
if config.t2i:
config.t2i = False
if config['t2i']:
config['t2i'] = False
config.save_config()
event.set_result(MessageEventResult().message("已关闭文本转图片模式。"))
return
config.t2i = True
config['t2i'] = True
config.save_config()
event.set_result(MessageEventResult().message("已开启文本转图片模式。"))