koishi-plugin-ll-brick 1.0.6 → 1.0.7
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.js +71 -29
- package/package.json +1 -1
- package/readme.md +9 -0
package/lib/index.js
CHANGED
|
@@ -52,11 +52,9 @@ exports.Config = koishi_1.Schema.intersect([
|
|
|
52
52
|
])
|
|
53
53
|
]);
|
|
54
54
|
exports.inject = ["database"];
|
|
55
|
-
// QQ
|
|
56
|
-
// 因此 QQ 平台的回复直接走开放平台 internal API 发 markdown
|
|
57
|
-
//
|
|
58
|
-
const BRICK_IMG = 'https://img3.tofaka.com/autoupload/ontjZmlK09ZHnuFOv9znC7KXl_QqVl-bpSwqP4fJO68/20260624/lOIl/240X240/images.jpg';
|
|
59
|
-
const FIRE_IMG = 'https://img3.tofaka.com/autoupload/ontjZmlK09ZHnuFOv9znC7KXl_QqVl-bpSwqP4fJO68/20260624/xsnm/447X447/images_%282%29.jpg';
|
|
55
|
+
// 本插件面向 QQ 官方机器人。@ 标签(<qqbot-at-user>)只有在 markdown 消息里才渲染,
|
|
56
|
+
// 因此 QQ 平台的回复直接走开放平台 internal API 发 markdown;其他平台沿用原 h.at 文本消息。
|
|
57
|
+
// 所有通知均为 markdown 卡片(不含图片)。
|
|
60
58
|
function atUser(session, userId) {
|
|
61
59
|
if (session?.platform === 'qq') {
|
|
62
60
|
return `<qqbot-at-user id="${userId}" />`;
|
|
@@ -75,22 +73,22 @@ function stripMarkdown(md) {
|
|
|
75
73
|
.replace(/\n{3,}/g, '\n\n')
|
|
76
74
|
.trim();
|
|
77
75
|
}
|
|
78
|
-
|
|
76
|
+
function mdCard(lines) {
|
|
77
|
+
return lines.filter(Boolean).join('\n');
|
|
78
|
+
}
|
|
79
|
+
async function sendQQMarkdown(session, text) {
|
|
79
80
|
const channelId = session.guildId;
|
|
80
81
|
const internal = session.bot?.internal;
|
|
81
82
|
if (!channelId || !internal || typeof internal.sendMessage !== 'function') {
|
|
82
83
|
return false;
|
|
83
84
|
}
|
|
84
|
-
|
|
85
|
-
const img = imageUrl ? `` : '';
|
|
86
|
-
const md = [img, text].filter(Boolean).join('\n\n');
|
|
87
|
-
const plain = stripMarkdown(md) || ' ';
|
|
85
|
+
const plain = stripMarkdown(text) || ' ';
|
|
88
86
|
try {
|
|
89
87
|
await internal.sendMessage(channelId, {
|
|
90
88
|
msg_type: 2,
|
|
91
89
|
msg_seq: 0,
|
|
92
90
|
content: plain,
|
|
93
|
-
markdown: { content:
|
|
91
|
+
markdown: { content: text },
|
|
94
92
|
});
|
|
95
93
|
return true;
|
|
96
94
|
}
|
|
@@ -154,7 +152,19 @@ async function apply(ctx, config) {
|
|
|
154
152
|
return `已经在烧砖了`;
|
|
155
153
|
}
|
|
156
154
|
users[user].burning = true;
|
|
157
|
-
|
|
155
|
+
const startCard = mdCard([
|
|
156
|
+
'# 🔥 砖厂开始烧砖啦!',
|
|
157
|
+
'---',
|
|
158
|
+
'> 🏭 **工作状态**:现在开始烧砖啦!',
|
|
159
|
+
`> 💬 **烧砖规则**:群友每发送 **${config.cost}** 条消息,就能成功烧好一块新砖 🧱`,
|
|
160
|
+
'> 📢 大家快来水群,给砖窑添把火吧!',
|
|
161
|
+
]);
|
|
162
|
+
if (session.platform === 'qq') {
|
|
163
|
+
await sendQQMarkdown(session, startCard);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
await session.send(startCard);
|
|
167
|
+
}
|
|
158
168
|
let messageCount = 0;
|
|
159
169
|
const dispose = ctx.guild(session.guildId).middleware(async (session_in, next) => {
|
|
160
170
|
if (![session.selfId, session.userId].includes(session_in.userId)) {
|
|
@@ -167,12 +177,17 @@ async function apply(ctx, config) {
|
|
|
167
177
|
brick: koishi_1.$.add(row.brick, 1),
|
|
168
178
|
}], ["userId", "guildId"]);
|
|
169
179
|
users[user].burning = false;
|
|
170
|
-
const fireDone =
|
|
180
|
+
const fireDone = mdCard([
|
|
181
|
+
'# 🎉 砖厂出炉啦!',
|
|
182
|
+
'---',
|
|
183
|
+
`> 🔨 ${atUser(session, session.userId)} 砖已经烧好啦!`,
|
|
184
|
+
'> 📢 快去用 `砖头 拍人` 狠狠地拍一下吧!',
|
|
185
|
+
]);
|
|
171
186
|
if (session.platform === 'qq') {
|
|
172
|
-
await sendQQMarkdown(session,
|
|
187
|
+
await sendQQMarkdown(session, fireDone);
|
|
173
188
|
}
|
|
174
189
|
else {
|
|
175
|
-
await session.send(
|
|
190
|
+
await session.send(fireDone);
|
|
176
191
|
}
|
|
177
192
|
}
|
|
178
193
|
}
|
|
@@ -217,29 +232,36 @@ async function apply(ctx, config) {
|
|
|
217
232
|
const probability = config.specialUser[targetUserId] !== undefined
|
|
218
233
|
? config.specialUser[targetUserId] / 100
|
|
219
234
|
: config.reverse / 100;
|
|
220
|
-
const brickImg = koishi_1.h.image('https://img3.tofaka.com/autoupload/ontjZmlK09ZHnuFOv9znC7KXl_QqVl-bpSwqP4fJO68/20260624/lOIl/240X240/images.jpg');
|
|
221
235
|
const isQQ = session.platform === 'qq';
|
|
222
236
|
if (koishi_1.Random.bool(probability)) {
|
|
223
237
|
const muteErr = await tryMute(session.userId);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
238
|
+
const msg = mdCard([
|
|
239
|
+
'# 💥 群内突发事件!',
|
|
240
|
+
'---',
|
|
241
|
+
'> ⚠️ 危险警告:有人动用了板砖!',
|
|
242
|
+
`> 🎯 ${atUser(session, targetUserId)} 夺过你的砖头,把你拍晕了 **${muteTime}** 秒 🏏`,
|
|
243
|
+
muteErr ? '> ⚠️ 因为我不是群管理员,所以并没什么卵用' : '',
|
|
244
|
+
]);
|
|
227
245
|
if (isQQ) {
|
|
228
|
-
await sendQQMarkdown(session,
|
|
246
|
+
await sendQQMarkdown(session, msg);
|
|
229
247
|
return;
|
|
230
248
|
}
|
|
231
|
-
return
|
|
249
|
+
return msg;
|
|
232
250
|
}
|
|
233
251
|
else {
|
|
234
252
|
const muteErr = await tryMute(targetUserId);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
253
|
+
const msg = mdCard([
|
|
254
|
+
'# 💥 群内突发事件!',
|
|
255
|
+
'---',
|
|
256
|
+
'> ⚠️ 危险警告:有人动用了板砖!',
|
|
257
|
+
`> 🎯 ${atUser(session, targetUserId)} 你被 ${atUser(session, session.userId)} 一砖头拍晕了 **${muteTime}** 秒 🏏`,
|
|
258
|
+
muteErr ? '> ⚠️ 因为我不是群管理员,所以并没什么卵用' : '',
|
|
259
|
+
]);
|
|
238
260
|
if (isQQ) {
|
|
239
|
-
await sendQQMarkdown(session,
|
|
261
|
+
await sendQQMarkdown(session, msg);
|
|
240
262
|
return;
|
|
241
263
|
}
|
|
242
|
-
return
|
|
264
|
+
return msg;
|
|
243
265
|
}
|
|
244
266
|
async function tryMute(slapedUserId) {
|
|
245
267
|
users[`${session.guildId}:${slapedUserId}`].muted = true;
|
|
@@ -304,7 +326,6 @@ async function apply(ctx, config) {
|
|
|
304
326
|
const date = new Date();
|
|
305
327
|
const today = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
|
306
328
|
let brick = koishi_1.Random.int(config.minGain, config.maxGain + 1);
|
|
307
|
-
const signImg = koishi_1.h.image('https://img3.tofaka.com/autoupload/ontjZmlK09ZHnuFOv9znC7KXl_QqVl-bpSwqP4fJO68/20260624/yNf2/447X447/images_%281%29.jpg');
|
|
308
329
|
const userData = await ctx.database.get('brick', {
|
|
309
330
|
userId: session.userId,
|
|
310
331
|
guildId: session.guildId,
|
|
@@ -316,7 +337,17 @@ async function apply(ctx, config) {
|
|
|
316
337
|
brick: brick,
|
|
317
338
|
checkingDay: today
|
|
318
339
|
});
|
|
319
|
-
|
|
340
|
+
const card = mdCard([
|
|
341
|
+
'# 🎡 砖厂打卡成功!',
|
|
342
|
+
'---',
|
|
343
|
+
`> 😋 辛苦啦!你刚刚搬运获得了 **${brick}** 块砖头 🧱`,
|
|
344
|
+
`> 📦 **当前库存**:你现在共有 \`${brick}/${config.maxBrick}\` 块砖头。`,
|
|
345
|
+
]);
|
|
346
|
+
if (session.platform === 'qq') {
|
|
347
|
+
await sendQQMarkdown(session, card);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
return card;
|
|
320
351
|
}
|
|
321
352
|
if (userData[0].checkingDay === today) {
|
|
322
353
|
return "你今天已经签到过了";
|
|
@@ -336,7 +367,18 @@ async function apply(ctx, config) {
|
|
|
336
367
|
brick: koishi_1.$.add(row.brick, brick),
|
|
337
368
|
checkingDay: today
|
|
338
369
|
}], ["userId", "guildId"]);
|
|
339
|
-
|
|
370
|
+
const total = userData[0].brick + brick;
|
|
371
|
+
const card = mdCard([
|
|
372
|
+
'# 🎡 砖厂打卡成功!',
|
|
373
|
+
'---',
|
|
374
|
+
`> 😋 辛苦啦!你刚刚搬运获得了 **${brick}** 块砖头 🧱`,
|
|
375
|
+
`> 📦 **当前库存**:你现在共有 \`${total}/${config.maxBrick}\` 块砖头。`,
|
|
376
|
+
]);
|
|
377
|
+
if (session.platform === 'qq') {
|
|
378
|
+
await sendQQMarkdown(session, card);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
return card;
|
|
340
382
|
});
|
|
341
383
|
}
|
|
342
384
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -13,6 +13,15 @@
|
|
|
13
13
|
- `砖头 查看` — 查看自己的砖头数量
|
|
14
14
|
- `砖头 签到`(可选开启)— 每日签到获取随机砖头
|
|
15
15
|
|
|
16
|
+
## v1.0.7 更新
|
|
17
|
+
|
|
18
|
+
- **移除所有图片**,所有通知统一改为 markdown 卡片样式(`# 标题` + `---` + `> 引用行`),加载更快
|
|
19
|
+
- 烧砖开始:「砖厂开始烧砖啦!」
|
|
20
|
+
- 烧砖完成:「砖厂出炉啦!」
|
|
21
|
+
- 拍人成功:「群内突发事件!」(两种分支)
|
|
22
|
+
- 签到打卡:「砖厂打卡成功!」
|
|
23
|
+
- `@` 保留用 `<qqbot-at-user>`,markdown 里正常渲染(与欢迎插件一致)
|
|
24
|
+
|
|
16
25
|
## v1.0.6 修复
|
|
17
26
|
|
|
18
27
|
- 修复 **`砖头 随机拍人` 报错 `not implemented: getGuildMemberList`**(QQ 官方适配器未实现群成员迭代接口):
|