Преглед на файлове

fix: mj open auth bug

master
zhayujie преди 1 година
родител
ревизия
21b956b983
променени са 3 файла, в които са добавени 36 реда и са изтрити 22 реда
  1. +4
    -22
      plugins/linkai/linkai.py
  2. +4
    -0
      plugins/linkai/midjourney.py
  3. +28
    -0
      plugins/linkai/utils.py

+ 4
- 22
plugins/linkai/linkai.py Целия файл

@@ -1,7 +1,6 @@
import plugins import plugins
from bridge.context import ContextType from bridge.context import ContextType
from bridge.reply import Reply, ReplyType from bridge.reply import Reply, ReplyType
from config import global_config
from plugins import * from plugins import *
from .midjourney import MJBot from .midjourney import MJBot
from .summary import LinkSummary from .summary import LinkSummary
@@ -9,7 +8,7 @@ from bridge import bridge
from common.expired_dict import ExpiredDict from common.expired_dict import ExpiredDict
from common import const from common import const
import os import os
from .utils import Util


@plugins.register( @plugins.register(
name="linkai", name="linkai",
@@ -129,7 +128,7 @@ class LinkAI(Plugin):


if len(cmd) == 2 and (cmd[1] == "open" or cmd[1] == "close"): if len(cmd) == 2 and (cmd[1] == "open" or cmd[1] == "close"):
# 知识库开关指令 # 知识库开关指令
if not _is_admin(e_context):
if not Util.is_admin(e_context):
_set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR) _set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR)
return return
is_open = True is_open = True
@@ -147,7 +146,7 @@ class LinkAI(Plugin):
if not context.kwargs.get("isgroup"): if not context.kwargs.get("isgroup"):
_set_reply_text("该指令需在群聊中使用", e_context, level=ReplyType.ERROR) _set_reply_text("该指令需在群聊中使用", e_context, level=ReplyType.ERROR)
return return
if not _is_admin(e_context):
if not Util.is_admin(e_context):
_set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR) _set_reply_text("需要管理员权限执行", e_context, level=ReplyType.ERROR)
return return
app_code = cmd[2] app_code = cmd[2]
@@ -164,7 +163,7 @@ class LinkAI(Plugin):


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


# 静态方法
def _is_admin(e_context: EventContext) -> bool:
"""
判断消息是否由管理员用户发送
:param e_context: 消息上下文
:return: True: 是, False: 否
"""
context = e_context["context"]
if context["isgroup"]:
actual_user_id= context.kwargs.get("msg").actual_user_id
for admin_user in global_config["admin_users"]:
if actual_user_id and actual_user_id in admin_user:
return True
return False
else:
return context["receiver"] in global_config["admin_users"]



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


+ 4
- 0
plugins/linkai/midjourney.py Целия файл

@@ -8,6 +8,7 @@ from bridge.reply import Reply, ReplyType
import asyncio import asyncio
from bridge.context import ContextType from bridge.context import ContextType
from plugins import EventContext, EventAction from plugins import EventContext, EventAction
from .utils import Util


INVALID_REQUEST = 410 INVALID_REQUEST = 410
NOT_FOUND_ORIGIN_IMAGE = 461 NOT_FOUND_ORIGIN_IMAGE = 461
@@ -113,6 +114,9 @@ class MJBot:
return return


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


+ 28
- 0
plugins/linkai/utils.py Целия файл

@@ -0,0 +1,28 @@
from config import global_config
from bridge.reply import Reply, ReplyType
from plugins.event import EventContext, EventAction


class Util:
@staticmethod
def is_admin(e_context: EventContext) -> bool:
"""
判断消息是否由管理员用户发送
:param e_context: 消息上下文
:return: True: 是, False: 否
"""
context = e_context["context"]
if context["isgroup"]:
actual_user_id = context.kwargs.get("msg").actual_user_id
for admin_user in global_config["admin_users"]:
if actual_user_id and actual_user_id in admin_user:
return True
return False
else:
return context["receiver"] in global_config["admin_users"]

@staticmethod
def set_reply_text(content: str, e_context: EventContext, level: ReplyType = ReplyType.ERROR):
reply = Reply(level, content)
e_context["reply"] = reply
e_context.action = EventAction.BREAK_PASS

Loading…
Отказ
Запис