@zhin.js/adapter-qq 1.0.1

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 ADDED
@@ -0,0 +1,9 @@
1
+ # @zhin.js/adapter-qq
2
+
3
+ ## 1.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [efdd58a]
8
+ - @zhin.js/types@1.0.1
9
+ - zhin.js@1.0.1
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 凉菜
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/lib/index.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { Bot, PrivateMessageEvent, GroupMessageEvent, ReceiverMode, ApplicationPlatform } from "qq-official-bot";
2
+ export { ReceiverMode, } from 'qq-official-bot';
3
+ export type { ApplicationPlatform, Intent, } from 'qq-official-bot';
4
+ import { Bot as ZhinBot, BotConfig, Adapter, Plugin, Message, SendOptions } from "zhin.js";
5
+ declare module 'zhin.js' {
6
+ interface RegisteredAdapters {
7
+ qq: Adapter<QQBot<ReceiverMode>>;
8
+ }
9
+ }
10
+ export type QQBotConfig<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> = BotConfig & Bot.Config<T, M> & {
11
+ context: 'qq';
12
+ name: `${number}`;
13
+ };
14
+ export interface QQBot<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> {
15
+ $config: QQBotConfig<T, M>;
16
+ }
17
+ export declare class QQBot<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> extends Bot implements ZhinBot<PrivateMessageEvent | GroupMessageEvent, QQBotConfig<T, M>> {
18
+ private plugin;
19
+ $connected?: boolean;
20
+ constructor(plugin: Plugin, config: QQBotConfig<T, M>);
21
+ private handleQQMessage;
22
+ $connect(): Promise<void>;
23
+ $disconnect(): Promise<void>;
24
+ $formatMessage(msg: PrivateMessageEvent | GroupMessageEvent): Message<PrivateMessageEvent | GroupMessageEvent>;
25
+ $sendMessage(options: SendOptions): Promise<void>;
26
+ }
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,GAAG,EACH,mBAAmB,EACnB,iBAAiB,EACjB,YAAY,EAAE,mBAAmB,EACpC,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,YAAY,GACf,MAAM,iBAAiB,CAAA;AACxB,YAAY,EACR,mBAAmB,EACnB,MAAM,GACT,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACH,GAAG,IAAI,OAAO,EACd,SAAS,EACT,OAAO,EACP,MAAM,EAEN,OAAO,EACP,WAAW,EAGd,MAAM,SAAS,CAAC;AACjB,OAAO,QAAQ,SAAS,CAAA;IACpB,UAAU,kBAAkB;QACxB,EAAE,EAAC,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAA;KAClC;CACJ;AACD,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,IAAI,SAAS,GAAE,GAAG,CAAC,MAAM,CAAC,CAAC,EAAC,CAAC,CAAC,GAAE;IAC/H,OAAO,EAAC,IAAI,CAAA;IACZ,IAAI,EAAC,GAAG,MAAM,EAAE,CAAA;CACnB,CAAA;AACD,MAAM,WAAW,KAAK,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,mBAAmB,GAAG,mBAAmB;IAC9F,OAAO,EAAC,WAAW,CAAC,CAAC,EAAC,CAAC,CAAC,CAAA;CAC3B;AACD,qBAAa,KAAK,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,CAAE,SAAQ,GAAI,YAAW,OAAO,CAAC,mBAAmB,GAAC,iBAAiB,EAAC,WAAW,CAAC,CAAC,EAAC,CAAC,CAAC,CAAC;IAEtK,OAAO,CAAC,MAAM;IAD1B,UAAU,CAAC,EAAC,OAAO,CAAA;gBACC,MAAM,EAAC,MAAM,EAAC,MAAM,EAAC,WAAW,CAAC,CAAC,EAAC,CAAC,CAAC;IAKzD,OAAO,CAAC,eAAe;IAMjB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAQzB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAIlC,cAAc,CAAC,GAAG,EAAC,mBAAmB,GAAC,iBAAiB;IAkClD,YAAY,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CA6B1D"}
package/lib/index.js ADDED
@@ -0,0 +1,101 @@
1
+ import { Bot } from "qq-official-bot";
2
+ import path from "path";
3
+ export { ReceiverMode, } from 'qq-official-bot';
4
+ import { Adapter, registerAdapter, Message, segment } from "zhin.js";
5
+ export class QQBot extends Bot {
6
+ plugin;
7
+ $connected;
8
+ constructor(plugin, config) {
9
+ if (!config.data_dir)
10
+ config.data_dir = path.join(process.cwd(), 'data');
11
+ super(config);
12
+ this.plugin = plugin;
13
+ this.$config = config;
14
+ }
15
+ handleQQMessage(msg) {
16
+ const message = this.$formatMessage(msg);
17
+ this.plugin.dispatch('message.receive', message);
18
+ this.plugin.logger.info(`recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`);
19
+ this.plugin.dispatch(`message.${message.$channel.type}.receive`, message);
20
+ }
21
+ async $connect() {
22
+ this.on('message.group', this.handleQQMessage.bind(this));
23
+ this.on('message.guild', this.handleQQMessage.bind(this));
24
+ this.on('message.private', this.handleQQMessage.bind(this));
25
+ await this.start();
26
+ this.$connected = true;
27
+ }
28
+ async $disconnect() {
29
+ await this.stop();
30
+ this.$connected = false;
31
+ }
32
+ $formatMessage(msg) {
33
+ let target_id = msg.user_id;
34
+ if (msg.message_type === 'guild')
35
+ target_id = msg.channel_id;
36
+ if (msg.message_type === 'group')
37
+ target_id = msg.group_id;
38
+ if (msg.sub_type === 'direct')
39
+ target_id = `direct:${msg.guild_id}`;
40
+ const result = Message.from(msg, {
41
+ $id: msg.message_id?.toString(),
42
+ $adapter: 'qq',
43
+ $bot: this.$config.name,
44
+ $sender: {
45
+ id: msg.sender.user_id?.toString(),
46
+ name: msg.sender.user_name?.toString(),
47
+ },
48
+ $channel: {
49
+ id: target_id,
50
+ type: msg.message_type === 'guild' ? "channel" : msg.message_type,
51
+ },
52
+ $content: msg.message,
53
+ $raw: msg.raw_message,
54
+ $timestamp: Date.now(),
55
+ $reply: async (content, quote = true) => {
56
+ if (!Array.isArray(content))
57
+ content = [content];
58
+ if (quote)
59
+ content.unshift({ type: 'reply', data: { id: typeof quote === "boolean" ? result.$id : quote } });
60
+ this.plugin.dispatch('message.send', {
61
+ ...result.$channel,
62
+ context: 'qq',
63
+ bot: this.$config.name,
64
+ content
65
+ });
66
+ }
67
+ });
68
+ return result;
69
+ }
70
+ async $sendMessage(options) {
71
+ options = await this.plugin.app.handleBeforeSend(options);
72
+ switch (options.type) {
73
+ case 'private': {
74
+ if (options.id.startsWith('direct:')) {
75
+ const id = options.id.replace('direct:', '');
76
+ await this.sendDirectMessage(id, options.content);
77
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`);
78
+ }
79
+ else {
80
+ await this.sendPrivateMessage(options.id, options.content);
81
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`);
82
+ }
83
+ break;
84
+ }
85
+ case "group": {
86
+ await this.sendGroupMessage(options.id, options.content);
87
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`);
88
+ break;
89
+ }
90
+ case 'channel': {
91
+ await this.sendGuildMessage(options.id, options.content);
92
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`);
93
+ break;
94
+ }
95
+ default:
96
+ throw new Error(`unsupported channel type ${options.type}`);
97
+ }
98
+ }
99
+ }
100
+ registerAdapter(new Adapter('qq', QQBot));
101
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,GAAG,EAIN,MAAM,iBAAiB,CAAC;AACzB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACH,YAAY,GACf,MAAM,iBAAiB,CAAA;AAKxB,OAAO,EAGH,OAAO,EAEP,eAAe,EACf,OAAO,EAGP,OAAO,EACV,MAAM,SAAS,CAAC;AAajB,MAAM,OAAO,KAAmF,SAAQ,GAAG;IAEnF;IADpB,UAAU,CAAS;IACnB,YAAoB,MAAa,EAAC,MAAuB;QACrD,IAAG,CAAC,MAAM,CAAC,QAAQ;YAAE,MAAM,CAAC,QAAQ,GAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAC,MAAM,CAAC,CAAA;QACpE,KAAK,CAAC,MAAM,CAAC,CAAC;QAFE,WAAM,GAAN,MAAM,CAAO;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CAAC,CAAA,CAAC;gBACV,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBACvD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;gBAC9F,MAAM;YACV,CAAC;YACD,KAAK,SAAS,CAAC,CAAA,CAAC;gBACZ,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,EAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBACvD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;gBAC9F,MAAM;YACV,CAAC;YACD;gBACI,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;QACnE,CAAC;IACL,CAAC;CAEJ;AAED,eAAe,CAAC,IAAI,OAAO,CAAC,IAAI,EAAC,KAAK,CAAC,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@zhin.js/adapter-qq",
3
+ "version": "1.0.1",
4
+ "description": "zhin adapter for qq",
5
+ "type": "module",
6
+ "main": "./lib/index.js",
7
+ "types": "./lib/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./lib/index.d.ts",
11
+ "import": "./lib/index.js"
12
+ }
13
+ },
14
+ "repository": {
15
+ "url": "git+https://github.com/lc-cn/zhin-next.git",
16
+ "type": "git",
17
+ "directory": "adapters/qq"
18
+ },
19
+ "dependencies": {
20
+ "qq-official-bot": "^1.0.11"
21
+ },
22
+ "devDependencies": {
23
+ "typescript": "^5.3.0"
24
+ },
25
+ "peerDependencies": {
26
+ "zhin.js": "1.0.1",
27
+ "@zhin.js/types": "1.0.1"
28
+ },
29
+ "peerDependenciesMeta": {
30
+ "@zhin.js/types": {
31
+ "optional": true
32
+ }
33
+ },
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "clean": "rm -rf lib"
37
+ }
38
+ }
package/src/index.ts ADDED
@@ -0,0 +1,128 @@
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
+ BotConfig,
18
+ Adapter,
19
+ Plugin,
20
+ registerAdapter,
21
+ Message,
22
+ SendOptions,
23
+ SendContent,
24
+ segment
25
+ } from "zhin.js";
26
+ declare module 'zhin.js'{
27
+ interface RegisteredAdapters{
28
+ qq:Adapter<QQBot<ReceiverMode>>
29
+ }
30
+ }
31
+ export type QQBotConfig<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> = BotConfig &Bot.Config<T,M> &{
32
+ context:'qq'
33
+ name:`${number}`
34
+ }
35
+ export interface QQBot<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform>{
36
+ $config:QQBotConfig<T,M>
37
+ }
38
+ export class QQBot<T extends ReceiverMode, M extends ApplicationPlatform = ApplicationPlatform> extends Bot implements ZhinBot<PrivateMessageEvent|GroupMessageEvent,QQBotConfig<T,M>>{
39
+ $connected?:boolean
40
+ constructor(private plugin:Plugin,config:QQBotConfig<T,M>) {
41
+ if(!config.data_dir) config.data_dir=path.join(process.cwd(),'data')
42
+ super(config);
43
+ this.$config=config
44
+ }
45
+ private handleQQMessage(msg: PrivateMessageEvent|GroupMessageEvent): void {
46
+ const message =this.$formatMessage(msg) ;
47
+ this.plugin.dispatch('message.receive',message)
48
+ this.plugin.logger.info(`recv ${message.$channel.type}(${message.$channel.id}):${segment.raw(message.$content)}`)
49
+ this.plugin.dispatch(`message.${message.$channel.type}.receive`,message)
50
+ }
51
+ async $connect(): Promise<void> {
52
+ this.on('message.group',this.handleQQMessage.bind(this))
53
+ this.on('message.guild',this.handleQQMessage.bind(this))
54
+ this.on('message.private',this.handleQQMessage.bind(this))
55
+ await this.start()
56
+ this.$connected=true;
57
+ }
58
+
59
+ async $disconnect(): Promise<void> {
60
+ await this.stop()
61
+ this.$connected=false;
62
+ }
63
+ $formatMessage(msg:PrivateMessageEvent|GroupMessageEvent){
64
+ let target_id=msg.user_id;
65
+ if(msg.message_type==='guild') target_id=msg.channel_id!
66
+ if(msg.message_type==='group') target_id=msg.group_id!;
67
+ if(msg.sub_type==='direct') target_id=`direct:${msg.guild_id}`;
68
+ const result= Message.from(msg,{
69
+ $id: msg.message_id?.toString(),
70
+ $adapter:'qq',
71
+ $bot:this.$config.name,
72
+ $sender:{
73
+ id:msg.sender.user_id?.toString(),
74
+ name:msg.sender.user_name?.toString(),
75
+ },
76
+ $channel:{
77
+ id:target_id,
78
+ type:msg.message_type==='guild'?"channel":msg.message_type,
79
+ },
80
+ $content: msg.message,
81
+ $raw: msg.raw_message,
82
+ $timestamp: Date.now(),
83
+ $reply:async (content: SendContent, quote: boolean|string=true):Promise<void>=> {
84
+ if(!Array.isArray(content)) content=[content];
85
+ if(quote) content.unshift({type:'reply',data:{id:typeof quote==="boolean"?result.$id:quote}})
86
+ this.plugin.dispatch('message.send',{
87
+ ...result.$channel,
88
+ context:'qq',
89
+ bot:this.$config.name,
90
+ content
91
+ })
92
+ }
93
+ })
94
+ return result
95
+ }
96
+
97
+ async $sendMessage(options: SendOptions): Promise<void> {
98
+ options=await this.plugin.app.handleBeforeSend(options)
99
+ switch (options.type){
100
+ case 'private':{
101
+ if(options.id.startsWith('direct:')){
102
+ const id=options.id.replace('direct:','')
103
+ await this.sendDirectMessage(id,options.content)
104
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`)
105
+ }else{
106
+ await this.sendPrivateMessage(options.id,options.content)
107
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`)
108
+ }
109
+ break;
110
+ }
111
+ case "group":{
112
+ await this.sendGroupMessage(options.id,options.content)
113
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`)
114
+ break;
115
+ }
116
+ case 'channel':{
117
+ await this.sendGuildMessage(options.id,options.content)
118
+ this.plugin.logger.info(`send ${options.type}(${options.id}):${segment.raw(options.content)}`)
119
+ break;
120
+ }
121
+ default:
122
+ throw new Error(`unsupported channel type ${options.type}`)
123
+ }
124
+ }
125
+
126
+ }
127
+
128
+ registerAdapter(new Adapter('qq',QQBot))
package/tsconfig.json ADDED
@@ -0,0 +1,24 @@
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
+ }