@zhin.js/adapter-icqq 1.1.17 → 1.1.19

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +55 -10
  3. package/adapters/icqq/index.js +3 -19
  4. package/adapters/icqq/index.ts +2 -25
  5. package/commands/icqq/endpoint/definition.js +3 -25
  6. package/commands/icqq/endpoint/definition.ts +3 -24
  7. package/commands/icqq/login/code/index.js +28 -0
  8. package/commands/icqq/login/code/index.ts +30 -0
  9. package/commands/icqq/login/confirm/index.js +20 -0
  10. package/commands/icqq/login/confirm/index.ts +21 -0
  11. package/commands/icqq/login/definition.js +65 -0
  12. package/commands/icqq/login/definition.ts +72 -0
  13. package/commands/icqq/login/qr/index.js +53 -0
  14. package/commands/icqq/login/qr/index.ts +55 -0
  15. package/commands/icqq/login/retry/index.js +21 -0
  16. package/commands/icqq/login/retry/index.ts +23 -0
  17. package/commands/icqq/login/status/index.js +31 -0
  18. package/commands/icqq/login/status/index.ts +34 -0
  19. package/lib/adapter.d.ts +13 -0
  20. package/lib/adapter.js +27 -0
  21. package/lib/client.d.ts +6 -9
  22. package/lib/client.js +1 -3
  23. package/lib/console-spec.d.ts +17 -0
  24. package/lib/console-spec.js +21 -0
  25. package/lib/console.d.ts +2 -0
  26. package/lib/console.js +13 -0
  27. package/lib/endpoint.d.ts +12 -15
  28. package/lib/endpoint.js +373 -164
  29. package/lib/group-moderation.d.ts +6 -3
  30. package/lib/group-moderation.js +9 -8
  31. package/lib/group-scene.d.ts +3 -3
  32. package/lib/group-scene.js +8 -7
  33. package/lib/icqq-login-assist.d.ts +3 -1
  34. package/lib/icqq-login-assist.js +3 -1
  35. package/lib/icqq-login-control.d.ts +24 -0
  36. package/lib/icqq-login-control.js +25 -0
  37. package/lib/index.d.ts +3 -2
  38. package/lib/index.js +2 -2
  39. package/lib/protocol.d.ts +13 -0
  40. package/lib/protocol.js +24 -9
  41. package/package.json +25 -17
  42. package/pages/index/index.js +15 -0
  43. package/pages/index/index.ts +16 -0
  44. package/plugin.js +3 -5
  45. package/schema.json +174 -0
  46. package/src/adapter.ts +29 -0
  47. package/src/client.ts +6 -11
  48. package/src/console-spec.ts +26 -0
  49. package/src/console.ts +17 -0
  50. package/src/endpoint.ts +381 -178
  51. package/src/group-moderation.ts +10 -10
  52. package/src/group-scene.ts +8 -8
  53. package/src/icqq-login-assist.ts +6 -2
  54. package/src/icqq-login-control.ts +42 -0
  55. package/src/index.ts +4 -1
  56. package/src/protocol.ts +35 -8
  57. package/lib/icqq-runtime-state.d.ts +0 -1
  58. package/lib/icqq-runtime-state.js +0 -6
  59. package/src/icqq-runtime-state.ts +0 -7
