koishi-plugin-echo-cave 1.3.2 → 1.4.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.
@@ -0,0 +1,6 @@
1
+ export declare function createTextMsg(content: string): {
2
+ type: string;
3
+ data: {
4
+ text: string;
5
+ };
6
+ };
package/lib/index.cjs CHANGED
@@ -105,16 +105,134 @@ async function processMessageContent(ctx, msg) {
105
105
  );
106
106
  }
107
107
 
108
+ // src/cqcode-helper.ts
109
+ function createTextMsg(content) {
110
+ return {
111
+ type: "text",
112
+ data: {
113
+ text: content
114
+ }
115
+ };
116
+ }
117
+
118
+ // src/onebot-helper.ts
119
+ async function getUserName(ctx, session, userId) {
120
+ try {
121
+ const memberInfo = await session.onebot.getGroupMemberInfo(
122
+ session.channelId,
123
+ userId
124
+ );
125
+ return memberInfo.card || memberInfo.nickname || userId;
126
+ } catch (error) {
127
+ ctx.logger.warn(`\u83B7\u53D6\u7FA4\u6210\u5458\u4FE1\u606F\u5931\u8D25\uFF08userId: ${userId}\uFF09\uFF1A`, error);
128
+ return userId;
129
+ }
130
+ }
131
+
108
132
  // src/msg-helper.ts
109
- async function sendCaveMsg(session, caveMsg) {
133
+ async function sendCaveMsg(ctx, session, caveMsg) {
110
134
  const { channelId } = session;
111
135
  const content = JSON.parse(caveMsg.content);
136
+ const date = formatDate(caveMsg.createTime);
137
+ const originName = await getUserName(ctx, session, caveMsg.originUserId);
138
+ const userName = await getUserName(ctx, session, caveMsg.userId);
139
+ const forwardStyles = [
140
+ `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
141
+
142
+ \u4E00\u5219\u56DE\u58F0\u4ECE\u65F6\u5149\u4E2D\u98D8\u6765\u2014\u2014
143
+ \u{1F4C5} ${date} \xB7 \u6765\u81EA @${originName}
144
+ \u{1F4EE} \u7531 @${userName} \u6295\u9012`,
145
+ `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
146
+
147
+ \u3010\u8BB0\u5F55\u7F16\u53F7\u3011${caveMsg.id}
148
+ \u3010\u521B\u5EFA\u65F6\u95F4\u3011${date}
149
+ \u3010\u539F\u59CB\u4F5C\u8005\u3011@${originName}
150
+ \u3010\u6295\u9012\u8005\u3011@${userName}`,
151
+ `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
152
+
153
+ \u8FD9\u58F0\u56DE\u54CD\u6700\u521D\u6765\u81EA @${originName}\uFF0C
154
+ \u7531 @${userName} \u5728 ${date} \u7559\u4E0B\u3002`,
155
+ `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
156
+
157
+ \u65F6\u95F4\u7684\u56DE\u97F3\u5728\u6B64\u6C47\u805A\u3002
158
+ \u{1F4C5} ${date}
159
+ \u{1F4E4} \u51FA\u5904\uFF1A@${originName}
160
+ \u{1F4EE} \u5C01\u5370\u8005\uFF1A@${userName}`,
161
+ `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
162
+
163
+ \u{1F4C5} ${date}
164
+ \u{1F464} \u6765\u81EA @${originName}
165
+ \u{1F4EE} \u6295\u9012\u8005 @${userName}`
166
+ ];
167
+ const msgStyles = [
168
+ {
169
+ prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
170
+
171
+ \u2014\u2014 \u6709\u4EBA\u7559\u4E0B\u4E86\u58F0\u97F3 \u2014\u2014
172
+
173
+ `,
174
+ suffix: `\u{1F4C5} ${date} \xB7 \u6765\u81EA @${originName}
175
+ \u{1F4EE} \u7531 @${userName} \u6295\u9012`
176
+ },
177
+ {
178
+ prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
179
+ \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
180
+ `,
181
+ suffix: `\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500
182
+ \u{1F4C5} ${date}
183
+ \u{1F464} ${originName} \xB7 \u7531 @${userName} \u6295\u9012`
184
+ },
185
+ {
186
+ prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
187
+
188
+ \u{1F4AD}\u300C\u6709\u4EBA\u5728\u6D1E\u58C1\u7559\u4E0B\u5370\u8BB0\u300D
189
+
190
+ `,
191
+ suffix: `\u{1F4C5} ${date}
192
+ \u{1F4EE} ${userName} \u8BB0\u5F55`
193
+ },
194
+ {
195
+ prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
196
+
197
+ \u2014 \u56DE\u58F0\u5F00\u59CB \u2014
198
+
199
+ `,
200
+ suffix: `\u2014 \u56DE\u58F0\u7ED3\u675F \u2014
201
+ \u{1F4C5} ${date} \xB7 @${originName}
202
+ \u{1F4EE} @${userName}`
203
+ },
204
+ {
205
+ prefix: `\u{1F300} \u56DE\u58F0\u6D1E #${caveMsg.id}
206
+
207
+ `,
208
+ suffix: `\u{1F4C5} ${date}
209
+ \u6765\u81EA @${originName}
210
+ \u7531 @${userName} \u6295\u9012`
211
+ }
212
+ ];
213
+ const random = (arr) => arr[Math.floor(Math.random() * arr.length)];
112
214
  if (caveMsg.type === "forward") {
215
+ const chosen = random(forwardStyles);
216
+ await session.onebot.sendGroupMsg(channelId, [createTextMsg(chosen)]);
113
217
  await session.onebot.sendGroupForwardMsg(channelId, content);
114
218
  } else {
219
+ const chosen = random(msgStyles);
220
+ const last = content.at(-1);
221
+ const needsNewline = last?.type === "text";
222
+ content.unshift(createTextMsg(chosen.prefix));
223
+ content.push(
224
+ createTextMsg(`${needsNewline ? "\n" : ""}${chosen.suffix}`)
225
+ );
115
226
  await session.onebot.sendGroupMsg(channelId, content);
116
227
  }
117
228
  }
229
+ function formatDate(date) {
230
+ return date.toLocaleDateString("zh-CN", {
231
+ year: "numeric",
232
+ month: "2-digit",
233
+ day: "2-digit"
234
+ });
235
+ }
118
236
 
119
237
  // src/index.ts
120
238
  var name = "echo-cave";
@@ -146,10 +264,10 @@ function apply(ctx) {
146
264
  "cave [id:number]",
147
265
  "\u968F\u673A\u83B7\u53D6 / \u83B7\u53D6\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F"
148
266
  ).action(async ({ session }, id) => await getCave(ctx, session, id));
149
- ctx.command("cave echo", "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E\u7A74").action(
267
+ ctx.command("cave.echo", "\u5C06\u6D88\u606F\u5B58\u5165\u56DE\u58F0\u6D1E\u7A74").action(
150
268
  async ({ session }) => await addCave(ctx, session)
151
269
  );
152
- ctx.command("cave wipe <id:number>", "\u62B9\u53BB\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F").action(
270
+ ctx.command("cave.wipe <id:number>", "\u62B9\u53BB\u7279\u5B9A id \u7684\u56DE\u58F0\u6D1E\u4FE1\u606F").action(
153
271
  async ({ session }, id) => await deleteCave(ctx, session, id)
154
272
  );
155
273
  }
@@ -174,7 +292,7 @@ async function getCave(ctx, session, id) {
174
292
  }
175
293
  caveMsg = caves[0];
176
294
  }
177
- await sendCaveMsg(session, caveMsg);
295
+ await sendCaveMsg(ctx, session, caveMsg);
178
296
  }
