9
9
from common import const
10
10
import os
11
11
from .utils import Util
12
- from config import plugin_config
12
+ from config import plugin_config , conf
13
13
14
14
15
15
@plugins .register (
@@ -28,7 +28,7 @@ def __init__(self):
28
28
# 未加载到配置,使用模板中的配置
29
29
self .config = self ._load_config_template ()
30
30
if self .config :
31
- self .mj_bot = MJBot (self .config .get ("midjourney" ))
31
+ self .mj_bot = MJBot (self .config .get ("midjourney" ), self . _fetch_group_app_code )
32
32
self .sum_config = {}
33
33
if self .config :
34
34
self .sum_config = self .config .get ("summary" )
@@ -56,7 +56,8 @@ def on_handle_context(self, e_context: EventContext):
56
56
return
57
57
if context .type != ContextType .IMAGE :
58
58
_send_info (e_context , "正在为你加速生成摘要,请稍后" )
59
- res = LinkSummary ().summary_file (file_path )
59
+ app_code = self ._fetch_app_code (context )
60
+ res = LinkSummary ().summary_file (file_path , app_code )
60
61
if not res :
61
62
if context .type != ContextType .IMAGE :
62
63
_set_reply_text ("因为神秘力量无法获取内容,请稍后再试吧" , e_context , level = ReplyType .TEXT )
@@ -74,7 +75,8 @@ def on_handle_context(self, e_context: EventContext):
74
75
if not LinkSummary ().check_url (context .content ):
75
76
return
76
77
_send_info (e_context , "正在为你加速生成摘要,请稍后" )
77
- res = LinkSummary ().summary_url (context .content )
78
+ app_code = self ._fetch_app_code (context )
79
+ res = LinkSummary ().summary_url (context .content , app_code )
78
80
if not res :
79
81
_set_reply_text ("因为神秘力量无法获取文章内容,请稍后再试吧~" , e_context , level = ReplyType .TEXT )
80
82
return
@@ -169,7 +171,7 @@ def _process_admin_cmd(self, e_context: EventContext):
169
171
return
170
172
171
173
if len (cmd ) == 3 and cmd [1 ] == "sum" and (cmd [2 ] == "open" or cmd [2 ] == "close" ):
172
- # 知识库开关指令
174
+ # 总结对话开关指令
173
175
if not Util .is_admin (e_context ):
174
176
_set_reply_text ("需要管理员权限执行" , e_context , level = ReplyType .ERROR )
175
177
return
@@ -192,14 +194,34 @@ def _process_admin_cmd(self, e_context: EventContext):
192
194
return
193
195
194
196
def _is_summary_open (self , context ) -> bool :
195
- if not self .sum_config or not self .sum_config .get ("enabled" ):
196
- return False
197
- if context .kwargs .get ("isgroup" ) and not self .sum_config .get ("group_enabled" ):
198
- return False
199
- support_type = self .sum_config .get ("type" ) or ["FILE" , "SHARING" ]
200
- if context .type .name not in support_type and context .type .name != "TEXT" :
201
- return False
202
- return True
197
+ # 获取远程应用插件状态
198
+ remote_enabled = False
199
+ if context .kwargs .get ("isgroup" ):
200
+ # 群聊场景只查询群对应的app_code
201
+ group_name = context .get ("msg" ).from_user_nickname
202
+ app_code = self ._fetch_group_app_code (group_name )
203
+ if app_code :
204
+ remote_enabled = Util .fetch_app_plugin (app_code , "内容总结" )
205
+ else :
206
+ # 非群聊场景使用全局app_code
207
+ app_code = conf ().get ("linkai_app_code" )
208
+ if app_code :
209
+ remote_enabled = Util .fetch_app_plugin (app_code , "内容总结" )
210
+
211
+ # 基础条件:总开关开启且消息类型符合要求
212
+ base_enabled = (
213
+ self .sum_config
214
+ and self .sum_config .get ("enabled" )
215
+ and (context .type .name in (
216
+ self .sum_config .get ("type" ) or ["FILE" , "SHARING" ]) or context .type .name == "TEXT" )
217
+ )
218
+
219
+ # 群聊:需要满足(总开关和群开关)或远程插件开启
220
+ if context .kwargs .get ("isgroup" ):
221
+ return (base_enabled and self .sum_config .get ("group_enabled" )) or remote_enabled
222
+
223
+ # 非群聊:只需要满足总开关或远程插件开启
224
+ return base_enabled or remote_enabled
203
225
204
226
# LinkAI 对话任务处理
205
227
def _is_chat_task (self , e_context : EventContext ):
@@ -230,6 +252,19 @@ def _fetch_group_app_code(self, group_name: str) -> str:
230
252
app_code = group_mapping .get (group_name ) or group_mapping .get ("ALL_GROUP" )
231
253
return app_code
232
254
255
+ def _fetch_app_code (self , context ) -> str :
256
+ """
257
+ 根据主配置或者群聊名称获取对应的应用code,优先获取群聊配置的应用code
258
+ :param context: 上下文
259
+ :return: 应用code
260
+ """
261
+ app_code = conf ().get ("linkai_app_code" )
262
+ if context .kwargs .get ("isgroup" ):
263
+ # 群聊场景只查询群对应的app_code
264
+ group_name = context .get ("msg" ).from_user_nickname
265
+ app_code = self ._fetch_group_app_code (group_name )
266
+ return app_code
267
+
233
268
def get_help_text (self , verbose = False , ** kwargs ):
234
269
trigger_prefix = _get_trigger_prefix ()
235
270
help_text = "用于集成 LinkAI 提供的知识库、Midjourney绘画、文档总结、联网搜索等能力。\n \n "
0 commit comments