koishi-plugin-echo-cave 1.3.3 → 1.4.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/cqcode-helper.d.ts +6 -0
- package/lib/index.cjs +125 -8
- package/lib/msg-helper.d.ts +3 -2
- package/lib/onebot-helper.d.ts +2 -0
- package/package.json +1 -1
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";
|
|
@@ -158,8 +276,8 @@ async function getCave(ctx, session, id) {
|
|
|
158
276
|
return "\u274C \u8BF7\u5728\u7FA4\u804A\u4E2D\u4F7F\u7528\u8BE5\u547D\u4EE4\uFF01";
|
|
159
277
|
}
|
|
160
278
|
let caveMsg;
|
|
279
|
+
const { channelId } = session;
|
|
161
280
|
if (!id) {
|
|
162
|
-
const { channelId } = session;
|
|
163
281
|
const caves = await ctx.database.get("echo_cave", {
|
|
164
282
|
channelId
|
|
165
283
|
});
|
|
@@ -168,13 +286,16 @@ async function getCave(ctx, session, id) {
|
|
|
168
286
|
}
|
|
169
287
|
caveMsg = caves[Math.floor(Math.random() * caves.length)];
|
|
170
288
|
} else {
|
|
171
|
-
const caves = await ctx.database.get("echo_cave",
|
|
289
|
+
const caves = await ctx.database.get("echo_cave", {
|
|
290
|
+
id,
|
|
291
|
+
channelId
|
|
292
|
+
});
|
|
172
293
|
if (caves.length === 0) {
|
|
173
294
|
return "\u{1F50D} \u672A\u627E\u5230\u8BE5 ID \u7684\u56DE\u58F0\u6D1E\u6D88\u606F";
|
|
174
295
|
}
|
|
175
296
|
caveMsg = caves[0];
|
|
176
297
|
}
|
|
177
|
-
await sendCaveMsg(session, caveMsg);
|
|
298
|
+
await sendCaveMsg(ctx, session, caveMsg);
|
|
178
299
|
}
|
|
179
300
|
async function deleteCave(ctx, session, id) {
|
|
180
301
|
if (!session.guildId) {
|
|
@@ -234,10 +355,6 @@ async function addCave(ctx, session) {
|
|
|
234
355
|
session.channelId,
|
|
235
356
|
`\u2705 \u56DE\u58F0\u6D1E\u6D88\u606F\u5DF2\u6210\u529F\u5B58\u5165\uFF0C\u6D88\u606F ID\uFF1A${result.id}`
|
|
236
357
|
);
|
|
237
|
-
ctx.setTimeout(
|
|
238
|
-
async () => await session.onebot.deleteMsg(messageId2),
|
|
239
|
-
5e3
|
|
240
|
-
);
|
|
241
358
|
} catch (error) {
|
|
242
359
|
this.ctx.logger.warn("\u4E0A\u67B6\u5546\u54C1\u5931\u8D25:", error);
|
|
243
360
|
return "\u274C \u4E0A\u67B6\u5546\u54C1\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF01";
|
package/lib/msg-helper.d.ts
CHANGED
|
@@ -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;
|