napcat-sdk 0.1.1 → 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/readme.md ADDED
@@ -0,0 +1,70 @@
1
+ # NapCat SDK for TypeScript
2
+
3
+ ## Getting Started
4
+
5
+ The NapCat SDK for TypeScript allows developers to easily integrate NapCat's functionalities into their TypeScript applications. This SDK provides a set of tools and utilities to interact with NapCat services seamlessly.
6
+
7
+ ## Installation
8
+
9
+ You can install the NapCat SDK via npm. Run the following command in your terminal:
10
+
11
+ ```bash
12
+ pnpm install napcat-sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ To connect to NapCat, you need to create an instance of the NapCat client. Here's a simple example:
18
+
19
+ ```typescript
20
+ import { NapCat, segment } from 'napcat-sdk'
21
+
22
+ // 1. Create a new NapCat client instance
23
+ const napcat = new NapCat({
24
+ // protocol: 'ws', // Optional: specify the protocol (default is 'ws')
25
+ // host: 'localhost', // Optional: specify a custom host
26
+ // port: 3333, // Optional: specify a custom port
27
+ token: 'here-your-auth-token', // Required: your authentication token
28
+ })
29
+
30
+ // 2. Subscribe to events
31
+ napcat.on('message', (event) => {
32
+ // replay is a method to send a message quickly, optional with reply mark
33
+ event.reply('Hello from NapCat SDK!', true) // true is for reply mark
34
+
35
+ // you can call all the NapCat api through `napcat.api()` method
36
+ const { value } = await napcat.api<{ value: unknown }>('awesome-function')
37
+ })
38
+
39
+ // you can also listen to specific message sub-types
40
+ napcat.on('message.group', async (event) => {
41
+ // all methods of a message event are available
42
+ await event.addEssence(event.message_id)
43
+ await event.recall()
44
+
45
+ // You can also interact with group instance to do some operations
46
+ await event.group.setTitle(114514, 'Special Title')
47
+
48
+ // message to send is allowed to be an array of segments
49
+ await event.reply(['Hi! ', napcat.segment.face(66)])
50
+
51
+ // or just use napcat to send messages
52
+ await napcat.sendGroupMsg(event.group_id, 'Hello Group!')
53
+ })
54
+
55
+ // and more events...
56
+ napcat.on('notice', (event) => {})
57
+ napcat.on('notice.group', (event) => {})
58
+ napcat.on('request', (event) => {})
59
+ napcat.on('request.group.invite', (event) => {
60
+ // approve the group invite request, or event.reject() to reject
61
+ event.approve()
62
+ })
63
+
64
+ // close the connection when needed
65
+ napcat.close()
66
+ ```
67
+
68
+ ## License
69
+
70
+ MIT License © 2025-PRESENT Viki