koishi-plugin-echo-cave 1.16.16 → 1.17.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.cjs +115 -4
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -101,15 +101,35 @@ var require_zh_CN = __commonJS({
|
|
|
101
101
|
invalidAllMention: "\u274C \u4E0D\u652F\u6301 @\u5168\u4F53\u6210\u5458\uFF0C\u8BF7\u76F4\u63A5\u6307\u5B9A\u5177\u4F53\u7528\u6237\uFF01"
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
|
-
"cave.
|
|
104
|
+
"cave.drop": {
|
|
105
105
|
description: "\u62B9\u53BB\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F",
|
|
106
106
|
messages: {
|
|
107
107
|
noIdProvided: "\u274C \u8BF7\u63D0\u4F9B\u8981\u5220\u9664\u7684\u56DE\u58F0\u6D1E\u6D88\u606F ID\uFF01",
|
|
108
108
|
adminOnly: "\u26D4 \u8BE5\u6D88\u606F\u7531\u7BA1\u7406\u5458\u53D1\u5E03\uFF0C\u5DF2\u5F00\u542F\u7BA1\u7406\u5458\u6D88\u606F\u4FDD\u62A4\uFF0C\u53EA\u6709\u7BA1\u7406\u5458\u53EF\u4EE5\u5220\u9664\u3002",
|
|
109
109
|
permissionDenied: "\u26D4 \u60A8\u6CA1\u6709\u6743\u9650\u5220\u9664\u6B64\u6D88\u606F\uFF01\u53EA\u6709\u7BA1\u7406\u5458\u53EF\u4EE5\u5220\u9664\u3002",
|
|
110
110
|
contributorDeleteDenied: "\u26D4 \u60A8\u6CA1\u6709\u6743\u9650\u5220\u9664\u6B64\u6D88\u606F\uFF01\u5F53\u524D\u914D\u7F6E\u4E0D\u5141\u8BB8\u6295\u7A3F\u8005\u5220\u9664\u56DE\u58F0\u6D1E\u3002",
|
|
111
|
-
senderDeleteDenied: "\u26D4 \u60A8\u6CA1\u6709\u6743\u9650\u5220\u9664\u6B64\u6D88\u606F\uFF01\u5F53\u524D\u914D\u7F6E\u4E0D\u5141\u8BB8\u539F\u59CB\u53D1\u9001\u8005\u5220\u9664\u56DE\u58F0\u6D1E\u3002"
|
|
112
|
-
|
|
111
|
+
senderDeleteDenied: "\u26D4 \u60A8\u6CA1\u6709\u6743\u9650\u5220\u9664\u6B64\u6D88\u606F\uFF01\u5F53\u524D\u914D\u7F6E\u4E0D\u5141\u8BB8\u539F\u59CB\u53D1\u9001\u8005\u5220\u9664\u56DE\u58F0\u6D1E\u3002"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"cave.purge": {
|
|
115
|
+
description: "\u62B9\u53BB\u591A\u4E2A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F",
|
|
116
|
+
messages: {
|
|
117
|
+
noIdProvided: "\u274C \u8BF7\u63D0\u4F9B\u8981\u5220\u9664\u7684\u56DE\u58F0\u6D1E\u6D88\u606F ID\uFF01",
|
|
118
|
+
msgDeleted: "\u2705 \u5DF2\u6210\u529F\u62B9\u53BB\u56DE\u58F0\u6D1E\u6D88\u606F ID\uFF1A{0}",
|
|
119
|
+
msgDeletedMultiple: "\u2705 \u5DF2\u6210\u529F\u62B9\u53BB {0} \u6761\u56DE\u58F0\u6D1E\u6D88\u606F\uFF01",
|
|
120
|
+
msgDeleteFailedAll: "\u274C \u6240\u6709\u6307\u5B9A\u7684\u56DE\u58F0\u6D1E\u6D88\u606F ID \u5747\u5220\u9664\u5931\u8D25\uFF1A{0}",
|
|
121
|
+
msgDeletePartial: "\u26A0\uFE0F \u90E8\u5206\u56DE\u58F0\u6D1E\u6D88\u606F\u5220\u9664\u5931\u8D25\uFF0C\u5931\u8D25 ID\uFF1A{0}"
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"cave.search": {
|
|
125
|
+
description: "\u641C\u7D22\u4E0E\u6307\u5B9A\u7528\u6237\u76F8\u5173\u7684\u56DE\u58F0\u6D1E",
|
|
126
|
+
messages: {
|
|
127
|
+
noUserIdProvided: "\u274C \u8BF7\u63D0\u4F9B\u8981\u641C\u7D22\u7684\u7528\u6237 ID\uFF01",
|
|
128
|
+
invalidAllMention: "\u274C \u4E0D\u652F\u6301 @\u5168\u4F53\u6210\u5458\uFF0C\u8BF7\u76F4\u63A5\u6307\u5B9A\u5177\u4F53\u7528\u6237\uFF01",
|
|
129
|
+
userNotInGroup: "\u274C \u63D0\u4F9B\u7684\u7528\u6237 ID \u4E0D\u5168\u5C5E\u4E8E\u8BE5\u7FA4\u7EC4\uFF01",
|
|
130
|
+
noValidUserIdProvided: "\u274C \u672A\u63D0\u4F9B\u6709\u6548\u7684\u7528\u6237 ID\uFF01",
|
|
131
|
+
noMatchingCaves: "\u{1F50D} \u672A\u627E\u5230\u4E0E\u7528\u6237 {0} \u76F8\u5173\u7684\u56DE\u58F0\u6D1E\u6D88\u606F",
|
|
132
|
+
searchResult: "\u{1F50D} \u5171\u627E\u5230 {0} \u6761\u4E0E\u8BE5\u7528\u6237\u76F8\u5173\u7684\u56DE\u58F0\u6D1E\u6D88\u606F\uFF1A\nID \u5217\u8868\uFF1A{1}"
|
|
113
133
|
}
|
|
114
134
|
},
|
|
115
135
|
"cave.listen": {
|
|
@@ -579,9 +599,15 @@ function apply(ctx, cfg) {
|
|
|
579
599
|
ctx.command("cave.echo [...userIds]").action(
|
|
580
600
|
async ({ session }, ...userIds) => await addCave(ctx, session, cfg, userIds)
|
|
581
601
|
);
|
|
582
|
-
ctx.command("cave.
|
|
602
|
+
ctx.command("cave.drop <id:number>").action(
|
|
583
603
|
async ({ session }, id) => await deleteCave(ctx, session, cfg, id)
|
|
584
604
|
);
|
|
605
|
+
ctx.command("cave.purge <...ids:number>").action(
|
|
606
|
+
async ({ session }, ...ids) => await deleteCaves(ctx, session, cfg, ids)
|
|
607
|
+
);
|
|
608
|
+
ctx.command("cave.search <...userIds>").action(
|
|
609
|
+
async ({ session }, ...userIds) => await searchCave(ctx, session, userIds)
|
|
610
|
+
);
|
|
585
611
|
ctx.command("cave.listen").action(async ({ session }) => await getCaveListByUser(ctx, session));
|
|
586
612
|
ctx.command("cave.trace").action(
|
|
587
613
|
async ({ session }) => await getCaveListByOriginUser(ctx, session)
|
|
@@ -694,6 +720,57 @@ async function deleteCave(ctx, session, cfg, id) {
|
|
|
694
720
|
await ctx.database.remove("echo_cave", id);
|
|
695
721
|
return session.text(".msgDeleted", [id]);
|
|
696
722
|
}
|
|
723
|
+
async function deleteCaves(ctx, session, cfg, ids) {
|
|
724
|
+
if (!session.guildId) {
|
|
725
|
+
return session.text("echo-cave.general.privateChatReminder");
|
|
726
|
+
}
|
|
727
|
+
if (!ids) {
|
|
728
|
+
return session.text(".noIdProvided");
|
|
729
|
+
}
|
|
730
|
+
const failedIds = [];
|
|
731
|
+
const currentUserId = session.userId;
|
|
732
|
+
const user = await ctx.database.getUser(session.platform, currentUserId);
|
|
733
|
+
const userAuthority = user.authority;
|
|
734
|
+
const isCurrentUserAdmin = userAuthority >= 4;
|
|
735
|
+
const caves = await ctx.database.get("echo_cave", ids);
|
|
736
|
+
for (const cave of caves) {
|
|
737
|
+
const caveMsg = caves[0];
|
|
738
|
+
if (cfg.adminMessageProtection) {
|
|
739
|
+
const caveUser = await ctx.database.getUser(session.platform, caveMsg.userId);
|
|
740
|
+
const isCaveUserAdmin = caveUser.authority >= 4;
|
|
741
|
+
if (isCaveUserAdmin && !isCurrentUserAdmin) {
|
|
742
|
+
failedIds.push(cave.id);
|
|
743
|
+
continue;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
let hasPermission = isCurrentUserAdmin;
|
|
747
|
+
if (!hasPermission) {
|
|
748
|
+
if (currentUserId === caveMsg.userId) {
|
|
749
|
+
hasPermission = cfg.allowContributorDelete;
|
|
750
|
+
} else if (currentUserId === caveMsg.originUserId) {
|
|
751
|
+
hasPermission = cfg.allowSenderDelete;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
if (!hasPermission) {
|
|
755
|
+
failedIds.push(cave.id);
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
if (cfg.deleteMediaWhenDeletingMsg) {
|
|
759
|
+
await deleteMediaFilesFromMessage(ctx, caveMsg.content);
|
|
760
|
+
}
|
|
761
|
+
await ctx.database.remove("echo_cave", cave.id);
|
|
762
|
+
}
|
|
763
|
+
const foundIds = new Set(caves.map((r) => r.id));
|
|
764
|
+
const missingIds = ids.filter((id) => !foundIds.has(id));
|
|
765
|
+
failedIds.push(...missingIds);
|
|
766
|
+
if (failedIds.length === 0) {
|
|
767
|
+
return session.text(".msgDeletedMultiple", [ids.length]);
|
|
768
|
+
} else if (failedIds.length === ids.length) {
|
|
769
|
+
return session.text(".msgDeleteFailedAll", [failedIds.join(", ")]);
|
|
770
|
+
} else {
|
|
771
|
+
return session.text(".msgDeletePartial", [failedIds.join(", ")]);
|
|
772
|
+
}
|
|
773
|
+
}
|
|
697
774
|
async function addCave(ctx, session, cfg, userIds) {
|
|
698
775
|
if (!session.guildId) {
|
|
699
776
|
return session.text("echo-cave.general.privateChatReminder");
|
|
@@ -790,6 +867,40 @@ async function bindUsersToCave(ctx, session, id, userIds) {
|
|
|
790
867
|
});
|
|
791
868
|
return session.text(".userBoundSuccess", [id]);
|
|
792
869
|
}
|
|
870
|
+
async function searchCave(ctx, session, userIds) {
|
|
871
|
+
if (!session.guildId) {
|
|
872
|
+
return session.text("echo-cave.general.privateChatReminder");
|
|
873
|
+
}
|
|
874
|
+
if (!userIds || userIds.length === 0) {
|
|
875
|
+
return session.text(".noUserIdProvided");
|
|
876
|
+
}
|
|
877
|
+
const result = parseUserIds(userIds);
|
|
878
|
+
if (result.error === "invalid_all_mention") {
|
|
879
|
+
return session.text(".invalidAllMention");
|
|
880
|
+
}
|
|
881
|
+
const parsedUserIds = result.parsedUserIds;
|
|
882
|
+
if (parsedUserIds.length === 0) {
|
|
883
|
+
return session.text(".noValidUserIdProvided");
|
|
884
|
+
}
|
|
885
|
+
const isUserInGroup = await checkUsersInGroup(ctx, session, parsedUserIds);
|
|
886
|
+
if (!isUserInGroup) {
|
|
887
|
+
return session.text(".userNotInGroup");
|
|
888
|
+
}
|
|
889
|
+
const targetUserId = parsedUserIds[0];
|
|
890
|
+
const { channelId } = session;
|
|
891
|
+
const caves = await ctx.database.get("echo_cave", {
|
|
892
|
+
channelId
|
|
893
|
+
});
|
|
894
|
+
const matchingCaves = caves.filter(
|
|
895
|
+
(cave) => cave.originUserId === targetUserId || cave.relatedUsers.includes(targetUserId)
|
|
896
|
+
);
|
|
897
|
+
if (matchingCaves.length === 0) {
|
|
898
|
+
return session.text(".noMatchingCaves", [targetUserId]);
|
|
899
|
+
}
|
|
900
|
+
const caveIds = matchingCaves.map((cave) => cave.id).join(", ");
|
|
901
|
+
const count = matchingCaves.length;
|
|
902
|
+
return session.text(".searchResult", [count, caveIds]);
|
|
903
|
+
}
|
|
793
904
|
// Annotate the CommonJS export names for ESM import in node:
|
|
794
905
|
0 && (module.exports = {
|
|
795
906
|
Config,
|