koishi-plugin-echo-cave 1.9.2 → 1.10.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.
Files changed (2) hide show
  1. package/lib/index.cjs +70 -89
  2. package/package.json +1 -1
package/lib/index.cjs CHANGED
@@ -33,14 +33,48 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
33
33
  var require_zh_CN = __commonJS({
34
34
  "src/locales/zh-CN.json"(exports2, module2) {
35
35
  module2.exports = {
36
- config: {
36
+ _config: {
37
37
  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",
38
38
  allowContributorDelete: "\u5141\u8BB8\u6295\u7A3F\u8005\u5220\u9664\u81EA\u5DF1\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E",
39
39
  allowSenderDelete: "\u5141\u8BB8\u539F\u59CB\u53D1\u9001\u8005\u5220\u9664\u88AB\u6295\u7A3F\u7684\u56DE\u58F0\u6D1E"
40
40
  },
41
- general: {
42
- privateChatReminder: "\u274C \u8BF7\u5728\u7FA4\u804A\u4E2D\u4F7F\u7528\u8BE5\u547D\u4EE4\uFF01",
43
- noMsgWithId: "\u{1F50D} \u672A\u627E\u5230\u8BE5 ID \u7684\u56DE\u58F0\u6D1E\u6D88\u606F"
41
+ "echo-cave": {
42
+ general: {
43
+ privateChatReminder: "\u274C \u8BF7\u5728\u7FA4\u804A\u4E2D\u4F7F\u7528\u8BE5\u547D\u4EE4\uFF01",
44
+ noMsgWithId: "\u{1F50D} \u672A\u627E\u5230\u8BE5 ID \u7684\u56DE\u58F0\u6D1E\u6D88\u606F",
45
+ noTemplatesConfigured: "\u274C \u672A\u914D\u7F6E\u56DE\u58F0\u6D1E\u6A21\u677F\uFF0C\u8BF7\u5148\u914D\u7F6E\u6A21\u677F\uFF01"
46
+ },
47
+ templates: {
48
+ forward: [
49
+ "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u4E00\u5219\u56DE\u58F0\u4ECE\u65F6\u5149\u4E2D\u98D8\u6765\u2014\u2014\n\u{1F4C5} {date} \xB7 \u6765\u81EA @{originName} \n\u{1F4EE} \u7531 @{userName} \u6295\u9012",
50
+ "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u3010\u8BB0\u5F55\u7F16\u53F7\u3011{id} \n\u3010\u521B\u5EFA\u65F6\u95F4\u3011{date} \n\u3010\u539F\u59CB\u4F5C\u8005\u3011@{originName} \n\u3010\u6295\u9012\u8005\u3011@{userName}",
51
+ "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u8FD9\u58F0\u56DE\u54CD\u6700\u521D\u6765\u81EA @{originName}\uFF0C \n\u7531 @{userName} \u5728 {date} \u7559\u4E0B\u3002",
52
+ "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u65F6\u95F4\u7684\u56DE\u97F3\u5728\u6B64\u6C47\u805A\u3002 \n\u{1F4C5} {date} \n\u{1F4E4} \u51FA\u5904\uFF1A@{originName} \n\u{1F4EE} \u5C01\u5370\u8005\uFF1A@{userName}",
53
+ "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u{1F4C5} {date} \n\u{1F464} \u6765\u81EA @{originName} \n\u{1F4EE} \u6295\u9012\u8005 @{userName}"
54
+ ],
55
+ msg: [
56
+ {
57
+ prefix: "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u2014\u2014 \u6709\u4EBA\u7559\u4E0B\u4E86\u58F0\u97F3 \u2014\u2014\n\n",
58
+ suffix: "\u{1F4C5} {date} \xB7 \u6765\u81EA @{originName}\n\u{1F4EE} \u7531 @{userName} \u6295\u9012"
59
+ },
60
+ {
61
+ prefix: "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n",
62
+ suffix: "\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\u{1F4C5} {date}\n\u{1F464} {originName} \xB7 \u7531 @{userName} \u6295\u9012"
63
+ },
64
+ {
65
+ prefix: "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u{1F4AD}\u300C\u6709\u4EBA\u5728\u6D1E\u58C1\u7559\u4E0B\u5370\u8BB0\u300D\n\n",
66
+ suffix: "\u{1F4C5} {date}\n\u{1F4EE} {userName} \u8BB0\u5F55"
67
+ },
68
+ {
69
+ prefix: "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n\u2014 \u56DE\u58F0\u5F00\u59CB \u2014\n\n",
70
+ suffix: "\u2014 \u56DE\u58F0\u7ED3\u675F \u2014\n\u{1F4C5} {date} \xB7 @{originName}\n\u{1F4EE} @{userName}"
71
+ },
72
+ {
73
+ prefix: "\u{1F300} \u56DE\u58F0\u6D1E #{id}\n\n",
74
+ suffix: "\u{1F4C5} {date}\n\u6765\u81EA @{originName}\n\u7531 @{userName} \u6295\u9012"
75
+ }
76
+ ]
77
+ }
44
78
  },
45
79
  commands: {
46
80
  cave: {
@@ -123,103 +157,50 @@ async function getUserName(ctx, session, userId) {
123
157
  }
124
158
 
125
159
  // src/cave-helper.ts
160
+ var random = (arr) => arr[Math.floor(Math.random() * arr.length)];
161
+ var replacePlaceholders = (template, data) => {
162
+ return template.replace(/{(\w+)}/g, (match, key) => data[key] || match);
163
+ };
126
164
  async function sendCaveMsg(ctx, session, caveMsg) {
127
165
  const { channelId } = session;
128
166
  const content = JSON.parse(caveMsg.content);
129
167
  const date = formatDate(caveMsg.createTime);
130
168
  const originName = await getUserName(ctx, session, caveMsg.originUserId);
131
169
  const userName = await getUserName(ctx, session, caveMsg.userId);
132
- const forwardStyles = [
133
- `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
134
-
135
- \u4E00\u5219\u56DE\u58F0\u4ECE\u65F6\u5149\u4E2D\u98D8\u6765\u2014\u2014
136
- \u{1F4C5} ${date} \xB7 \u6765\u81EA @${originName}
137
- \u{1F4EE} \u7531 @${userName} \u6295\u9012`,
138
- `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
139
-
140
- \u3010\u8BB0\u5F55\u7F16\u53F7\u3011${caveMsg.id}
141
- \u3010\u521B\u5EFA\u65F6\u95F4\u3011${date}
142
- \u3010\u539F\u59CB\u4F5C\u8005\u3011@${originName}
143
- \u3010\u6295\u9012\u8005\u3011@${userName}`,
144
- `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
145
-
146
- \u8FD9\u58F0\u56DE\u54CD\u6700\u521D\u6765\u81EA @${originName}\uFF0C
147
- \u7531 @${userName} \u5728 ${date} \u7559\u4E0B\u3002`,
148
- `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
149
-
150
- \u65F6\u95F4\u7684\u56DE\u97F3\u5728\u6B64\u6C47\u805A\u3002
151
- \u{1F4C5} ${date}
152
- \u{1F4E4} \u51FA\u5904\uFF1A@${originName}
153
- \u{1F4EE} \u5C01\u5370\u8005\uFF1A@${userName}`,
154
- `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
155
-
156
- \u{1F4C5} ${date}
157
- \u{1F464} \u6765\u81EA @${originName}
158
- \u{1F4EE} \u6295\u9012\u8005 @${userName}`
159
- ];
160
- const msgStyles = [
161
- {
162
- prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
163
-
164
- \u2014\u2014 \u6709\u4EBA\u7559\u4E0B\u4E86\u58F0\u97F3 \u2014\u2014
165
-
166
- `,
167
- suffix: `\u{1F4C5} ${date} \xB7 \u6765\u81EA @${originName}
168
- \u{1F4EE} \u7531 @${userName} \u6295\u9012`
169
- },
170
- {
171
- prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
172
- \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
173
- `,
174
- suffix: `\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
175
- \u{1F4C5} ${date}
176
- \u{1F464} ${originName} \xB7 \u7531 @${userName} \u6295\u9012`
177
- },
178
- {
179
- prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
180
-
181
- \u{1F4AD}\u300C\u6709\u4EBA\u5728\u6D1E\u58C1\u7559\u4E0B\u5370\u8BB0\u300D
182
-
183
- `,
184
- suffix: `\u{1F4C5} ${date}
185
- \u{1F4EE} ${userName} \u8BB0\u5F55`
186
- },
187
- {
188
- prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
189
-
190
- \u2014 \u56DE\u58F0\u5F00\u59CB \u2014
191
-
192
- `,
193
- suffix: `\u2014 \u56DE\u58F0\u7ED3\u675F \u2014
194
- \u{1F4C5} ${date} \xB7 @${originName}
195
- \u{1F4EE} @${userName}`
196
- },
197
- {
198
- prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
199
-
200
- `,
201
- suffix: `\u{1F4C5} ${date}
202
- \u6765\u81EA @${originName}
203
- \u7531 @${userName} \u6295\u9012`
204
- }
205
- ];
206
- const random = (arr) => arr[Math.floor(Math.random() * arr.length)];
170
+ const templateData = {
171
+ id: caveMsg.id.toString(),
172
+ date,
173
+ originName,
174
+ userName
175
+ };
176
+ const templates = require_zh_CN()["echo-cave"].templates;
207
177
  if (caveMsg.type === "forward") {
208
- const chosen2 = random(forwardStyles);
209
- await session.onebot.sendGroupMsg(channelId, [createTextMsg(chosen2)]);
178
+ const forwardTemplates = (templates.forward || []).filter(
179
+ (template) => template.trim() !== ""
180
+ );
181
+ if (forwardTemplates.length === 0) {
182
+ await session.send(session.text("echo-cave.general.noTemplatesConfigured"));
183
+ return;
184
+ }
185
+ const chosenTemplate2 = replacePlaceholders(random(forwardTemplates), templateData);
186
+ await session.onebot.sendGroupMsg(channelId, [createTextMsg(chosenTemplate2)]);
210
187
  await session.onebot.sendGroupForwardMsg(channelId, content);
211
188
  return;
212
- } else if (caveMsg.type == "msg" && content.some((m) => m.type === "reply")) {
213
- const chosen2 = random(forwardStyles);
214
- await session.onebot.sendGroupMsg(channelId, [createTextMsg(chosen2)]);
215
- await session.onebot.sendGroupMsg(channelId, content);
189
+ }
190
+ const msgTemplates = (templates.msg || []).filter(
191
+ (template) => template && template.prefix?.trim() !== "" && template.suffix?.trim() !== ""
192
+ );
193
+ if (msgTemplates.length === 0) {
194
+ await session.send(session.text("echo-cave.general.noTemplatesConfigured"));
216
195
  return;
217
196
  }
218
- const chosen = random(msgStyles);
197
+ const chosenTemplate = random(msgTemplates);
198
+ const prefix = replacePlaceholders(chosenTemplate.prefix, templateData);
199
+ const suffix = replacePlaceholders(chosenTemplate.suffix, templateData);
219
200
  const last = content.at(-1);
220
201
  const needsNewline = last?.type === "text";
221
- content.unshift(createTextMsg(chosen.prefix));
222
- content.push(createTextMsg(`${needsNewline ? "\n\n" : ""}${chosen.suffix}`));
202
+ content.unshift(createTextMsg(prefix));
203
+ content.push(createTextMsg(`${needsNewline ? "\n\n" : ""}${suffix}`));
223
204
  await session.onebot.sendGroupMsg(channelId, content);
224
205
  }
225
206
  function formatDate(date) {
@@ -349,7 +330,7 @@ var Config = import_koishi.Schema.object({
349
330
  allowContributorDelete: import_koishi.Schema.boolean().default(true),
350
331
  allowSenderDelete: import_koishi.Schema.boolean().default(true)
351
332
  }).i18n({
352
- "zh-CN": require_zh_CN().config
333
+ "zh-CN": require_zh_CN()._config
353
334
  });
354
335
  function apply(ctx, cfg) {
355
336
  ctx.i18n.define("zh-CN", require_zh_CN());
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.9.2",
4
+ "version": "1.10.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",