@zhin.js/adapter-qq 1.0.12 → 1.0.14
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/CHANGELOG.md +15 -0
- package/package.json +21 -7
- package/src/index.ts +0 -146
- package/tsconfig.json +0 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @zhin.js/adapter-qq
|
|
2
2
|
|
|
3
|
+
## 1.0.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 547028f: fix: 优化包结构,优化客户端支持
|
|
8
|
+
- Updated dependencies [547028f]
|
|
9
|
+
- @zhin.js/types@1.0.5
|
|
10
|
+
- zhin.js@1.0.14
|
|
11
|
+
|
|
12
|
+
## 1.0.13
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- zhin.js@1.0.13
|
|
17
|
+
|
|
3
18
|
## 1.0.12
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-qq",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "zhin adapter for qq",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -11,10 +11,17 @@
|
|
|
11
11
|
"import": "./lib/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"zhin",
|
|
16
|
+
"adapter",
|
|
17
|
+
"qq"
|
|
18
|
+
],
|
|
19
|
+
"author": "lc-cn",
|
|
20
|
+
"license": "MIT",
|
|
14
21
|
"repository": {
|
|
15
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/zhinjs/zhin.git",
|
|
16
23
|
"type": "git",
|
|
17
|
-
"directory": "adapters/qq"
|
|
24
|
+
"directory": "plugins/adapters/qq"
|
|
18
25
|
},
|
|
19
26
|
"dependencies": {
|
|
20
27
|
"qq-official-bot": "^1.0.11"
|
|
@@ -23,16 +30,23 @@
|
|
|
23
30
|
"typescript": "^5.3.0"
|
|
24
31
|
},
|
|
25
32
|
"peerDependencies": {
|
|
26
|
-
"zhin.js": "1.0.
|
|
27
|
-
"@zhin.js/types": "1.0.
|
|
33
|
+
"zhin.js": "1.0.14",
|
|
34
|
+
"@zhin.js/types": "1.0.5"
|
|
28
35
|
},
|
|
29
36
|
"peerDependenciesMeta": {
|
|
30
37
|
"@zhin.js/types": {
|
|
31
38
|
"optional": true
|
|
32
39
|
}
|
|
33
40
|
},
|
|
41
|
+
"files": [
|
|
42
|
+
"lib",
|
|
43
|
+
"node",
|
|
44
|
+
"README.md",
|
|
45
|
+
"CHANGELOG.md"
|
|
46
|
+
],
|
|
34
47
|
"scripts": {
|
|
35
|
-
"build": "
|
|
36
|
-
"clean": "rm -rf lib"
|
|
48
|
+
"build": "pnpm build:node",
|
|
49
|
+
"clean": "rm -rf lib",
|
|
50
|
+
"build:node": "tsc"
|
|
37
51
|
}
|
|
38
52
|
}
|
package/src/index.ts
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Bot,
|
|
3
|
-
PrivateMessageEvent,
|
|
4
|
-
GroupMessageEvent,
|
|
5
|
-
ReceiverMode, ApplicationPlatform
|
|
6
|
-
} from "qq-official-bot";
|
|
7
|
-
import path from "path";
|
|
8
|
-
export {
|
|
9
|
-
ReceiverMode,
|
|
10
|
-
} from 'qq-official-bot'
|
|
11
|
-
export type {
|
|
12
|
-
ApplicationPlatform,
|
|
13
|
-
Intent,
|
|
14
|
-
} from 'qq-official-bot'
|
|
15
|
-
import {
|
|
16
|
-
Bot as ZhinBot,
|
|
17
|
-
usePlugin,
|
|
18
|
-
Adapter,
|
|
19
|
-
Plugin,
|
|
20
|
-
registerAdapter,
|
|
21
|
-
Message,
|
|
22
|
-
SendOptions,
|
|
23
|
-
SendContent,
|
|
24
|
-
segment
|
|
25
|
-
} from "zhin.js";
|
|
26
|
-
// 声明模块,注册 qq 适配器类型
|
|
27
|
-
declare module '@zhin.js/types'{
|
|
28
|
-
interface RegisteredAdapters{
|
|
29
|
-
qq:Adapter<QQBot<ReceiverMode>>
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export type QQBotConfig<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> = ZhinBot.Config &Bot.Config<T,M> &{
|
|
33
|
-
context:'qq'
|
|
34
|
-
name:`${number}`
|
|
35
|
-
}
|
|
36
|
-
export interface QQBot<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform>{
|
|
37
|
-
$config:QQBotConfig<T,M>
|
|
38
|
-
}
|
|
39
|
-
const plugin=usePlugin()
|
|
40
|
-
export class QQBot<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> extends Bot implements ZhinBot<PrivateMessageEvent|GroupMessageEvent,QQBotConfig<T,M>>{
|
|
41
|
-
$connected?:boolean
|
|
42
|
-
constructor(config:QQBotConfig<T,M>) {
|
|
43
|
-
if(!config.data_dir) config.data_dir=path.join(process.cwd(),'data')
|
|
44
|
-
super(config);
|
|
45
|
-
this.$config=config
|
|
46
|
-
}
|
|
47
|
-
private handleQQMessage(msg: PrivateMessageEvent|GroupMessageEvent): void {
|
|
48
|
-
const message =this.$formatMessage(msg) ;
|
|
49
|
-
plugin.dispatch('message.receive',message)
|
|
50
|
-
plugin.logger.info(`${this.$config.name} recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`)
|
|
51
|
-
plugin.dispatch(`message.${message.$channel.type}.receive`,message)
|
|
52
|
-
}
|
|
53
|
-
async $connect(): Promise<void> {
|
|
54
|
-
this.on('message.group',this.handleQQMessage.bind(this))
|
|
55
|
-
this.on('message.guild',this.handleQQMessage.bind(this))
|
|
56
|
-
this.on('message.private',this.handleQQMessage.bind(this))
|
|
57
|
-
await this.start()
|
|
58
|
-
this.$connected=true;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
async $disconnect(): Promise<void> {
|
|
62
|
-
await this.stop()
|
|
63
|
-
this.$connected=false;
|
|
64
|
-
}
|
|
65
|
-
$formatMessage(msg:PrivateMessageEvent|GroupMessageEvent){
|
|
66
|
-
let target_id=msg.user_id;
|
|
67
|
-
if(msg.message_type==='guild') target_id=msg.channel_id!
|
|
68
|
-
if(msg.message_type==='group') target_id=msg.group_id!;
|
|
69
|
-
if(msg.sub_type==='direct') target_id=`direct:${msg.guild_id}`;
|
|
70
|
-
const result= Message.from(msg,{
|
|
71
|
-
$id: msg.message_id?.toString(),
|
|
72
|
-
$adapter:'qq',
|
|
73
|
-
$bot:this.$config.name,
|
|
74
|
-
$sender:{
|
|
75
|
-
id:msg.sender.user_id?.toString(),
|
|
76
|
-
name:msg.sender.user_name?.toString(),
|
|
77
|
-
},
|
|
78
|
-
$channel:{
|
|
79
|
-
id:target_id,
|
|
80
|
-
type:msg.message_type==='guild'?"channel":msg.message_type,
|
|
81
|
-
},
|
|
82
|
-
$content: msg.message,
|
|
83
|
-
$raw: msg.raw_message,
|
|
84
|
-
$timestamp: Date.now(),
|
|
85
|
-
$reply:async (content: SendContent, quote: boolean|string=true):Promise<string>=> {
|
|
86
|
-
if(!Array.isArray(content)) content=[content];
|
|
87
|
-
if(quote) content.unshift({type:'reply',data:{id:typeof quote==="boolean"?result.$id:quote}})
|
|
88
|
-
return await this.$sendMessage({
|
|
89
|
-
...result.$channel,
|
|
90
|
-
context:'qq',
|
|
91
|
-
bot:this.$config.name,
|
|
92
|
-
content
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
return result
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async $sendMessage(options: SendOptions): Promise<string> {
|
|
100
|
-
options=await plugin.app.handleBeforeSend(options)
|
|
101
|
-
switch (options.type){
|
|
102
|
-
case 'private':{
|
|
103
|
-
if(options.id.startsWith('direct:')){
|
|
104
|
-
const id=options.id.replace('direct:','')
|
|
105
|
-
const result= await this.sendDirectMessage(id,options.content)
|
|
106
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
107
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
108
|
-
return `direct-${options.id}:${result.message_id.toString()}`
|
|
109
|
-
}else{
|
|
110
|
-
const result= await this.sendPrivateMessage(options.id,options.content)
|
|
111
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
112
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
113
|
-
return `private-${options.id}:${result.message_id.toString()}`
|
|
114
|
-
}
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
case "group":{
|
|
118
|
-
const result= await this.sendGroupMessage(options.id,options.content)
|
|
119
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
120
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
121
|
-
return `group-${options.id}:${result.message_id.toString()}`
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
case 'channel':{
|
|
125
|
-
const result= await this.sendGuildMessage(options.id,options.content)
|
|
126
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
127
|
-
plugin.logger.info(`${this.$config.name} send ${options.type}(${options.id}):${segment.raw(options.content)}`)
|
|
128
|
-
return `channel-${options.id}:${result.message_id.toString()}`
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
default:
|
|
132
|
-
throw new Error(`unsupported channel type ${options.type}`)
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
async $recallMessage(id:string):Promise<void> {
|
|
136
|
-
if(!/^(private|group|channel|direct)-([^\:]+):(.+)$/.test(id)) throw new Error(`invalid message id ${id}`)
|
|
137
|
-
const [target_type,target_id,message_id]=id.match(/^(private|group|channel|direct)-([^\:]+):(.+)$/)!
|
|
138
|
-
if(target_type==='private') await this.recallPrivateMessage(target_id,message_id)
|
|
139
|
-
if(target_type==='group') await this.recallGroupMessage(target_id,message_id)
|
|
140
|
-
if(target_type==='channel') await this.recallGuildMessage(target_id,message_id)
|
|
141
|
-
if(target_type==='direct') await this.recallDirectMessage(target_id,message_id)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
registerAdapter(new Adapter('qq',QQBot))
|
package/tsconfig.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"outDir": "./lib",
|
|
7
|
-
"rootDir": "./src",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"esModuleInterop": true,
|
|
10
|
-
"skipLibCheck": true,
|
|
11
|
-
"forceConsistentCasingInFileNames": true,
|
|
12
|
-
"resolveJsonModule": true,
|
|
13
|
-
"isolatedModules": true,
|
|
14
|
-
"allowSyntheticDefaultImports": true,
|
|
15
|
-
"experimentalDecorators": true,
|
|
16
|
-
"emitDecoratorMetadata": true,
|
|
17
|
-
"declaration": true,
|
|
18
|
-
"declarationMap": true,
|
|
19
|
-
"sourceMap": true,
|
|
20
|
-
"verbatimModuleSyntax": false
|
|
21
|
-
},
|
|
22
|
-
"include": ["src/**/*"],
|
|
23
|
-
"exclude": ["lib", "node_modules"]
|
|
24
|
-
}
|