koishi-plugin-cocoyyy-console 1.2.1-alpha.2 → 1.2.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +52 -31
- package/lib/services/group_func_limit_service.d.ts +11 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -381,19 +381,62 @@ function loadGroupFunctionLimitConfig(config) {
|
|
|
381
381
|
}
|
|
382
382
|
}
|
|
383
383
|
__name(loadGroupFunctionLimitConfig, "loadGroupFunctionLimitConfig");
|
|
384
|
+
function getEffectiveMenuListForGuild(guildId) {
|
|
385
|
+
if (!groupFunctionLimitConfig || groupFunctionLimitConfig.length === 0) {
|
|
386
|
+
return [];
|
|
387
|
+
}
|
|
388
|
+
const explicit = groupFunctionLimitConfig.find(
|
|
389
|
+
(item) => String(item.group_id) === String(guildId)
|
|
390
|
+
);
|
|
391
|
+
if (explicit) {
|
|
392
|
+
return Array.isArray(explicit.menu_list) ? explicit.menu_list : [];
|
|
393
|
+
}
|
|
394
|
+
const defaultEntry = groupFunctionLimitConfig.find(
|
|
395
|
+
(item) => String(item.group_id) === "#"
|
|
396
|
+
);
|
|
397
|
+
if (defaultEntry) {
|
|
398
|
+
return Array.isArray(defaultEntry.menu_list) ? defaultEntry.menu_list : [];
|
|
399
|
+
}
|
|
400
|
+
return [];
|
|
401
|
+
}
|
|
402
|
+
__name(getEffectiveMenuListForGuild, "getEffectiveMenuListForGuild");
|
|
403
|
+
function isFunctionAllowedForGuild(guildId, menuNumber) {
|
|
404
|
+
if (!groupFunctionLimitConfig || groupFunctionLimitConfig.length === 0) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
if (guildId === void 0 || guildId === null) {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
return getEffectiveMenuListForGuild(guildId).includes(menuNumber);
|
|
411
|
+
}
|
|
412
|
+
__name(isFunctionAllowedForGuild, "isFunctionAllowedForGuild");
|
|
413
|
+
function getAllowedMenuNumbersForGuild(guildId) {
|
|
414
|
+
if (!groupFunctionLimitConfig || groupFunctionLimitConfig.length === 0) {
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
if (guildId === void 0 || guildId === null) {
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
const allMenus = menuList ?? [];
|
|
421
|
+
if (allMenus.length === 0) {
|
|
422
|
+
return null;
|
|
423
|
+
}
|
|
424
|
+
const validNumbers = new Set(allMenus.map((item) => item.number));
|
|
425
|
+
return getEffectiveMenuListForGuild(guildId).filter((n) => validNumbers.has(n));
|
|
426
|
+
}
|
|
427
|
+
__name(getAllowedMenuNumbersForGuild, "getAllowedMenuNumbersForGuild");
|
|
384
428
|
function getCtxForFunction(ctx, menuNumber) {
|
|
385
429
|
if (!groupFunctionLimitConfig || groupFunctionLimitConfig.length === 0) {
|
|
386
430
|
return ctx;
|
|
387
431
|
}
|
|
388
|
-
const
|
|
389
|
-
const defaultAllowed = defaultEntry ? defaultEntry.menu_list.includes(menuNumber) : false;
|
|
432
|
+
const defaultAllowed = isFunctionAllowedForGuild("#", menuNumber) ?? false;
|
|
390
433
|
const explicitGroups = groupFunctionLimitConfig.filter((item) => String(item.group_id) !== "#");
|
|
391
434
|
if (defaultAllowed) {
|
|
392
|
-
const excludedIds = explicitGroups.filter((item) => !item.
|
|
435
|
+
const excludedIds = explicitGroups.filter((item) => !getEffectiveMenuListForGuild(item.group_id).includes(menuNumber)).map((item) => String(item.group_id));
|
|
393
436
|
if (excludedIds.length === 0) return ctx;
|
|
394
437
|
return ctx.exclude((session) => !!session.guildId && excludedIds.includes(session.guildId));
|
|
395
438
|
} else {
|
|
396
|
-
const includedIds = explicitGroups.filter((item) => item.
|
|
439
|
+
const includedIds = explicitGroups.filter((item) => getEffectiveMenuListForGuild(item.group_id).includes(menuNumber)).map((item) => String(item.group_id));
|
|
397
440
|
if (includedIds.length === 0) {
|
|
398
441
|
logger.info(`[getCtxForFunction Info]: 功能 ${menuNumber} 在所有群组中均未启用,跳过注册`);
|
|
399
442
|
return null;
|
|
@@ -402,38 +445,16 @@ function getCtxForFunction(ctx, menuNumber) {
|
|
|
402
445
|
}
|
|
403
446
|
}
|
|
404
447
|
__name(getCtxForFunction, "getCtxForFunction");
|
|
405
|
-
function getGroupFunctionLimitConfig() {
|
|
406
|
-
return groupFunctionLimitConfig;
|
|
407
|
-
}
|
|
408
|
-
__name(getGroupFunctionLimitConfig, "getGroupFunctionLimitConfig");
|
|
409
448
|
function getMenuList() {
|
|
410
449
|
return menuList;
|
|
411
450
|
}
|
|
412
451
|
__name(getMenuList, "getMenuList");
|
|
413
452
|
|
|
414
453
|
// src/services/menu_service.ts
|
|
415
|
-
function getAllowedMenuNumbersForGuild(guildId) {
|
|
416
|
-
const groupList = getGroupFunctionLimitConfig();
|
|
417
|
-
if (!groupList || groupList.length === 0) return null;
|
|
418
|
-
if (guildId === void 0 || guildId === null) return null;
|
|
419
|
-
const allMenus = getMenuList() ?? [];
|
|
420
|
-
if (!allMenus || allMenus.length === 0) return null;
|
|
421
|
-
const match = groupList.find(
|
|
422
|
-
(item) => String(item.group_id) === String(guildId)
|
|
423
|
-
);
|
|
424
|
-
if (!match) return null;
|
|
425
|
-
if (!Array.isArray(match.menu_list)) return null;
|
|
426
|
-
const menuByNumber = /* @__PURE__ */ new Map();
|
|
427
|
-
for (const item of allMenus) {
|
|
428
|
-
menuByNumber.set(item.number, item.number);
|
|
429
|
-
}
|
|
430
|
-
return match.menu_list.map((menuNum) => Number(menuByNumber.get(menuNum)));
|
|
431
|
-
}
|
|
432
|
-
__name(getAllowedMenuNumbersForGuild, "getAllowedMenuNumbersForGuild");
|
|
433
454
|
function isCommandAllowedForGuild(commandNumber, guildId) {
|
|
434
|
-
const allowed =
|
|
435
|
-
if (
|
|
436
|
-
return allowed
|
|
455
|
+
const allowed = isFunctionAllowedForGuild(guildId, commandNumber);
|
|
456
|
+
if (allowed === null) return true;
|
|
457
|
+
return allowed;
|
|
437
458
|
}
|
|
438
459
|
__name(isCommandAllowedForGuild, "isCommandAllowedForGuild");
|
|
439
460
|
function buildFuncMenu(menuTitle, featureName, commandList2) {
|
|
@@ -444,7 +465,7 @@ ${menuTitle}:
|
|
|
444
465
|
}
|
|
445
466
|
__name(buildFuncMenu, "buildFuncMenu");
|
|
446
467
|
function getMenuListByCommand(command = null, functionConfig, session) {
|
|
447
|
-
const guildId = session?.
|
|
468
|
+
const guildId = session?.guildId;
|
|
448
469
|
const allMenus = getMenuList() ?? [];
|
|
449
470
|
if (allMenus.length === 0) return "当前没有可用的功能,请联系管理员配置功能";
|
|
450
471
|
const menuByNumber = /* @__PURE__ */ new Map();
|
|
@@ -517,7 +538,7 @@ function getMenuListByCommand(command = null, functionConfig, session) {
|
|
|
517
538
|
return buildFuncMenu("禁漫下载功能菜单", "禁漫下载功能", jmFuncMenuList);
|
|
518
539
|
default:
|
|
519
540
|
const allowedMenuNumbers = getAllowedMenuNumbersForGuild(guildId);
|
|
520
|
-
const finalMenuList = allowedMenuNumbers ? allMenus.filter((item) => allowedMenuNumbers.includes(item.number))
|
|
541
|
+
const finalMenuList = allowedMenuNumbers === null ? allMenus : allMenus.filter((item) => allowedMenuNumbers.includes(item.number));
|
|
521
542
|
return `[所有命令都需要@bot]
|
|
522
543
|
当前可用功能列表:
|
|
523
544
|
${finalMenuList.map((item) => item.name + ": " + item.description).join("\n ")}
|
|
@@ -11,6 +11,16 @@ type MenuList = {
|
|
|
11
11
|
description: string;
|
|
12
12
|
};
|
|
13
13
|
declare function loadGroupFunctionLimitConfig(config: my_config.GroupFunctionLimitConfig): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* 判断指定群聊是否允许使用某功能编号。
|
|
16
|
+
* 返回 null 表示未加载功能限制配置(不做限制)。
|
|
17
|
+
*/
|
|
18
|
+
declare function isFunctionAllowedForGuild(guildId: string | number | undefined, menuNumber: number): boolean | null;
|
|
19
|
+
/**
|
|
20
|
+
* 返回指定群聊允许使用的功能编号列表。
|
|
21
|
+
* 返回 null 表示未加载功能限制配置(不做限制)。
|
|
22
|
+
*/
|
|
23
|
+
declare function getAllowedMenuNumbersForGuild(guildId: string | number | undefined): number[] | null;
|
|
14
24
|
/**
|
|
15
25
|
* 根据 groupFuncLimit.json 的 groupList 配置,为指定功能编号返回对应的 Koishi Context:
|
|
16
26
|
*
|
|
@@ -21,7 +31,7 @@ declare function loadGroupFunctionLimitConfig(config: my_config.GroupFunctionLim
|
|
|
21
31
|
* - 若未加载功能限制配置:直接返回原始 ctx(不加限制)
|
|
22
32
|
*/
|
|
23
33
|
declare function getCtxForFunction(ctx: Context, menuNumber: number): Context | null;
|
|
24
|
-
export { groupFunctionLimitConfig, loadGroupFunctionLimitConfig, getCtxForFunction, };
|
|
34
|
+
export { groupFunctionLimitConfig, loadGroupFunctionLimitConfig, getCtxForFunction, isFunctionAllowedForGuild, getAllowedMenuNumbersForGuild, };
|
|
25
35
|
declare function getGroupFunctionLimitConfig(): GroupFunctionLimitItem[];
|
|
26
36
|
declare function getMenuList(): MenuList[];
|
|
27
37
|
export { getGroupFunctionLimitConfig, getMenuList, };
|