koishi-plugin-fake-message 2.0.0 → 2.0.1

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.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Context, Schema } from 'koishi';
2
2
  export declare const name = "fake-message";
3
3
  export interface Config {
4
4
  blockedUsers: string[];
5
+ debug: boolean;
5
6
  }
6
7
  export declare const Config: Schema<Config>;
7
8
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -28,7 +28,8 @@ module.exports = __toCommonJS(src_exports);
28
28
  var import_koishi = require("koishi");
29
29
  var name = "fake-message";
30
30
  var Config = import_koishi.Schema.object({
31
- blockedUsers: import_koishi.Schema.array(import_koishi.Schema.string()).default([]).description("被屏蔽的用户ID列表")
31
+ blockedUsers: import_koishi.Schema.array(import_koishi.Schema.string()).default([]).description("被屏蔽的用户ID列表"),
32
+ debug: import_koishi.Schema.boolean().default(false).description("是否启用调试日志")
32
33
  });
33
34
  function parseMessages(elements, quotedContent) {
34
35
  const messages = [];
@@ -81,11 +82,24 @@ function apply(ctx, config) {
81
82
  if (!contentStr) {
82
83
  return "请输入要伪造的消息内容";
83
84
  }
85
+ const logger = session.app.logger("fake-message");
86
+ if (config.debug) {
87
+ logger.info(`[DEBUG] 原始 content: ${JSON.stringify(contentStr)}`);
88
+ logger.info(`[DEBUG] 包含换行符: ${contentStr.includes("\n")}, 包含\\r: ${contentStr.includes("\r")}`);
89
+ }
90
+ contentStr = contentStr.replace(/<br\s*\/?>/gi, "\n");
84
91
  contentStr = contentStr.replace(/(^|[\s])@(\d+)(?=$|[\s])/g, (match, prefix, id) => {
85
92
  return `${prefix}<at id="${id}"/>`;
86
93
  });
87
94
  contentStr = contentStr.replace(/(\n\s*)(<at)/g, "$1<message-boundary/>$2");
95
+ if (config.debug) {
96
+ logger.info(`[DEBUG] 处理后 content: ${JSON.stringify(contentStr)}`);
97
+ }
88
98
  const elements = import_koishi.h.parse(contentStr);
99
+ if (config.debug) {
100
+ logger.info(`[DEBUG] 解析后元素数量: ${elements.length}`);
101
+ logger.info(`[DEBUG] 元素类型: ${elements.map((e) => e.type).join(", ")}`);
102
+ }
89
103
  let quotedContent = null;
90
104
  if (session.quote) {
91
105
  if (session.quote.content) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-fake-message",
3
3
  "description": "伪造合并转发消息",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [