koishi-plugin-echo-cave 1.24.7 → 1.24.9

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.
@@ -1,5 +1,40 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name2 in all)
9
+ __defProp(target, name2, { get: all[name2], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
1
29
  // src/index.ts
2
- import "@pynickle/koishi-plugin-adapter-onebot";
30
+ var index_exports = {};
31
+ __export(index_exports, {
32
+ Config: () => Config,
33
+ apply: () => apply,
34
+ inject: () => inject,
35
+ name: () => name
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
3
38
 
4
39
  // src/adapters/onebot/user.ts
5
40
  async function getUserIdFromNickname(session, nickname, userId) {
@@ -31,7 +66,7 @@ async function checkUsersInGroup(ctx, session, userIds) {
31
66
  }
32
67
 
33
68
  // src/utils/msg/element-helper.ts
34
- import { h } from "koishi";
69
+ var import_koishi = require("koishi");
35
70
  function parseUserIds(userIds) {
36
71
  const parsedUserIds = [];
37
72
  for (const userId of typeof userIds === "string" ? [userIds] : userIds) {
@@ -40,7 +75,7 @@ function parseUserIds(userIds) {
40
75
  parsedUserIds.push(userId);
41
76
  continue;
42
77
  }
43
- const element = h.parse(userId);
78
+ const element = import_koishi.h.parse(userId);
44
79
  if (element.length === 1 && element[0].type === "at") {
45
80
  const userId2 = element[0].attrs.id;
46
81
  if (userId2 === "all") {
@@ -58,10 +93,10 @@ function parseUserIds(userIds) {
58
93
  }
59
94
 
60
95
  // src/utils/media/media-helper.ts
61
- import axios from "axios";
62
- import { promises as fs } from "node:fs";
63
- import path from "node:path";
64
- import { v4 as uuidv4 } from "uuid";
96
+ var import_axios = __toESM(require("axios"), 1);
97
+ var import_node_fs = require("node:fs");
98
+ var import_node_path = __toESM(require("node:path"), 1);
99
+ var import_uuid = require("uuid");
65
100
  async function saveMedia(ctx, mediaElement, type, cfg) {
66
101
  const mediaUrl = mediaElement.url;
67
102
  const originalMediaName = mediaElement.file;
@@ -69,13 +104,13 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
69
104
  const i = originalMediaName.lastIndexOf(".");
70
105
  return i === -1 ? type === "image" ? "png" : type === "video" ? "mp4" : type === "record" ? "mp3" : "bin" : originalMediaName.slice(i + 1).toLowerCase();
71
106
  })();
72
- const mediaDir = path.join(ctx.baseDir, "data", "cave", type + "s");
73
- const mediaName = uuidv4().replace(/-/g, "");
74
- const fullMediaPath = path.join(mediaDir, `${mediaName}.${ext}`);
107
+ const mediaDir = import_node_path.default.join(ctx.baseDir, "data", "cave", type + "s");
108
+ const mediaName = (0, import_uuid.v4)().replace(/-/g, "");
109
+ const fullMediaPath = import_node_path.default.join(mediaDir, `${mediaName}.${ext}`);
75
110
  ctx.logger.info(`Saving ${type} from ${mediaUrl} -> ${fullMediaPath}`);
76
111
  try {
77
- await fs.mkdir(mediaDir, { recursive: true });
78
- const res = await axios.get(mediaUrl, {
112
+ await import_node_fs.promises.mkdir(mediaDir, { recursive: true });
113
+ const res = await import_axios.default.get(mediaUrl, {
79
114
  responseType: "arraybuffer",
80
115
  validateStatus: () => true
81
116
  });
@@ -105,7 +140,7 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
105
140
  ctx.logger.warn(`Downloaded ${type} buffer is empty`);
106
141
  return mediaUrl;
107
142
  }
108
- await fs.writeFile(fullMediaPath, buffer);
143
+ await import_node_fs.promises.writeFile(fullMediaPath, buffer);
109
144
  ctx.logger.info(
110
145
  `${type.charAt(0).toUpperCase() + type.slice(1)} saved successfully: ${fullMediaPath}`
111
146
  );
@@ -142,7 +177,7 @@ async function convertFileUriToBase64(ctx, element) {
142
177
  const fileUri = element.data.file;
143
178
  const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
144
179
  try {
145
- const buffer = await fs.readFile(filePath);
180
+ const buffer = await import_node_fs.promises.readFile(filePath);
146
181
  const base64 = buffer.toString("base64");
147
182
  const mimeTypes = {
148
183
  image: "image/jpeg",
@@ -183,7 +218,7 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
183
218
  if (!cfg.enableSizeLimit) {
184
219
  return;
185
220
  }
186
- const mediaDir = path.join(ctx.baseDir, "data", "cave", type + "s");
221
+ const mediaDir = import_node_path.default.join(ctx.baseDir, "data", "cave", type + "s");
187
222
  const maxSize = (() => {
188
223
  switch (type) {
189
224
  case "image":
@@ -198,14 +233,14 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
198
233
  }
199
234
  })();
200
235
  try {
201
- const files = await fs.readdir(mediaDir);
236
+ const files = await import_node_fs.promises.readdir(mediaDir);
202
237
  if (files.length === 0) {
203
238
  return;
204
239
  }
205
240
  const fileInfos = await Promise.all(
206
241
  files.map(async (file) => {
207
- const filePath = path.join(mediaDir, file);
208
- const stats = await fs.stat(filePath);
242
+ const filePath = import_node_path.default.join(mediaDir, file);
243
+ const stats = await import_node_fs.promises.stat(filePath);
209
244
  return {
210
245
  path: filePath,
211
246
  size: stats.size,
@@ -232,9 +267,9 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
232
267
  currentSize -= file.size;
233
268
  }
234
269
  for (const file of filesToDelete) {
235
- await fs.unlink(file.path);
270
+ await import_node_fs.promises.unlink(file.path);
236
271
  ctx.logger.info(
237
- `Deleted oldest ${type} file: ${path.basename(file.path)} (${(file.size / (1024 * 1024)).toFixed(2)} MB)`
272
+ `Deleted oldest ${type} file: ${import_node_path.default.basename(file.path)} (${(file.size / (1024 * 1024)).toFixed(2)} MB)`
238
273
  );
239
274
  }
240
275
  ctx.logger.info(
@@ -252,8 +287,8 @@ async function deleteMediaFilesFromMessage(ctx, content) {
252
287
  if (fileUri && fileUri.startsWith("file:///")) {
253
288
  const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
254
289
  try {
255
- await fs.access(filePath);
256
- await fs.unlink(filePath);
290
+ await import_node_fs.promises.access(filePath);
291
+ await import_node_fs.promises.unlink(filePath);
257
292
  ctx.logger.info(`Deleted media file: ${filePath}`);
258
293
  } catch (err) {
259
294
  ctx.logger.warn(`Failed to delete media file: ${filePath}, error: ${err}`);
@@ -323,7 +358,7 @@ async function processMessageContent(ctx, msg, cfg) {
323
358
  }
324
359
 
325
360
  // src/core/command/add-cave.ts
326
- import { CQCode } from "@pynickle/koishi-plugin-adapter-onebot";
361
+ var import_koishi_plugin_adapter_onebot = require("@pynickle/koishi-plugin-adapter-onebot");
327
362
  async function addCave(ctx, session, cfg, userIds) {
328
363
  if (!session.guildId) {
329
364
  return session.text("echo-cave.general.privateChatReminder");
@@ -363,7 +398,7 @@ async function addCave(ctx, session, cfg, userIds) {
363
398
  const message = (await session.onebot.getMsg(messageId)).message;
364
399
  let msgJson;
365
400
  if (typeof message === "string") {
366
- msgJson = CQCode.parse(message);
401
+ msgJson = import_koishi_plugin_adapter_onebot.CQCode.parse(message);
367
402
  } else {
368
403
  if (message[0].type === "video" || message[0].type === "file") {
369
404
  type = "forward";
@@ -1027,20 +1062,20 @@ var zh_CN_default2 = {
1027
1062
  };
1028
1063
 
1029
1064
  // src/config/config.ts
1030
- import { Schema } from "koishi";
1031
- var Config = Schema.object({
1032
- adminMessageProtection: Schema.boolean().default(false),
1033
- allowContributorDelete: Schema.boolean().default(true),
1034
- allowSenderDelete: Schema.boolean().default(true),
1035
- deleteMediaWhenDeletingMsg: Schema.boolean().default(true),
1036
- enableSizeLimit: Schema.boolean().default(false),
1037
- maxImageSize: Schema.number().default(2048),
1038
- maxVideoSize: Schema.number().default(512),
1039
- maxFileSize: Schema.number().default(512),
1040
- maxRecordSize: Schema.number().default(512),
1041
- useBase64ForMedia: Schema.boolean().default(false),
1042
- sendAllAsForwardMsg: Schema.boolean().default(false),
1043
- rankingTopCount: Schema.number().default(10)
1065
+ var import_koishi2 = require("koishi");
1066
+ var Config = import_koishi2.Schema.object({
1067
+ adminMessageProtection: import_koishi2.Schema.boolean().default(false),
1068
+ allowContributorDelete: import_koishi2.Schema.boolean().default(true),
1069
+ allowSenderDelete: import_koishi2.Schema.boolean().default(true),
1070
+ deleteMediaWhenDeletingMsg: import_koishi2.Schema.boolean().default(true),
1071
+ enableSizeLimit: import_koishi2.Schema.boolean().default(false),
1072
+ maxImageSize: import_koishi2.Schema.number().default(2048),
1073
+ maxVideoSize: import_koishi2.Schema.number().default(512),
1074
+ maxFileSize: import_koishi2.Schema.number().default(512),
1075
+ maxRecordSize: import_koishi2.Schema.number().default(512),
1076
+ useBase64ForMedia: import_koishi2.Schema.boolean().default(false),
1077
+ sendAllAsForwardMsg: import_koishi2.Schema.boolean().default(false),
1078
+ rankingTopCount: import_koishi2.Schema.number().default(10)
1044
1079
  }).i18n({
1045
1080
  "zh-CN": zh_CN_default2
1046
1081
  });
@@ -1120,9 +1155,10 @@ function apply(ctx, cfg) {
1120
1155
  async ({ session }, period) => await getRanking(ctx, session, cfg, period)
1121
1156
  );
1122
1157
  }
1123
- export {
1158
+ // Annotate the CommonJS export names for ESM import in node:
1159
+ 0 && (module.exports = {
1124
1160
  Config,
1125
1161
  apply,
1126
1162
  inject,
1127
1163
  name
1128
- };
1164
+ });
package/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import '@pynickle/koishi-plugin-adapter-onebot';
2
1
  import { Config } from './config/config';
3
2
  import { Context } from 'koishi';
4
3
  export declare const name = "echo-cave";
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "koishi-plugin-echo-cave",
3
3
  "description": "Group echo cave",
4
- "version": "1.24.7",
5
- "main": "lib/index.js",
4
+ "version": "1.24.9",
5
+ "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",
8
8
  "files": [
@@ -32,9 +32,9 @@
32
32
  "koishi": "^4.18.9"
33
33
  },
34
34
  "dependencies": {
35
- "@pynickle/koishi-plugin-adapter-onebot": "^1.0.0",
36
35
  "axios": "^1.13.2",
37
- "uuid": "^13.0.0"
36
+ "uuid": "^11.1.0",
37
+ "@pynickle/koishi-plugin-adapter-onebot": "^1.0.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@semantic-release/changelog": "^6.0.3",