koishi-plugin-echo-cave 1.18.6 → 1.19.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 CHANGED
@@ -540,13 +540,13 @@ async function addCave(ctx, session, cfg, userIds) {
540
540
  }
541
541
  content = JSON.stringify(await processMessageContent(ctx, msgJson, cfg));
542
542
  }
543
- await ctx.database.get("echo_cave", { content }).then((existing) => {
543
+ await ctx.database.get("echo_cave_v2", { content }).then((existing) => {
544
544
  if (existing) {
545
545
  return session.text(".existingMsg");
546
546
  }
547
547
  });
548
548
  try {
549
- const result = await ctx.database.create("echo_cave", {
549
+ const result = await ctx.database.create("echo_cave_v2", {
550
550
  channelId,
551
551
  createTime: /* @__PURE__ */ new Date(),
552
552
  userId,
@@ -569,7 +569,7 @@ async function deleteCave(ctx, session, cfg, id) {
569
569
  if (!id) {
570
570
  return session.text(".noIdProvided");
571
571
  }
572
- const caves = await ctx.database.get("echo_cave", id);
572
+ const caves = await ctx.database.get("echo_cave_v2", id);
573
573
  if (caves.length === 0) {
574
574
  return session.text("echo-cave.general.noMsgWithId");
575
575
  }
@@ -601,7 +601,7 @@ async function deleteCave(ctx, session, cfg, id) {
601
601
  if (cfg.deleteMediaWhenDeletingMsg) {
602
602
  await deleteMediaFilesFromMessage(ctx, caveMsg.content);
603
603
  }
604
- await ctx.database.remove("echo_cave", id);
604
+ await ctx.database.remove("echo_cave_v2", id);
605
605
  return session.text(".msgDeleted", [id]);
606
606
  }
607
607
  async function deleteCaves(ctx, session, cfg, ids) {
@@ -616,7 +616,7 @@ async function deleteCaves(ctx, session, cfg, ids) {
616
616
  const user = await ctx.database.getUser(session.platform, currentUserId);
617
617
  const userAuthority = user.authority;
618
618
  const isCurrentUserAdmin = userAuthority >= 4;
619
- const caves = await ctx.database.get("echo_cave", ids);
619
+ const caves = await ctx.database.get("echo_cave_v2", ids);
620
620
  for (const cave of caves) {
621
621
  const caveMsg = caves[0];
622
622
  if (cfg.adminMessageProtection) {
@@ -642,7 +642,7 @@ async function deleteCaves(ctx, session, cfg, ids) {
642
642
  if (cfg.deleteMediaWhenDeletingMsg) {
643
643
  await deleteMediaFilesFromMessage(ctx, caveMsg.content);
644
644
  }
645
- await ctx.database.remove("echo_cave", cave.id);
645
+ await ctx.database.remove("echo_cave_v2", cave.id);
646
646
  }
647
647
  const foundIds = new Set(caves.map((r) => r.id));
648
648
  const missingIds = ids.filter((id) => !foundIds.has(id));
@@ -745,7 +745,7 @@ async function getCaveListByUser(ctx, session) {
745
745
  }
746
746
  const { userId, channelId } = session;
747
747
  const caves = await ctx.database.get(
748
- "echo_cave",
748
+ "echo_cave_v2",
749
749
  {
750
750
  userId,
751
751
  channelId
@@ -764,7 +764,7 @@ async function getCaveListByOriginUser(ctx, session) {
764
764
  }
765
765
  const { userId, channelId } = session;
766
766
  const caves = await ctx.database.get(
767
- "echo_cave",
767
+ "echo_cave_v2",
768
768
  {
769
769
  originUserId: userId,
770
770
  channelId
@@ -784,7 +784,7 @@ async function getCave(ctx, session, cfg, id) {
784
784
  let caveMsg;
785
785
  const { channelId } = session;
786
786
  if (!id) {
787
- const caves = await ctx.database.get("echo_cave", {
787
+ const caves = await ctx.database.get("echo_cave_v2", {
788
788
  channelId
789
789
  });
790
790
  if (caves.length === 0) {
@@ -792,7 +792,7 @@ async function getCave(ctx, session, cfg, id) {
792
792
  }
793
793
  caveMsg = caves[Math.floor(Math.random() * caves.length)];
794
794
  } else {
795
- const caves = await ctx.database.get("echo_cave", {
795
+ const caves = await ctx.database.get("echo_cave_v2", {
796
796
  id,
797
797
  channelId
798
798
  });
@@ -823,7 +823,7 @@ async function bindUsersToCave(ctx, session, id, userIds) {
823
823
  if (parsedUserIds.length === 0) {
824
824
  return session.text(".noValidUserIdProvided");
825
825
  }
826
- const caves = await ctx.database.get("echo_cave", id);
826
+ const caves = await ctx.database.get("echo_cave_v2", id);
827
827
  if (caves.length === 0) {
828
828
  return session.text("echo-cave.general.noMsgWithId");
829
829
  }
@@ -831,7 +831,7 @@ async function bindUsersToCave(ctx, session, id, userIds) {
831
831
  if (!isAllUsersInGroup) {
832
832
  return session.text("echo-cave.user.userNotInGroup");
833
833
  }
834
- await ctx.database.set("echo_cave", id, {
834
+ await ctx.database.set("echo_cave_v2", id, {
835
835
  relatedUsers: parsedUserIds
836
836
  });
837
837
  return session.text(".userBoundSuccess", [id]);
@@ -859,7 +859,7 @@ async function searchCave(ctx, session, userIds) {
859
859
  }
860
860
  const targetUserId = parsedUserIds[0];
861
861
  const { channelId } = session;
862
- const caves = await ctx.database.get("echo_cave", {
862
+ const caves = await ctx.database.get("echo_cave_v2", {
863
863
  channelId
864
864
  });
865
865
  const matchingCaves = caves.filter(
@@ -912,6 +912,33 @@ function apply(ctx, cfg) {
912
912
  autoInc: true
913
913
  }
914
914
  );
915
+ ctx.model.extend(
916
+ "echo_cave_v2",
917
+ {
918
+ id: "unsigned",
919
+ channelId: "string",
920
+ createTime: "timestamp",
921
+ userId: "string",
922
+ originUserId: "string",
923
+ type: "string",
924
+ content: "text",
925
+ relatedUsers: "list"
926
+ },
927
+ {
928
+ primary: "id",
929
+ autoInc: true
930
+ }
931
+ );
932
+ ctx.model.migrate(
933
+ "echo_cave",
934
+ {
935
+ id: "unsigned"
936
+ },
937
+ async (database) => {
938
+ const data = await database.get("echo_cave", {});
939
+ await database.upsert("echo_cave_v2", data);
940
+ }
941
+ );
915
942
  ctx.command("cave [id:number]").action(
916
943
  async ({ session }, id) => await getCave(ctx, session, cfg, id)
917
944
  );
package/lib/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export interface EchoCave {
17
17
  declare module 'koishi' {
18
18
  interface Tables {
19
19
  echo_cave: EchoCave;
20
+ echo_cave_v2: EchoCave;
20
21
  }
21
22
  }
22
23
  export declare function apply(ctx: Context, cfg: Config): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.18.6",
4
+ "version": "1.19.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",