@karinjs/adapter-qqbot 1.2.1 → 1.2.3
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/lib/core/api.d.ts +5 -8
- package/lib/core/api.js +6 -5
- package/lib/core/index.js +7 -7
- package/lib/index.js +1 -1
- package/package.json +1 -1
package/lib/core/api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import WebSocket from 'ws';
|
|
2
|
-
import
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
3
|
import { AccountCfgType } from '../utils/index.js';
|
|
4
|
+
import { LoggerLevel } from 'node-karin';
|
|
4
5
|
import { IdType, FileType, PathType, V2ApiType, UploadMediaOptions, SendMessageOptions, UploadMediaResponse, SubEvent } from '../types/index.js';
|
|
5
6
|
export interface SendMessageResponse {
|
|
6
7
|
/** 消息唯一ID */
|
|
@@ -15,7 +16,7 @@ export type Params = Array<{
|
|
|
15
16
|
key: string;
|
|
16
17
|
values: string[];
|
|
17
18
|
}>;
|
|
18
|
-
export declare class QQBotApi {
|
|
19
|
+
export declare class QQBotApi extends EventEmitter {
|
|
19
20
|
#private;
|
|
20
21
|
/** 开发者的appId */
|
|
21
22
|
appId: string;
|
|
@@ -57,13 +58,9 @@ export declare class QQBotApi {
|
|
|
57
58
|
* @param isRefresh 是否是刷新凭证
|
|
58
59
|
*/
|
|
59
60
|
getAccessToken(isRefresh?: boolean): Promise<{
|
|
60
|
-
/**
|
|
61
|
-
* 凭证有效时间,单位:秒 需要在倒计时50秒内刷新凭证
|
|
62
|
-
*/
|
|
61
|
+
/** 凭证有效时间,单位:秒 需要在倒计时50秒内刷新凭证 */
|
|
63
62
|
expires_in: string;
|
|
64
|
-
/**
|
|
65
|
-
* 调用凭证
|
|
66
|
-
*/
|
|
63
|
+
/** 调用凭证 */
|
|
67
64
|
access_token: string;
|
|
68
65
|
}>;
|
|
69
66
|
/**
|
package/lib/core/api.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import got from 'got';
|
|
2
2
|
import WebSocket from 'ws';
|
|
3
|
+
import EventEmitter from 'events';
|
|
3
4
|
import { Intents } from './intents.js';
|
|
4
5
|
import { common, logger } from 'node-karin';
|
|
5
|
-
export class QQBotApi {
|
|
6
|
+
export class QQBotApi extends EventEmitter {
|
|
6
7
|
/** 开发者的appId */
|
|
7
8
|
appId;
|
|
8
9
|
/** Bot头像 */
|
|
@@ -29,6 +30,7 @@ export class QQBotApi {
|
|
|
29
30
|
host;
|
|
30
31
|
#config;
|
|
31
32
|
constructor(config) {
|
|
33
|
+
super();
|
|
32
34
|
this.#config = config;
|
|
33
35
|
this.appId = String(this.#config.appId);
|
|
34
36
|
this.avatar = '';
|
|
@@ -78,7 +80,6 @@ export class QQBotApi {
|
|
|
78
80
|
const time = Number(expires_in) * 1000 - 50000;
|
|
79
81
|
setTimeout(async () => {
|
|
80
82
|
this.getAccessToken(true);
|
|
81
|
-
/** 重新鉴权 */
|
|
82
83
|
}, time);
|
|
83
84
|
return data;
|
|
84
85
|
}
|
|
@@ -210,17 +211,17 @@ export class QQBotApi {
|
|
|
210
211
|
const info = await this.getBotInfo();
|
|
211
212
|
this.avatar = info.avatar;
|
|
212
213
|
this.nick = data.d.user.username;
|
|
213
|
-
this.
|
|
214
|
+
this.emit('start');
|
|
214
215
|
break;
|
|
215
216
|
}
|
|
216
217
|
case "GROUP_AT_MESSAGE_CREATE" /* EventType.GROUP_AT_MESSAGE_CREATE */: {
|
|
217
218
|
this.heartbeat.d = data.s;
|
|
218
|
-
this.
|
|
219
|
+
this.emit("GROUP_AT_MESSAGE_CREATE" /* EventType.GROUP_AT_MESSAGE_CREATE */, data);
|
|
219
220
|
break;
|
|
220
221
|
}
|
|
221
222
|
case "C2C_MESSAGE_CREATE" /* EventType.C2C_MESSAGE_CREATE */: {
|
|
222
223
|
this.heartbeat.d = data.s;
|
|
223
|
-
this.
|
|
224
|
+
this.emit("C2C_MESSAGE_CREATE" /* EventType.C2C_MESSAGE_CREATE */, data);
|
|
224
225
|
break;
|
|
225
226
|
}
|
|
226
227
|
// case 'GUILD_CREATE':
|
package/lib/core/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { QQBotApi } from './api.js';
|
|
2
2
|
import { markdownTemplate, markdownRaw } from './markdown.js';
|
|
3
3
|
import { common, common as Common, config as Config, } from '../utils/index.js';
|
|
4
|
-
import { logger,
|
|
4
|
+
import { logger, karin, segment, KarinMessage, } from 'node-karin';
|
|
5
5
|
/**
|
|
6
6
|
* - QQBot适配器
|
|
7
7
|
*/
|
|
@@ -47,7 +47,7 @@ export class AdapterQQBot {
|
|
|
47
47
|
await this.super.getAccessToken();
|
|
48
48
|
await this.super.getWssUrl();
|
|
49
49
|
this.super.createWss();
|
|
50
|
-
this.super.
|
|
50
|
+
this.super.on("GROUP_AT_MESSAGE_CREATE" /* QQBotEventType.GROUP_AT_MESSAGE_CREATE */, (data) => {
|
|
51
51
|
const user_id = data.d.author.id;
|
|
52
52
|
const group_id = data.d.group_id;
|
|
53
53
|
const time = new Date(data.d.timestamp).getTime();
|
|
@@ -79,9 +79,9 @@ export class AdapterQQBot {
|
|
|
79
79
|
const e = new KarinMessage(message);
|
|
80
80
|
e.bot = this;
|
|
81
81
|
e.replyCallback = async (elements) => await this._sendNsg(elements, "groups" /* PathType.Groups */, e.contact.peer, e.message_id);
|
|
82
|
-
|
|
82
|
+
karin.emit('adapter.message', e);
|
|
83
83
|
});
|
|
84
|
-
this.super.
|
|
84
|
+
this.super.on("C2C_MESSAGE_CREATE" /* QQBotEventType.C2C_MESSAGE_CREATE */, (data) => {
|
|
85
85
|
const user_id = data.d.author.user_openid;
|
|
86
86
|
const time = new Date(data.d.timestamp).getTime();
|
|
87
87
|
const message = {
|
|
@@ -112,14 +112,14 @@ export class AdapterQQBot {
|
|
|
112
112
|
const e = new KarinMessage(message);
|
|
113
113
|
e.bot = this;
|
|
114
114
|
e.replyCallback = async (elements) => await this._sendNsg(elements, "users" /* PathType.Friends */, e.contact.peer, e.message_id);
|
|
115
|
-
|
|
115
|
+
karin.emit('adapter.message', e);
|
|
116
116
|
});
|
|
117
117
|
/** 等待建立连接 注册Bot */
|
|
118
|
-
this.super.
|
|
118
|
+
this.super.on('start', () => {
|
|
119
119
|
this.account.name = this.super.nick;
|
|
120
120
|
this.logger('info', `建立连接成功: ${this.account.name}`);
|
|
121
121
|
/** 注册bot */
|
|
122
|
-
const index =
|
|
122
|
+
const index = karin.addBot({ type: this.adapter.type, bot: this });
|
|
123
123
|
if (index)
|
|
124
124
|
this.adapter.index = index;
|
|
125
125
|
});
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import './core/index.js';
|
|
2
|
+
import Jimp from 'jimp';
|
|
2
3
|
import { logger, common } from 'node-karin';
|
|
3
4
|
import { basename, dirPath } from './utils/dir.js';
|
|
4
|
-
import Jimp from 'jimp';
|
|
5
5
|
const pkg = common.readJson(dirPath + '/package.json');
|
|
6
6
|
logger.info(`${logger.violet(`[插件:${pkg.version}]`)} ${logger.green(basename)} 初始化完成~`);
|
|
7
7
|
export default Jimp;
|