179
297
  async function deleteCave(ctx, session, id) {
180
298
  if (!session.guildId) {
@@ -234,10 +352,6 @@ async function addCave(ctx, session) {
234
352
  session.channelId,
235
353
  `\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A${result.id}`
236
354
  );
237
- ctx.setTimeout(
238
- async () => await session.onebot.deleteMsg(messageId2),
239
- 5e3
240
- );
241
355
  } catch (error) {
242
356
  this.ctx.logger.warn("\u4E0A\u67B6\u5546\u54C1\u5931\u8D25:", error);
243
357
  return "\u274C \u4E0A\u67B6\u5546\u54C1\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01";
@@ -1,3 +1,4 @@
1
- import { Session } from 'koishi';
1
+ import { Context, Session } from 'koishi';
2
2
  import { EchoCave } from './index';
3
- export declare function sendCaveMsg(session: Session, caveMsg: EchoCave): Promise<void>;
3
+ export declare function sendCaveMsg(ctx: Context, session: Session, caveMsg: EchoCave): Promise<void>;
4
+ export declare function formatDate(date: Date): string;
@@ -0,0 +1,2 @@
1
+ import { Context, Session } from 'koishi';
2
+ export declare function getUserName(ctx: Context, session: Session, userId: string): Promise<string>;
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.3.2",
4
+ "version": "1.4.0",
5
5
  "main": "lib/index.cjs",
6
6
  "typings": "lib/index.d.ts",
7
7
  "type": "module",