koishi-plugin-echo-cave 1.24.4 → 1.24.5

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,38 +1,12 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
1
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
2
  var __commonJS = (cb, mod) => function __require() {
8
3
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
4
  };
10
- var __export = (target, all) => {
11
- for (var name2 in all)
12
- __defProp(target, name2, { get: all[name2], enumerable: true });
13
- };
14
- var __copyProps = (to, from, except, desc) => {
15
- if (from && typeof from === "object" || typeof from === "function") {
16
- for (let key of __getOwnPropNames(from))
17
- if (!__hasOwnProp.call(to, key) && key !== except)
18
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
- // If the importer is in node compatibility mode or this is not an ESM
24
- // file that has been converted to a CommonJS file using a Babel-
25
- // compatible transform (i.e. "__esModule" has not been set), then set
26
- // "default" to the CommonJS "module.exports" for node compatibility.
27
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
- mod
29
- ));
30
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
5
 
32
6
  // src/config/locales/zh-CN.json
33
7
  var require_zh_CN = __commonJS({
34
- "src/config/locales/zh-CN.json"(exports2, module2) {
35
- module2.exports = {
8
+ "src/config/locales/zh-CN.json"(exports, module) {
9
+ module.exports = {
36
10
  adminMessageProtection: "\u5F00\u542F\u7BA1\u7406\u5458\u6D88\u606F\u4FDD\u62A4\uFF0C\u5F00\u542F\u540E\u7BA1\u7406\u5458\u53D1\u5E03\u7684\u6D88\u606F\u53EA\u80FD\u7531\u7BA1\u7406\u5458\u5220\u9664",
37
11
  allowContributorDelete: "\u5141\u8BB8\u6295\u7A3F\u8005\u5220\u9664\u81EA\u5DF1\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E",
38
12
  allowSenderDelete: "\u5141\u8BB8\u539F\u59CB\u53D1\u9001\u8005\u5220\u9664\u88AB\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E",
@@ -51,8 +25,8 @@ var require_zh_CN = __commonJS({
51
25
 
52
26
  // src/locales/zh-CN.json
53
27
  var require_zh_CN2 = __commonJS({
54
- "src/locales/zh-CN.json"(exports2, module2) {
55
- module2.exports = {
28
+ "src/locales/zh-CN.json"(exports, module) {
29
+ module.exports = {
56
30
  _config: {
57
31
  adminMessageProtection: "\u5F00\u542F\u7BA1\u7406\u5458\u6D88\u606F\u4FDD\u62A4\uFF0C\u5F00\u542F\u540E\u7BA1\u7406\u5458\u53D1\u5E03\u7684\u6D88\u606F\u53EA\u80FD\u7531\u7BA1\u7406\u5458\u5220\u9664",
58
32
  allowContributorDelete: "\u5141\u8BB8\u6295\u7A3F\u8005\u5220\u9664\u81EA\u5DF1\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E",
@@ -199,15 +173,7 @@ var require_zh_CN2 = __commonJS({
199
173
  });
200
174
 
201
175
  // src/index.ts
202
- var index_exports = {};
203
- __export(index_exports, {
204
- Config: () => Config,
205
- apply: () => apply,
206
- inject: () => inject,
207
- name: () => name
208
- });
209
- module.exports = __toCommonJS(index_exports);
210
- var import_koishi_plugin_adapter_onebot2 = require("@pynickle/koishi-plugin-adapter-onebot");
176
+ import "@pynickle/koishi-plugin-adapter-onebot";
211
177
 
212
178
  // src/adapters/onebot/user.ts
213
179
  async function getUserIdFromNickname(session, nickname, userId) {
@@ -239,7 +205,7 @@ async function checkUsersInGroup(ctx, session, userIds) {
239
205
  }
240
206
 
241
207
  // src/utils/msg/element-helper.ts
242
- var import_koishi = require("koishi");
208
+ import { h } from "koishi";
243
209
  function parseUserIds(userIds) {
244
210
  const parsedUserIds = [];
245
211
  for (const userId of typeof userIds === "string" ? [userIds] : userIds) {
@@ -248,7 +214,7 @@ function parseUserIds(userIds) {
248
214
  parsedUserIds.push(userId);
249
215
  continue;
250
216
  }
251
- const element = import_koishi.h.parse(userId);
217
+ const element = h.parse(userId);
252
218
  if (element.length === 1 && element[0].type === "at") {
253
219
  const userId2 = element[0].attrs.id;
254
220
  if (userId2 === "all") {
@@ -266,10 +232,10 @@ function parseUserIds(userIds) {
266
232
  }
267
233
 
268
234
  // src/utils/media/media-helper.ts
269
- var import_axios = __toESM(require("axios"), 1);
270
- var import_node_fs = require("node:fs");
271
- var import_node_path = __toESM(require("node:path"), 1);
272
- var import_uuid = require("uuid");
235
+ import axios from "axios";
236
+ import { promises as fs } from "node:fs";
237
+ import path from "node:path";
238
+ import { v4 as uuidv4 } from "uuid";
273
239
  async function saveMedia(ctx, mediaElement, type, cfg) {
274
240
  const mediaUrl = mediaElement.url;
275
241
  const originalMediaName = mediaElement.file;
@@ -277,13 +243,13 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
277
243
  const i = originalMediaName.lastIndexOf(".");
278
244
  return i === -1 ? type === "image" ? "png" : type === "video" ? "mp4" : type === "record" ? "mp3" : "bin" : originalMediaName.slice(i + 1).toLowerCase();
279
245
  })();
280
- const mediaDir = import_node_path.default.join(ctx.baseDir, "data", "cave", type + "s");
281
- const mediaName = (0, import_uuid.v4)().replace(/-/g, "");
282
- const fullMediaPath = import_node_path.default.join(mediaDir, `${mediaName}.${ext}`);
246
+ const mediaDir = path.join(ctx.baseDir, "data", "cave", type + "s");
247
+ const mediaName = uuidv4().replace(/-/g, "");
248
+ const fullMediaPath = path.join(mediaDir, `${mediaName}.${ext}`);
283
249
  ctx.logger.info(`Saving ${type} from ${mediaUrl} -> ${fullMediaPath}`);
284
250
  try {
285
- await import_node_fs.promises.mkdir(mediaDir, { recursive: true });
286
- const res = await import_axios.default.get(mediaUrl, {
251
+ await fs.mkdir(mediaDir, { recursive: true });
252
+ const res = await axios.get(mediaUrl, {
287
253
  responseType: "arraybuffer",
288
254
  validateStatus: () => true
289
255
  });
@@ -313,7 +279,7 @@ async function saveMedia(ctx, mediaElement, type, cfg) {
313
279
  ctx.logger.warn(`Downloaded ${type} buffer is empty`);
314
280
  return mediaUrl;
315
281
  }
316
- await import_node_fs.promises.writeFile(fullMediaPath, buffer);
282
+ await fs.writeFile(fullMediaPath, buffer);
317
283
  ctx.logger.info(
318
284
  `${type.charAt(0).toUpperCase() + type.slice(1)} saved successfully: ${fullMediaPath}`
319
285
  );
@@ -350,7 +316,7 @@ async function convertFileUriToBase64(ctx, element) {
350
316
  const fileUri = element.data.file;
351
317
  const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
352
318
  try {
353
- const buffer = await import_node_fs.promises.readFile(filePath);
319
+ const buffer = await fs.readFile(filePath);
354
320
  const base64 = buffer.toString("base64");
355
321
  const mimeTypes = {
356
322
  image: "image/jpeg",
@@ -391,7 +357,7 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
391
357
  if (!cfg.enableSizeLimit) {
392
358
  return;
393
359
  }
394
- const mediaDir = import_node_path.default.join(ctx.baseDir, "data", "cave", type + "s");
360
+ const mediaDir = path.join(ctx.baseDir, "data", "cave", type + "s");
395
361
  const maxSize = (() => {
396
362
  switch (type) {
397
363
  case "image":
@@ -406,14 +372,14 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
406
372
  }
407
373
  })();
408
374
  try {
409
- const files = await import_node_fs.promises.readdir(mediaDir);
375
+ const files = await fs.readdir(mediaDir);
410
376
  if (files.length === 0) {
411
377
  return;
412
378
  }
413
379
  const fileInfos = await Promise.all(
414
380
  files.map(async (file) => {
415
- const filePath = import_node_path.default.join(mediaDir, file);
416
- const stats = await import_node_fs.promises.stat(filePath);
381
+ const filePath = path.join(mediaDir, file);
382
+ const stats = await fs.stat(filePath);
417
383
  return {
418
384
  path: filePath,
419
385
  size: stats.size,
@@ -440,9 +406,9 @@ async function checkAndCleanMediaFiles(ctx, cfg, type) {
440
406
  currentSize -= file.size;
441
407
  }
442
408
  for (const file of filesToDelete) {
443
- await import_node_fs.promises.unlink(file.path);
409
+ await fs.unlink(file.path);
444
410
  ctx.logger.info(
445
- `Deleted oldest ${type} file: ${import_node_path.default.basename(file.path)} (${(file.size / (1024 * 1024)).toFixed(2)} MB)`
411
+ `Deleted oldest ${type} file: ${path.basename(file.path)} (${(file.size / (1024 * 1024)).toFixed(2)} MB)`
446
412
  );
447
413
  }
448
414
  ctx.logger.info(
@@ -460,8 +426,8 @@ async function deleteMediaFilesFromMessage(ctx, content) {
460
426
  if (fileUri && fileUri.startsWith("file:///")) {
461
427
  const filePath = decodeURIComponent(fileUri.replace("file:///", ""));
462
428
  try {
463
- await import_node_fs.promises.access(filePath);
464
- await import_node_fs.promises.unlink(filePath);
429
+ await fs.access(filePath);
430
+ await fs.unlink(filePath);
465
431
  ctx.logger.info(`Deleted media file: ${filePath}`);
466
432
  } catch (err) {
467
433
  ctx.logger.warn(`Failed to delete media file: ${filePath}, error: ${err}`);
@@ -531,7 +497,7 @@ async function processMessageContent(ctx, msg, cfg) {
531
497
  }
532
498
 
533
499
  // src/core/command/add-cave.ts
534
- var import_koishi_plugin_adapter_onebot = require("@pynickle/koishi-plugin-adapter-onebot");
500
+ import { CQCode } from "@pynickle/koishi-plugin-adapter-onebot";
535
501
  async function addCave(ctx, session, cfg, userIds) {
536
502
  if (!session.guildId) {
537
503
  return session.text("echo-cave.general.privateChatReminder");
@@ -571,7 +537,7 @@ async function addCave(ctx, session, cfg, userIds) {
571
537
  const message = (await session.onebot.getMsg(messageId)).message;
572
538
  let msgJson;
573
539
  if (typeof message === "string") {
574
- msgJson = import_koishi_plugin_adapter_onebot.CQCode.parse(message);
540
+ msgJson = CQCode.parse(message);
575
541
  } else {
576
542
  if (message[0].type === "video" || message[0].type === "file") {
577
543
  type = "forward";
@@ -1100,20 +1066,20 @@ async function searchCave(ctx, session, userIds) {
1100
1066
  }
1101
1067
 
1102
1068
  // src/config/config.ts
1103
- var import_koishi2 = require("koishi");
1104
- var Config = import_koishi2.Schema.object({
1105
- adminMessageProtection: import_koishi2.Schema.boolean().default(false),
1106
- allowContributorDelete: import_koishi2.Schema.boolean().default(true),
1107
- allowSenderDelete: import_koishi2.Schema.boolean().default(true),
1108
- deleteMediaWhenDeletingMsg: import_koishi2.Schema.boolean().default(true),
1109
- enableSizeLimit: import_koishi2.Schema.boolean().default(false),
1110
- maxImageSize: import_koishi2.Schema.number().default(2048),
1111
- maxVideoSize: import_koishi2.Schema.number().default(512),
1112
- maxFileSize: import_koishi2.Schema.number().default(512),
1113
- maxRecordSize: import_koishi2.Schema.number().default(512),
1114
- useBase64ForMedia: import_koishi2.Schema.boolean().default(false),
1115
- sendAllAsForwardMsg: import_koishi2.Schema.boolean().default(false),
1116
- rankingTopCount: import_koishi2.Schema.number().default(10)
1069
+ import { Schema } from "koishi";
1070
+ var Config = Schema.object({
1071
+ adminMessageProtection: Schema.boolean().default(false),
1072
+ allowContributorDelete: Schema.boolean().default(true),
1073
+ allowSenderDelete: Schema.boolean().default(true),
1074
+ deleteMediaWhenDeletingMsg: Schema.boolean().default(true),
1075
+ enableSizeLimit: Schema.boolean().default(false),
1076
+ maxImageSize: Schema.number().default(2048),
1077
+ maxVideoSize: Schema.number().default(512),
1078
+ maxFileSize: Schema.number().default(512),
1079
+ maxRecordSize: Schema.number().default(512),
1080
+ useBase64ForMedia: Schema.boolean().default(false),
1081
+ sendAllAsForwardMsg: Schema.boolean().default(false),
1082
+ rankingTopCount: Schema.number().default(10)
1117
1083
  }).i18n({
1118
1084
  "zh-CN": require_zh_CN()
1119
1085
  });
@@ -1193,10 +1159,9 @@ function apply(ctx, cfg) {
1193
1159
  async ({ session }, period) => await getRanking(ctx, session, cfg, period)
1194
1160
  );
1195
1161
  }
1196
- // Annotate the CommonJS export names for ESM import in node:
1197
- 0 && (module.exports = {
1162
+ export {
1198
1163
  Config,
1199
1164
  apply,
1200
1165
  inject,
1201
1166
  name
1202
- });
1167
+ };
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.4",
5
- "main": "lib/index.cjs",
4
+ "version": "1.24.5",
5
+ "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",
8
8
  "files": [