koishi-plugin-echo-cave 1.16.15 → 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 +130 -29
- 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": {
|
|
@@ -135,7 +155,6 @@ var require_zh_CN = __commonJS({
|
|
|
135
155
|
noUserIdProvided: "\u274C \u8BF7\u63D0\u4F9B\u8981\u7ED1\u5B9A\u7684\u7528\u6237 ID\uFF01",
|
|
136
156
|
msgNotFound: "\u{1F50D} \u672A\u627E\u5230\u8BE5 ID \u7684\u56DE\u58F0\u6D1E\u6D88\u606F",
|
|
137
157
|
userBoundSuccess: "\u2705 \u5DF2\u6210\u529F\u5C06\u7528\u6237\u7ED1\u5B9A\u5230\u56DE\u58F0\u6D1E #{0}\uFF01",
|
|
138
|
-
userAlreadyBound: "\u2139\uFE0F \u8BE5\u7528\u6237\u5DF2\u7ED1\u5B9A\u5230\u56DE\u58F0\u6D1E #{0}\uFF01",
|
|
139
158
|
userNotInGroup: "\u274C \u63D0\u4F9B\u7684\u7528\u6237 ID \u4E0D\u5168\u5C5E\u4E8E\u8BE5\u7FA4\u7EC4\uFF01",
|
|
140
159
|
invalidAllMention: "\u274C \u4E0D\u652F\u6301 @\u5168\u4F53\u6210\u5458\uFF0C\u8BF7\u76F4\u63A5\u6307\u5B9A\u5177\u4F53\u7528\u6237\uFF01"
|
|
141
160
|
}
|
|
@@ -169,23 +188,21 @@ function createTextMsg(content) {
|
|
|
169
188
|
function parseUserIds(userIds) {
|
|
170
189
|
const parsedUserIds = [];
|
|
171
190
|
for (const userId of userIds) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const num = Number(userId);
|
|
186
|
-
if (!Number.isNaN(num)) {
|
|
187
|
-
parsedUserIds.push(userId);
|
|
191
|
+
const num = Number(userId);
|
|
192
|
+
if (!Number.isNaN(num)) {
|
|
193
|
+
parsedUserIds.push(userId);
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
const element = import_koishi.h.parse(userId);
|
|
197
|
+
if (element.length === 1 && element[0].type === "at") {
|
|
198
|
+
const userId2 = element[0].attrs.id;
|
|
199
|
+
if (userId2 === "all") {
|
|
200
|
+
return {
|
|
201
|
+
parsedUserIds: [],
|
|
202
|
+
error: "invalid_all_mention"
|
|
203
|
+
};
|
|
188
204
|
}
|
|
205
|
+
parsedUserIds.push(userId2);
|
|
189
206
|
}
|
|
190
207
|
}
|
|
191
208
|
return {
|
|
@@ -582,22 +599,21 @@ function apply(ctx, cfg) {
|
|
|
582
599
|
ctx.command("cave.echo [...userIds]").action(
|
|
583
600
|
async ({ session }, ...userIds) => await addCave(ctx, session, cfg, userIds)
|
|
584
601
|
);
|
|
585
|
-
ctx.command("cave.
|
|
602
|
+
ctx.command("cave.drop <id:number>").action(
|
|
586
603
|
async ({ session }, id) => await deleteCave(ctx, session, cfg, id)
|
|
587
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
|
+
);
|
|
588
611
|
ctx.command("cave.listen").action(async ({ session }) => await getCaveListByUser(ctx, session));
|
|
589
612
|
ctx.command("cave.trace").action(
|
|
590
613
|
async ({ session }) => await getCaveListByOriginUser(ctx, session)
|
|
591
614
|
);
|
|
592
615
|
ctx.command("cave.bind <id:number> <...userIds>", { authority: 4 }).action(
|
|
593
|
-
async ({ session }, id, ...userIds) =>
|
|
594
|
-
ctx.logger.info(`Binding users ${JSON.stringify(userIds)} to cave ID ${id}`);
|
|
595
|
-
for (const uid of userIds) {
|
|
596
|
-
ctx.logger.info(`User ID to bind: ${uid}`);
|
|
597
|
-
ctx.logger.info(`userid type: ${typeof uid}`);
|
|
598
|
-
}
|
|
599
|
-
await bindUsersToCave(ctx, session, id, userIds);
|
|
600
|
-
}
|
|
616
|
+
async ({ session }, id, ...userIds) => await bindUsersToCave(ctx, session, id, userIds)
|
|
601
617
|
);
|
|
602
618
|
}
|
|
603
619
|
async function getCaveListByUser(ctx, session) {
|
|
@@ -704,6 +720,57 @@ async function deleteCave(ctx, session, cfg, id) {
|
|
|
704
720
|
await ctx.database.remove("echo_cave", id);
|
|
705
721
|
return session.text(".msgDeleted", [id]);
|
|
706
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
|
+
}
|
|
707
774
|
async function addCave(ctx, session, cfg, userIds) {
|
|
708
775
|
if (!session.guildId) {
|
|
709
776
|
return session.text("echo-cave.general.privateChatReminder");
|
|
@@ -800,6 +867,40 @@ async function bindUsersToCave(ctx, session, id, userIds) {
|
|
|
800
867
|
});
|
|
801
868
|
return session.text(".userBoundSuccess", [id]);
|
|
802
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
|
+
}
|
|
803
904
|
// Annotate the CommonJS export names for ESM import in node:
|
|
804
905
|
0 && (module.exports = {
|
|
805
906
|
Config,
|