Skip to content

Commit 21b956b

Browse files
committed
fix: mj open auth bug
1 parent 792e940 commit 21b956b

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

plugins/linkai/linkai.py

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import plugins
22
from bridge.context import ContextType
33
from bridge.reply import Reply, ReplyType
4-
from config import global_config
54
from plugins import *
65
from .midjourney import MJBot
76
from .summary import LinkSummary
87
from bridge import bridge
98
from common.expired_dict import ExpiredDict
109
from common import const
1110
import os
12-
11+
from .utils import Util
1312

1413
@plugins.register(
1514
name="linkai",
@@ -129,7 +128,7 @@ def _process_admin_cmd(self, e_context: EventContext):
129128

130129
if len(cmd) == 2 and (cmd[1] == "open" or cmd[1] == "close"):
131130
# 知识库开关指令
132-
if not _is_admin(e_context):
131+
if not Util.is_admin(e_context):
133132
_set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR)
134133
return
135134
is_open = True
@@ -147,7 +146,7 @@ def _process_admin_cmd(self, e_context: EventContext):
147146
if not context.kwargs.get("isgroup"):
148147
_set_reply_text("该指令需在群聊中使用", e_context, level=ReplyType.ERROR)
149148
return
150-
if not _is_admin(e_context):
149+
if not Util.is_admin(e_context):
151150
_set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR)
152151
return
153152
app_code = cmd[2]
@@ -164,7 +163,7 @@ def _process_admin_cmd(self, e_context: EventContext):
164163

165164
if len(cmd) == 3 and cmd[1] == "sum" and (cmd[2] == "open" or cmd[2] == "close"):
166165
# 知识库开关指令
167-
if not _is_admin(e_context):
166+
if not Util.is_admin(e_context):
168167
_set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR)
169168
return
170169
is_open = True
@@ -253,23 +252,6 @@ def _send_info(e_context: EventContext, content: str):
253252
channel = e_context["channel"]
254253
channel.send(reply, e_context["context"])
255254

256-
# 静态方法
257-
def _is_admin(e_context: EventContext) -> bool:
258-
"""
259-
判断消息是否由管理员用户发送
260-
:param e_context: 消息上下文
261-
:return: True: 是, False: 否
262-
"""
263-
context = e_context["context"]
264-
if context["isgroup"]:
265-
actual_user_id= context.kwargs.get("msg").actual_user_id
266-
for admin_user in global_config["admin_users"]:
267-
if actual_user_id and actual_user_id in admin_user:
268-
return True
269-
return False
270-
else:
271-
return context["receiver"] in global_config["admin_users"]
272-
273255

274256
def _find_user_id(context):
275257
if context["isgroup"]:

plugins/linkai/midjourney.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import asyncio
99
from bridge.context import ContextType
1010
from plugins import EventContext, EventAction
11+
from .utils import Util
1112

1213
INVALID_REQUEST = 410
1314
NOT_FOUND_ORIGIN_IMAGE = 461
@@ -113,6 +114,9 @@ def process_mj_task(self, mj_type: TaskType, e_context: EventContext):
113114
return
114115

115116
if len(cmd) == 2 and (cmd[1] == "open" or cmd[1] == "close"):
117+
if not Util.is_admin(e_context):
118+
Util.set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR)
119+
return
116120
# midjourney 开关指令
117121
is_open = True
118122
tips_text = "开启"

plugins/linkai/utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from config import global_config
2+
from bridge.reply import Reply, ReplyType
3+
from plugins.event import EventContext, EventAction
4+
5+
6+
class Util:
7+
@staticmethod
8+
def is_admin(e_context: EventContext) -> bool:
9+
"""
10+
判断消息是否由管理员用户发送
11+
:param e_context: 消息上下文
12+
:return: True: 是, False: 否
13+
"""
14+
context = e_context["context"]
15+
if context["isgroup"]:
16+
actual_user_id = context.kwargs.get("msg").actual_user_id
17+
for admin_user in global_config["admin_users"]:
18+
if actual_user_id and actual_user_id in admin_user:
19+
return True
20+
return False
21+
else:
22+
return context["receiver"] in global_config["admin_users"]
23+
24+
@staticmethod
25+
def set_reply_text(content: str, e_context: EventContext, level: ReplyType = ReplyType.ERROR):
26+
reply = Reply(level, content)
27+
e_context["reply"] = reply
28+
e_context.action = EventAction.BREAK_PASS

0 commit comments

Comments
 (0)