@koishi-ce/plugin-broadcast 1.0.0 → 1.1.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.
package/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # @koishi-ce/plugin-broadcast
2
+
3
+ **简体中文** | [English](#english)
4
+
5
+ 全体广播插件,移植自上游 [koishijs/koishi](https://github.com/koishijs/koishi) 的 `plugins/common/broadcast`。向机器人所在的全部频道一次性推送广播消息。
6
+
7
+ ## 指令
8
+
9
+ | 指令 | 权限 | 说明 |
10
+ | --- | --- | --- |
11
+ | `broadcast <message:text>` | 4 | 全服广播 |
12
+
13
+ - `-f, --forced`:无视 silent 标签进行广播。
14
+ - `-o, --only`:仅向当前账号负责的群进行广播。
15
+
16
+ ## 配置项
17
+
18
+ 本插件无需配置。
19
+
20
+ ## 用法
21
+
22
+ ```bash
23
+ bun add @koishi-ce/plugin-broadcast
24
+ ```
25
+
26
+ 也可以在控制台的插件市场中直接安装。随后在配置文件中启用:
27
+
28
+ ```yaml
29
+ plugins:
30
+ broadcast: {}
31
+ ```
32
+
33
+ ## 备注
34
+
35
+ - 依赖数据库服务,读取内置 `channel` 表的 assignee 与 flag 字段,不新建表。
36
+ - 默认跳过标记为静默(silent)的频道,`-f` 可强制发送到这些频道。
37
+ - `-o` 只向当前平台、当前 bot 被指派(assignee)的频道发送。
38
+
39
+ ## 许可证
40
+
41
+ [MIT](https://github.com/Koishi-CE/koishi/blob/main/LICENSE)。本包是上游 [koishijs/koishi](https://github.com/koishijs/koishi) 的社区再分发,版权归属见 [NOTICE](https://github.com/Koishi-CE/koishi/blob/main/NOTICE)。
42
+
43
+ ---
44
+
45
+ ## English
46
+
47
+ A global broadcast plugin, ported from `plugins/common/broadcast` of the upstream [koishijs/koishi](https://github.com/koishijs/koishi) repository. It pushes a message to all channels the bots have joined.
48
+
49
+ ## Commands
50
+
51
+ | Command | Authority | Description |
52
+ | --- | --- | --- |
53
+ | `broadcast <message:text>` | 4 | Broadcast to all channels |
54
+
55
+ - `-f, --forced`: broadcast even to channels marked as silent.
56
+ - `-o, --only`: broadcast only to the channels assigned to the current account.
57
+
58
+ ## Configuration
59
+
60
+ None.
61
+
62
+ ## Usage
63
+
64
+ ```bash
65
+ bun add @koishi-ce/plugin-broadcast
66
+ ```
67
+
68
+ The plugin can also be installed from the console plugin market, then enabled in the config file:
69
+
70
+ ```yaml
71
+ plugins:
72
+ broadcast: {}
73
+ ```
74
+
75
+ ## Notes
76
+
77
+ - Requires the database service (reads the assignee and flag fields of the built-in `channel` table; no new tables).
78
+ - Silent channels are skipped by default; `-f` forces delivery to them.
79
+ - `-o` sends only to the channels assigned to the current platform and bot.
80
+
81
+ ## License
82
+
83
+ [MIT](https://github.com/Koishi-CE/koishi/blob/main/LICENSE). This package is a community redistribution of upstream koishijs/koishi; see [NOTICE](https://github.com/Koishi-CE/koishi/blob/main/NOTICE) for attribution.
@@ -1,3 +1,6 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
6
  description: 全服广播
package/lib/index.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { Context, Schema } from "@koishi-ce/koishi";
2
2
  //#region src/index.d.ts
3
3
  /** 配置项(当前无可用配置) */
4
- type Config = Record<never, never>;
5
- declare const name = "broadcast";
6
- declare const inject: string[];
7
- declare const Config: Schema<Config>;
8
- declare function apply(ctx: Context): void;
9
- //#endregion
10
- export { Config, apply, inject, name };
4
+ export type Config = Record<never, never>;
5
+ export declare const name = "broadcast";
6
+ export declare const inject: string[];
7
+ export declare const Config: Schema<Config>;
8
+ export declare function apply(ctx: Context): void;
9
+ //#endregion
package/lib/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Channel, Schema } from "@koishi-ce/koishi";
2
- import zhCN from "./assets/zh-CN-Bnc3gtS6.yml";
2
+ import zhCN from "./assets/zh-CN-JWl0QM2R.yml";
3
3
  //#region src/index.ts
4
4
  /**
5
5
  * 全体广播插件(broadcast)。
package/locales/de-DE.yml CHANGED
@@ -1,8 +1,11 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
- description: 全服广播
6
+ description: Broadcast an alle Kanäle
4
7
  options:
5
- forced: 无视 silent 标签进行广播
6
- only: 仅向当前账号负责的群进行广播
8
+ forced: Broadcast unter Umgehung des silent-Tags
9
+ only: Broadcast nur an die vom aktuellen Konto betreuten Gruppen
7
10
  messages:
8
- expect-text: 请输入要发送的文本。
11
+ expect-text: Bitte geben Sie den zu sendenden Text ein.
package/locales/en-US.yml CHANGED
@@ -1,8 +1,11 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
- description: 全服广播
6
+ description: Broadcast to all channels
4
7
  options:
5
- forced: 无视 silent 标签进行广播
6
- only: 仅向当前账号负责的群进行广播
8
+ forced: Broadcast ignoring the silent flag
9
+ only: Broadcast only to groups served by the current account
7
10
  messages:
8
11
  expect-text: Please type to send
package/locales/fr-FR.yml CHANGED
@@ -1,8 +1,11 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
- description: 全服广播
6
+ description: Diffuser sur tous les canaux
4
7
  options:
5
- forced: 无视 silent 标签进行广播
6
- only: 仅向当前账号负责的群进行广播
8
+ forced: Diffuser en ignorant le marqueur silent
9
+ only: Ne diffuser que vers les groupes gérés par le compte actuel
7
10
  messages:
8
- expect-text: 请输入要发送的文本。
11
+ expect-text: Veuillez saisir le texte à envoyer.
package/locales/ja-JP.yml CHANGED
@@ -1,8 +1,11 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
- description: 全服广播
6
+ description: サーバー全体にブロードキャスト
4
7
  options:
5
- forced: 无视 silent 标签进行广播
6
- only: 仅向当前账号负责的群进行广播
8
+ forced: silent タグを無視してブロードキャストする
9
+ only: 現在のアカウントが担当するグループのみにブロードキャストする
7
10
  messages:
8
- expect-text: 请输入要发送的文本。
11
+ expect-text: 送信するテキストを入力してください。
package/locales/ru-RU.yml CHANGED
@@ -1,8 +1,11 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
- description: 全服广播
6
+ description: Рассылка по всем каналам
4
7
  options:
5
- forced: 无视 silent 标签进行广播
6
- only: 仅向当前账号负责的群进行广播
8
+ forced: Рассылка с игнорированием метки silent
9
+ only: Рассылка только в группы, обслуживаемые текущим аккаунтом
7
10
  messages:
8
- expect-text: 请输入要发送的文本。
11
+ expect-text: Пожалуйста, введите текст для отправки.
package/locales/zh-CN.yml CHANGED
@@ -1,3 +1,6 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
6
  description: 全服广播
package/locales/zh-TW.yml CHANGED
@@ -1,3 +1,6 @@
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+
1
4
  commands:
2
5
  broadcast:
3
6
  description: 全服廣播
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@koishi-ce/plugin-broadcast",
3
3
  "description": "Broadcast messages in Koishi",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "type": "module",
6
6
  "main": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",
@@ -47,13 +47,12 @@
47
47
  ]
48
48
  },
49
49
  "peerDependencies": {
50
- "koishi": "^4.18.11"
50
+ "@koishi-ce/koishi": "^1.0.0"
51
51
  },
52
52
  "devDependencies": {
53
+ "@koishi-ce/koishi": "^1.0.8",
53
54
  "@koishi-ce/plugin-mock": "^1.0.0",
54
- "@minatojs/driver-memory": "^3.7.0",
55
- "@koishi-ce/koishi": "^1.0.0",
56
- "minato": "^3.7.0"
55
+ "@koishijs/plugin-database-memory": "^3.7.0"
57
56
  },
58
57
  "exports": {
59
58
  ".": {
package/src/index.test.ts CHANGED
@@ -1,12 +1,25 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2026-present Koishi-CE contributors.
3
+
1
4
  /**
2
5
  * broadcast 插件测试:用两个 mock bot 验证全局广播、
3
6
  * 仅本 bot 广播(-o)与静默频道过滤(-f)的目标频道集合。
4
7
  */
5
- import { beforeAll, describe, expect, it, jest } from "bun:test";
8
+ import {
9
+ beforeAll,
10
+ describe,
11
+ expect,
12
+ it,
13
+ jest,
14
+ } from "bun:test";
6
15
  import { App, type Bot, Channel } from "@koishi-ce/koishi";
7
16
  import * as broadcast from "@koishi-ce/plugin-broadcast";
8
17
  import mock from "@koishi-ce/plugin-mock";
9
- import memory from "@minatojs/driver-memory";
18
+ import * as memoryModule from "@koishijs/plugin-database-memory";
19
+
20
+ // CJS 实现配 ESM 声明,Bun 互操作视图多包一层 default,穿透取真实驱动
21
+ const memory =
22
+ memoryModule.default as unknown as typeof memoryModule.default.default;
10
23
 
11
24
  const app = new App({
12
25
  delay: { broadcast: 0 },
@@ -24,7 +37,9 @@ beforeAll(async () => {
24
37
  await app.mock.initUser("123", 4);
25
38
  await app.mock.initChannel("111", "114");
26
39
  await app.mock.initChannel("222", "514");
27
- await app.mock.initChannel("333", "514", { flag: Channel.Flag.silent });
40
+ await app.mock.initChannel("333", "514", {
41
+ flag: Channel.Flag.silent,
42
+ });
28
43
  await app.mock.initChannel("444", "810");
29
44
  });
30
45
 
@@ -32,13 +47,22 @@ describe("@koishi-ce/plugin-broadcast", () => {
32
47
  // 拦截各 bot 的 sendMessage,断言广播命中了正确的频道且静默频道被正确跳过或强制发送
33
48
  it("basic support", async () => {
34
49
  // 在拦截前验证缺参数提示(此时回复链路完整,消息能送达 mock 客户端)
35
- await client.shouldReply("broadcast", "请输入要发送的文本。");
50
+ await client.shouldReply(
51
+ "broadcast",
52
+ "请输入要发送的文本。",
53
+ );
36
54
 
37
55
  // 替换 sendMessage 为仅记录参数的 mock;返回空 ID 列表以维持 bot.broadcast 的展开推送
38
- const send1 = (app.bots.find((bot) => bot.selfId === "514")!.sendMessage =
39
- jest.fn<Bot["sendMessage"]>(async () => []));
40
- const send2 = (app.bots.find((bot) => bot.selfId === "114")!.sendMessage =
41
- jest.fn<Bot["sendMessage"]>(async () => []));
56
+ const send1 = (app.bots.find(
57
+ (bot) => bot.selfId === "514",
58
+ )!.sendMessage = jest.fn<Bot["sendMessage"]>(
59
+ async () => [],
60
+ ));
61
+ const send2 = (app.bots.find(
62
+ (bot) => bot.selfId === "114",
63
+ )!.sendMessage = jest.fn<Bot["sendMessage"]>(
64
+ async () => [],
65
+ ));
42
66
 
43
67
  await client.shouldNotReply("broadcast foo");
44
68
  // 全局广播:两个 bot 各发送被指派的频道,静默频道 333 被跳过
package/src/index.ts CHANGED
@@ -1,3 +1,7 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Copyright (c) 2019-present Shigma and Koishijs contributors.
3
+ // Copyright (c) 2026-present Koishi-CE contributors.
4
+
1
5
  /**
2
6
  * 全体广播插件(broadcast)。
3
7
  *
@@ -6,7 +10,11 @@
6
10
  * 选项:`-f` 强制发送到静默频道;`-o` 仅发送到当前 bot 被指派的频道。
7
11
  * 依赖数据库(channel 表的 assignee / flag 字段)。
8
12
  */
9
- import { Channel, type Context, Schema } from "@koishi-ce/koishi";
13
+ import {
14
+ Channel,
15
+ type Context,
16
+ Schema,
17
+ } from "@koishi-ce/koishi";
10
18
  import zhCN from "../locales/zh-CN.yml";
11
19
 
12
20
  /** 配置项(当前无可用配置) */
@@ -28,18 +36,26 @@ export function apply(ctx: Context) {
28
36
  if (!message) return session.text(".expect-text");
29
37
  if (!options.only) {
30
38
  // 非仅本 bot 模式:交给全局广播(覆盖所有 bot 的指派频道)
31
- await ctx.broadcast(message, Boolean(options.forced));
39
+ await ctx.broadcast(
40
+ message,
41
+ Boolean(options.forced),
42
+ );
32
43
  return;
33
44
  }
34
45
 
35
46
  // -o 模式:只取当前平台、当前 bot 被指派的频道;非强制时需 flag 字段用于过滤静默频道
36
47
  const fields: ("id" | "flag")[] = ["id"];
37
48
  if (!options.forced) fields.push("flag");
38
- let channels = await ctx.database.getAssignedChannels(fields, {
39
- [session.platform]: [session.selfId],
40
- });
49
+ let channels = await ctx.database.getAssignedChannels(
50
+ fields,
51
+ {
52
+ [session.platform]: [session.selfId],
53
+ },
54
+ );
41
55
  if (!options.forced) {
42
- channels = channels.filter((g) => !(g.flag & Channel.Flag.silent));
56
+ channels = channels.filter(
57
+ (g) => !(g.flag & Channel.Flag.silent),
58
+ );
43
59
  }
44
60
  await session.bot.broadcast(
45
61
  channels.map((channel) => channel.id),