package/src/adapter.ts ADDED
@@ -0,0 +1,29 @@
1
+ import { Adapter, createAdapterOutageNotifier, type AdapterContext, type EndpointCreationContext } from 'zhin.js/adapter';
2
+ import { projectLocaleToken } from 'zhin.js/i18n';
3
+ import { loginAssistToken } from '@zhin.js/core/runtime';
4
+ import { outboundHostToken } from 'zhin.js';
5
+ import { IcqqEndpoint } from './endpoint.js';
6
+ import { resolveIcqqConfig, type IcqqEndpointConfig } from './protocol.js';
7
+ import type { IcqqClientEventMap } from './client.js';
8
+
9
+ /** ICQQ account construction and actual SDK ownership belong to this Adapter. */
10
+ export class IcqqAdapter extends Adapter<IcqqEndpoint, IcqqEndpointConfig, IcqqClientEventMap> {
11
+ override get configurationIdentityFields(): readonly string[] { return ['id']; }
12
+ override get configurationUpdateFields(): readonly string[] {
13
+ return ['password', 'platform', 'ver', 'dataDir', 'signApiAddr', 'autoReconnect', 'autoServer', 'qqnt', 'ntLogin'];
14
+ }
15
+ readonly #context: AdapterContext<IcqqEndpointConfig>;
16
+ constructor(context: AdapterContext<IcqqEndpointConfig>) { super(); this.#context = context; }
17
+ protected override validateConfiguration(config: IcqqEndpointConfig): void { resolveIcqqConfig(config); }
18
+ protected createEndpoint(input: IcqqEndpointConfig, execution: EndpointCreationContext): IcqqEndpoint {
19
+ const context = this.#context;
20
+ const config = resolveIcqqConfig(input);
21
+ const outbound = context.has?.(outboundHostToken) ? context.use(outboundHostToken) : undefined;
22
+ const endpoint = new IcqqEndpoint({ id: execution.canonicalId, config,
23
+ signal: execution.signal, endpointIdentity: { canonicalId: execution.canonicalId, instanceId: execution.instanceId, epoch: execution.epoch, incarnationId: execution.incarnationId },
24
+ loginAssist: context.use(loginAssistToken), locale: context.use(projectLocaleToken),
25
+ notifier: createAdapterOutageNotifier(outbound, config.notify),
26
+ });
27
+ return endpoint;
28
+ }
29
+ }
package/src/client.ts CHANGED
@@ -1,5 +1,6 @@
1
- import type { Client, EventMap } from '@icqqjs/icqq';
2
- import { defineEndpointClient } from 'zhin.js/adapter';
1
+ import type { IcqqAdapter } from './adapter.js';
2
+ import type { IcqqEndpoint } from './endpoint.js';
3
+ import type { EventMap } from '@icqqjs/icqq';
3
4
 
4
5
  type EventPayload<TListener> = TListener extends (
5
6
  event: infer TEvent,
@@ -9,7 +10,7 @@ type EventPayload<TListener> = TListener extends (
9
10
  : never;
10
11
 
11
12
  /** The actual ICQQ SDK instance exposed by every ICQQ Endpoint event. */
12
- export type IcqqClient = Client;
13
+ export type IcqqClient = IcqqEndpoint;
13
14
 
14
15
  /** Native ICQQ event-name → first public event payload, derived from the SDK SSOT. */
15
16
  export type IcqqClientEventMap = {
@@ -17,13 +18,7 @@ export type IcqqClientEventMap = {
17
18
  };
18
19
 
19
20
  declare module '@zhin.js/feature-kit' {
20
- interface AdapterClientRegistry {
21
- readonly icqq: {
22
- readonly client: IcqqClient;
23
- readonly events: IcqqClientEventMap;
24
- };
21
+ interface AdapterRegistry {
22
+ readonly icqq: IcqqAdapter;
25
23
  }
26
24
  }
27
-
28
- /** Typed, generation-checked identity used by handlers, commands, tools and schedules. */
29
- export const icqqClient = defineEndpointClient<IcqqClient, IcqqClientEventMap>('icqq');
@@ -0,0 +1,26 @@
1
+ /**
2
+ * ICQQ Console 页面元数据(浏览器与服务端共享;不要在这里 import 服务端代码)。
3
+ */
4
+ import type { AdapterConsoleField } from 'zhin.js/adapter';
5
+
6
+ export const icqqConsoleSpec = {
7
+ adapterKey: 'icqq',
8
+ adapterDisplayName: 'ICQQ',
9
+ fields: [
10
+ { key: 'password', env: true, description: 'QQ password; leave blank to retain the saved credential' },
11
+ { key: 'platform', type: 'number', description: 'ICQQ platform number' },
12
+ { key: 'ver', description: 'ICQQ protocol version' },
13
+ { key: 'dataDir', description: 'ICQQ device and session directory' },
14
+ { key: 'signApiAddr', description: 'ICQQ signing service URL' },
15
+ { key: 'autoReconnect', type: 'boolean', description: 'ICQQ reconnect setting' },
16
+ { key: 'autoServer', type: 'boolean', description: 'ICQQ automatic server selection' },
17
+ { key: 'qqnt', type: 'boolean', description: 'QQNT protocol' },
18
+ { key: 'ntLogin', type: 'boolean', description: 'QQNT login' },
19
+ ] as readonly AdapterConsoleField[],
20
+ docsUrl: 'https://zhin.js.org/adapters/icqq',
21
+ readPermission: 'icqq:read',
22
+ writePermission: 'icqq:write',
23
+ idPattern: /^\d+$/,
24
+ idHint: 'ICQQ endpoint id 是 QQ 号(纯数字)',
25
+ idHintI18n: { en: 'ICQQ endpoint ID is the QQ number (digits only)' },
26
+ } as const;
package/src/console.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * ICQQ Console RPC:运行状态 + endpoint 增删(原 `icqq endpoint` 聊天命令)。
3
+ *
4
+ * 页面绑定 `pages/index`,读取 / 写入分别要求 `<adapter>:read` / `<adapter>:write`。
5
+ */
6
+ import { createAdapterConsoleRpc } from 'zhin.js/adapter';
7
+ import type { PluginConsoleRpc } from 'zhin.js';
8
+ import { icqqConsoleSpec } from './console-spec.js';
9
+
10
+ export function createIcqqConsoleRpc(
11
+ getConfig: () => unknown,
12
+ ): PluginConsoleRpc {
13
+ return createAdapterConsoleRpc({
14
+ ...icqqConsoleSpec,
15
+ getConfig,
16
+ });
17
+ }