koishi-plugin-ll-brick 1.0.7 → 1.0.8

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
@@ -26,6 +26,7 @@ export interface Config {
26
26
  ignoreMuted: boolean;
27
27
  reverse: number;
28
28
  specialUser: SpecialUser;
29
+ adminUsers: string[];
29
30
  checking: boolean;
30
31
  minGain?: number;
31
32
  maxGain?: number;
package/lib/index.js CHANGED
@@ -34,6 +34,9 @@ exports.Config = koishi_1.Schema.intersect([
34
34
  specialUser: koishi_1.Schema.dict(Number)
35
35
  .role('table')
36
36
  .description('键为用户ID,值为被拍时的反击概率(%)<br/>不设置则使用默认概率'),
37
+ adminUsers: koishi_1.Schema.array(koishi_1.Schema.string())
38
+ .default([])
39
+ .description('管理员 ID 列表(openid):被加入的 ID 可以使用「充值」等管理命令'),
37
40
  }),
38
41
  koishi_1.Schema.object({
39
42
  checking: koishi_1.Schema.boolean()
@@ -319,6 +322,49 @@ async function apply(ctx, config) {
319
322
  return `你有 ${brickData[0].brick}/${config.maxBrick} 块砖头`;
320
323
  }
321
324
  });
325
+ ctx.command("砖头.充值 <user:user> <amount:number>", "给指定用户充值砖头(仅管理员)")
326
+ .alias("充值")
327
+ .example("充值 @某人 10")
328
+ .action(async ({ session }, user, amount) => {
329
+ if (!config.adminUsers.includes(session.userId)) {
330
+ return '只有管理员才能使用 充值';
331
+ }
332
+ const targetUserId = user && user.split(":")[1];
333
+ if (!targetUserId) {
334
+ return '无效的用户';
335
+ }
336
+ const add = Math.floor(Number(amount));
337
+ if (!Number.isFinite(add) || add <= 0) {
338
+ return '充值数量无效';
339
+ }
340
+ const existing = await ctx.database.get('brick', {
341
+ userId: targetUserId,
342
+ guildId: session.guildId,
343
+ });
344
+ const cur = existing.length ? existing[0].brick : 0;
345
+ if (cur >= config.maxBrick) {
346
+ return `该用户砖头已满(${cur}/${config.maxBrick})`;
347
+ }
348
+ let real = add;
349
+ if (cur + real > config.maxBrick) {
350
+ real = config.maxBrick - cur;
351
+ }
352
+ if (existing.length === 0) {
353
+ await ctx.database.create('brick', {
354
+ userId: targetUserId,
355
+ guildId: session.guildId,
356
+ brick: real,
357
+ });
358
+ }
359
+ else {
360
+ await ctx.database.upsert('brick', (row) => [{
361
+ userId: targetUserId,
362
+ guildId: session.guildId,
363
+ brick: koishi_1.$.add(row.brick, real),
364
+ }], ["userId", "guildId"]);
365
+ }
366
+ return `已给 ${targetUserId.slice(0, 8)} 充值 ${real} 块砖头(现有 ${cur + real}/${config.maxBrick})`;
367
+ });
322
368
  if (config.checking) {
323
369
  ctx.command("砖头.签到")
324
370
  .alias("砖头签到")
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-ll-brick",
3
3
  "description": "砖头拍人插件(克隆自 koishi-plugin-brick),非管理员时会提示",
4
- "version": "1.0.7",
4
+ "version": "1.0.8",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/readme.md CHANGED
@@ -13,6 +13,12 @@
13
13
  - `砖头 查看` — 查看自己的砖头数量
14
14
  - `砖头 签到`(可选开启)— 每日签到获取随机砖头
15
15
 
16
+ ## v1.0.8 新增
17
+
18
+ - **设置页新增「管理员 ID 列表」**(`adminUsers`):填入用户的 openid 即成为管理员,无需额外管理员命令
19
+ - 新增命令 **`砖头 充值 @某人 <数量>`**(仅管理员可用):给指定用户充入砖头(不会超过上限 `maxBrick`)
20
+ - 非管理员使用充值会提示"只有管理员才能使用 充值"
21
+
16
22
  ## v1.0.7 更新
17
23
 
18
24
  - **移除所有图片**,所有通知统一改为 markdown 卡片样式(`# 标题` + `---` + `> 引用行`),加载更快