napcat-sdk 0.1.0 → 0.1.2

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/src/segment.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { ExtractByType } from './types'
2
- import type { SendElement } from './onebot'
3
-
4
- function createSegment<T extends SendElement['type'], D>(type: T, data: D): SendElement {
5
- return { type, ...data } as SendElement
6
- }
7
-
8
- /**
9
- * 消息片段构造器
10
- */
11
- export const segment = {
12
- /** 创建一个文本消息片段 */
13
- text: (text: string): SendElement => createSegment('text', { text }),
14
- /** 创建一个艾特消息片段 */
15
- at: (qq: 'all' | (string & {})): SendElement => createSegment('at', { qq }),
16
- /** 创建一个 QQ 表情消息片段 */
17
- face: (id: number): SendElement => createSegment('face', { id }),
18
- /** 创建一个回复消息片段 */
19
- reply: (id: string): SendElement => createSegment('reply', { id }),
20
- /** 创建一个图片消息片段 */
21
- image: (file: string, options?: Omit<ExtractByType<SendElement, 'image'>, 'type' | 'file'>): SendElement =>
22
- createSegment('image', { file, ...options }),
23
- /** 创建一个语音消息片段 */
24
- record: (file: string, options?: Omit<ExtractByType<SendElement, 'record'>, 'type' | 'file'>): SendElement =>
25
- createSegment('record', { file, ...options }),
26
- /** 创建一个视频消息片段 */
27
- video: (file: string, options?: Omit<ExtractByType<SendElement, 'video'>, 'type' | 'file'>): SendElement =>
28
- createSegment('video', { file, ...options }),
29
- /** 创建一个动态表情消息片段 */
30
- mface: (options: Omit<ExtractByType<SendElement, 'mface'>, 'type'>): SendElement =>
31
- createSegment('mface', { ...options }),
32
- /** 创建一个大表情消息片段 */
33
- bface: (id: number): SendElement => createSegment('bface', { id }),
34
- /** 创建一个 联系人/群 分享消息片段 */
35
- contact: (type: 'qq' | 'group', id: string): SendElement => createSegment('contact', { id, sub_type: type }),
36
- /** 创建一个戳一戳消息片段 */
37
- poke: (): SendElement => createSegment('poke', {}),
38
- /** 创建一个音乐消息片段 */
39
- music: (platform: 'qq' | '163' | 'kugou' | 'migu' | 'kuwo', id: string): SendElement =>
40
- createSegment('music', { platform, id }),
41
- /** 创建一个自定义音乐消息片段 */
42
- musicCustom: (
43
- title: string,
44
- audio: string,
45
- url: string,
46
- options?: Omit<ExtractByType<SendElement, 'music'>, 'type' | 'platform' | 'url' | 'audio' | 'title'>,
47
- ): SendElement => createSegment('music', { platform: 'custom', url, audio, title, ...options }),
48
- /** 创建一个合并转发消息片段 */
49
- forward: (id: string): SendElement => createSegment('forward', { id }),
50
- /** 创建一个 JSON 消息片段 */
51
- json: (data: string): SendElement => createSegment('json', { data }),
52
- /** 创建一个文件消息片段 */
53
- file: (file: string, options?: Omit<ExtractByType<SendElement, 'file'>, 'type' | 'file'>): SendElement =>
54
- createSegment('file', { file, ...options }),
55
- /** 创建一个 Markdown 消息片段 */
56
- markdown: (): SendElement => createSegment('markdown', {}),
57
- /** 创建一个轻应用消息片段 */
58
- lightapp: (): SendElement => createSegment('lightapp', {}),
59
- }
package/src/types.ts DELETED
@@ -1,34 +0,0 @@
1
- import type { Logger } from './logger'
2
- import type { OneBotEventMap } from './onebot'
3
-
4
- export interface MiokiOptions {
5
- /** NapCat 访问令牌 */
6
- token: string
7
- /** NapCat 服务器协议,默认为 ws */
8
- protocol?: 'ws' | 'wss'
9
- /** NapCat 服务器主机,默认为 localhost */
10
- host?: string
11
- /** NapCat 服务器端口,默认为 3333 */
12
- port?: number
13
- /** 日志记录器,默认为控制台日志记录器 */
14
- logger?: Logger
15
- }
16
-
17
- export type OptionalKeys<T> = {
18
- [K in keyof T]-?: {} extends Pick<T, K> ? K : never
19
- }[keyof T]
20
-
21
- export type OptionalProps<T> = Pick<T, OptionalKeys<T>>
22
-
23
- export type ExtractByType<T, K> = T extends { type: K } ? T : never
24
-
25
- export interface EventMap extends OneBotEventMap {
26
- /** WebSocket 连接已打开 */
27
- 'ws.open': void
28
- /** WebSocket 连接已关闭 */
29
- 'ws.close': void
30
- /** WebSocket 连接发生错误 */
31
- 'ws.error': Event
32
- /** 收到 WebSocket 消息 */
33
- 'ws.message': any
34
- }
package/tsconfig.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json"
3
- }
package/tsdown.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'tsdown'
2
-
3
- export default defineConfig({
4
- entry: ['./src/index.ts'],
5
- dts: true,
6
- sourcemap: true,
7
- target: 'node24',
8
- treeshake: true,
9
- tsconfig: './tsconfig.json',
10
- format: ['cjs', 'esm'],
11
- failOnWarn: false,
12
- })