onebots 0.4.23 → 0.4.26
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 +25 -3
- package/lib/adapter.d.ts +55 -0
- package/lib/adapter.js +60 -0
- package/lib/adapters/icqq/index.d.ts +36 -0
- package/lib/adapters/icqq/index.js +300 -0
- package/lib/adapters/qq/bot.d.ts +22 -0
- package/lib/adapters/qq/bot.js +20 -0
- package/lib/adapters/qq/constans.d.ts +69 -0
- package/lib/adapters/qq/constans.js +128 -0
- package/lib/adapters/qq/elements.d.ts +125 -0
- package/lib/adapters/qq/elements.js +8 -0
- package/lib/adapters/qq/entries/channel.d.ts +17 -0
- package/lib/adapters/qq/entries/channel.js +2 -0
- package/lib/adapters/qq/entries/friend.d.ts +8 -0
- package/lib/adapters/qq/entries/friend.js +2 -0
- package/lib/adapters/qq/entries/group.d.ts +6 -0
- package/lib/adapters/qq/entries/group.js +2 -0
- package/lib/adapters/qq/entries/groupMember.d.ts +7 -0
- package/lib/adapters/qq/entries/groupMember.js +2 -0
- package/lib/adapters/qq/entries/guild.d.ts +21 -0
- package/lib/adapters/qq/entries/guild.js +2 -0
- package/lib/adapters/qq/entries/guildMember.d.ts +9 -0
- package/lib/adapters/qq/entries/guildMember.js +2 -0
- package/lib/adapters/qq/entries/user.d.ts +9 -0
- package/lib/adapters/qq/entries/user.js +2 -0
- package/lib/adapters/qq/event.d.ts +28 -0
- package/lib/adapters/qq/event.js +24 -0
- package/lib/adapters/qq/index.d.ts +35 -0
- package/lib/adapters/qq/index.js +172 -0
- package/lib/adapters/qq/message.d.ts +84 -0
- package/lib/adapters/qq/message.js +272 -0
- package/lib/adapters/qq/qqBot.d.ts +122 -0
- package/lib/adapters/qq/qqBot.js +440 -0
- package/lib/adapters/qq/sessionManager.d.ts +33 -0
- package/lib/adapters/qq/sessionManager.js +257 -0
- package/lib/adapters/qq/types.d.ts +45 -0
- package/lib/adapters/qq/types.js +2 -0
- package/lib/adapters/qq/utils.d.ts +12 -0
- package/lib/adapters/qq/utils.js +86 -0
- package/lib/bin.js +17 -2
- package/lib/config.sample.yaml +23 -5
- package/lib/onebot.d.ts +32 -24
- package/lib/onebot.js +51 -188
- package/lib/server/app.d.ts +22 -12
- package/lib/server/app.js +97 -71
- package/lib/service/V11/action/common.d.ts +9 -11
- package/lib/service/V11/action/common.js +27 -64
- package/lib/service/V11/action/friend.d.ts +5 -13
- package/lib/service/V11/action/friend.js +6 -16
- package/lib/service/V11/action/group.d.ts +19 -22
- package/lib/service/V11/action/group.js +20 -30
- package/lib/service/V11/action/index.d.ts +1 -1
- package/lib/service/V11/db_entities.d.ts +1 -1
- package/lib/service/V11/db_entities.js +1 -1
- package/lib/service/V11/db_sqlite.d.ts +1 -1
- package/lib/service/V11/index.d.ts +47 -16
- package/lib/service/V11/index.js +143 -164
- package/lib/service/V12/action/common.d.ts +3 -67
- package/lib/service/V12/action/common.js +9 -63
- package/lib/service/V12/action/friend.d.ts +4 -10
- package/lib/service/V12/action/friend.js +4 -12
- package/lib/service/V12/action/group.d.ts +19 -21
- package/lib/service/V12/action/group.js +19 -27
- package/lib/service/V12/action/guild.d.ts +40 -13
- package/lib/service/V12/action/guild.js +99 -11
- package/lib/service/V12/action/index.d.ts +1 -1
- package/lib/service/V12/index.d.ts +37 -13
- package/lib/service/V12/index.js +44 -72
- package/lib/service.d.ts +7 -2
- package/lib/service.js +32 -30
- package/lib/utils.d.ts +7 -4
- package/lib/utils.js +33 -28
- package/package.json +5 -4
- package/lib/service/V12/utils.d.ts +0 -8
- package/lib/service/V12/utils.js +0 -47
- /package/lib/{service/V11 → adapters/icqq}/utils.d.ts +0 -0
- /package/lib/{service/V11 → adapters/icqq}/utils.js +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1
|
|
2
|
+
<h1>使用ts实现的oneBot应用启动器,支持icqq和qq官方机器人</h1>
|
|
3
3
|
<p>
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/onebots) [](https://github.com/icqqjs/onebots/actions/workflows/release.yml) [](https://www.npmjs.com/package/onebots) [](https://onebot.dev/)
|
|
@@ -50,7 +50,8 @@ npm install onebots icqq
|
|
|
50
50
|
## 3. 执行如下命令生成配置文件
|
|
51
51
|
|
|
52
52
|
```shell
|
|
53
|
-
npx onebots
|
|
53
|
+
npx onebots -r icqq #注册icqq适配器并启动onebots
|
|
54
|
+
npx onebots -r qq #注册qq官方适配器并启动onebots
|
|
54
55
|
```
|
|
55
56
|
|
|
56
57
|
## 4. 更改生成的默认配置文件成你想要的配置配置后再次运行上面的指令,启动项目
|
|
@@ -94,7 +95,7 @@ general: # 通用配置,在单个配置省略时的默认值
|
|
|
94
95
|
password: "" # 账号密码,未配置则扫码登陆
|
|
95
96
|
# ...其他配置项参考icqq的Config配置
|
|
96
97
|
# 每个账号的单独配置(用于覆盖通用配置)
|
|
97
|
-
123456789:
|
|
98
|
+
icqq.123456789:
|
|
98
99
|
password: "" # 账号密码,未配置则扫码登陆
|
|
99
100
|
version: V11 # 使用的oneBot版本
|
|
100
101
|
# ...其他配置项参见上方对应oneBot版本的通用配置
|
|
@@ -102,6 +103,27 @@ general: # 通用配置,在单个配置省略时的默认值
|
|
|
102
103
|
platform: 2
|
|
103
104
|
sign_api_addr: "" #你的签名地址
|
|
104
105
|
# ...其他配置项参考icqq的Config配置
|
|
106
|
+
|
|
107
|
+
qq.123456789: # `${适配器名称}:${appId}`
|
|
108
|
+
versions:
|
|
109
|
+
- version: V11
|
|
110
|
+
# 。。。其他配置项参见上方对应oneBot版本的通用配置
|
|
111
|
+
protocol: # 将会覆盖通用配置中的protocol
|
|
112
|
+
token: '' # qq机器人token
|
|
113
|
+
secret: '' # qq机器人secret
|
|
114
|
+
sandbox: false # 是否沙箱环境
|
|
115
|
+
intents: # 需要监听的intents
|
|
116
|
+
- 'GROUP_AT_MESSAGE_CREATE' # 群聊@事件 没有群聊权限请注释
|
|
117
|
+
- 'C2C_MESSAGE_CREATE' # 私聊事件 没有私聊权限请注释
|
|
118
|
+
- 'DIRECT_MESSAGE' # 频道私信事件
|
|
119
|
+
# - 'GUILD_MESSAGES' # 私域机器人频道消息事件,公域机器人请注释
|
|
120
|
+
- 'GUILDS' # 频道变更事件
|
|
121
|
+
- 'GUILD_MEMBERS' # 频道成员变更事件
|
|
122
|
+
- 'GUILD_MESSAGE_REACTIONS' # 频道消息表态事件
|
|
123
|
+
- 'INTERACTION' # 互动事件
|
|
124
|
+
- 'PUBLIC_GUILD_MESSAGES' # 公域机器人频道消息事件,私域机器人请注释
|
|
125
|
+
# 。。。其他配置项参见上方对应oneBot版本的通用配置
|
|
126
|
+
|
|
105
127
|
```
|
|
106
128
|
|
|
107
129
|
# 配置解释
|
package/lib/adapter.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { App } from "./server/app";
|
|
4
|
+
import { OneBot } from "./onebot";
|
|
5
|
+
import { Dict } from "@zhinjs/shared";
|
|
6
|
+
import { Logger } from "log4js";
|
|
7
|
+
export declare abstract class Adapter<T extends string = string> extends EventEmitter {
|
|
8
|
+
#private;
|
|
9
|
+
app: App;
|
|
10
|
+
platform: T;
|
|
11
|
+
config: Adapter.Configs[T];
|
|
12
|
+
oneBots: Map<string, OneBot>;
|
|
13
|
+
protected constructor(app: App, platform: T, config: Adapter.Configs[T]);
|
|
14
|
+
get logger(): Logger;
|
|
15
|
+
getLogger(uin: string, version?: string): Logger;
|
|
16
|
+
createOneBot(uin: string, protocol: Dict, versions: OneBot.Config[]): OneBot;
|
|
17
|
+
start(uin?: string): Promise<any>;
|
|
18
|
+
stop(uin?: string, force?: boolean): Promise<any>;
|
|
19
|
+
}
|
|
20
|
+
export interface Adapter extends Adapter.Base {
|
|
21
|
+
call<V extends OneBot.Version>(uin: string, version: V, method: string, args?: any[]): Promise<any>;
|
|
22
|
+
}
|
|
23
|
+
export declare namespace Adapter {
|
|
24
|
+
interface Base {
|
|
25
|
+
toSegment<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): OneBot.Segment<V>[];
|
|
26
|
+
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V>): OneBot.MessageElement<V>[];
|
|
27
|
+
toCqcode<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): string;
|
|
28
|
+
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
29
|
+
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
30
|
+
/** 格式化事件 */
|
|
31
|
+
formatEventPayload<V extends OneBot.Version>(version: V, event: string, payload: Dict): OneBot.Payload<V>;
|
|
32
|
+
/** 解析消息事件的消息 */
|
|
33
|
+
parseMessage<V extends OneBot.Version>(version: V, payload: Dict): OneBot.Message<V>[];
|
|
34
|
+
/** 获取群列表 */
|
|
35
|
+
getGroupList<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.GroupInfo<V>[]>;
|
|
36
|
+
/** 获取好友列表 */
|
|
37
|
+
getFriendList<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.UserInfo<V>[]>;
|
|
38
|
+
getGroupMemberList<V extends OneBot.Version>(uin: string, version: V, args: [string]): Promise<OneBot.GroupMemberInfo<V>[]>;
|
|
39
|
+
/** 发送群消息 */
|
|
40
|
+
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
41
|
+
/** 发送私聊消息 */
|
|
42
|
+
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
43
|
+
/** 获取消息 */
|
|
44
|
+
getMessage<V extends OneBot.Version>(uin: string, version: V): Promise<OneBot.Message<V>>;
|
|
45
|
+
deleteMessage<V extends OneBot.Version>(uin: string, version: V, args: [string]): Promise<boolean>;
|
|
46
|
+
}
|
|
47
|
+
interface Configs {
|
|
48
|
+
[key: string]: Adapter.Config;
|
|
49
|
+
}
|
|
50
|
+
type Config<T extends string = string> = {
|
|
51
|
+
platform?: T;
|
|
52
|
+
versions: OneBot.Config<OneBot.Version>[];
|
|
53
|
+
protocol?: Dict;
|
|
54
|
+
} & Record<string, any>;
|
|
55
|
+
}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _Adapter_logger;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.Adapter = void 0;
|
|
16
|
+
const events_1 = require("events");
|
|
17
|
+
const onebot_1 = require("./onebot");
|
|
18
|
+
class Adapter extends events_1.EventEmitter {
|
|
19
|
+
constructor(app, platform, config) {
|
|
20
|
+
super();
|
|
21
|
+
this.app = app;
|
|
22
|
+
this.platform = platform;
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.oneBots = new Map();
|
|
25
|
+
_Adapter_logger.set(this, void 0);
|
|
26
|
+
}
|
|
27
|
+
get logger() {
|
|
28
|
+
return __classPrivateFieldSet(this, _Adapter_logger, __classPrivateFieldGet(this, _Adapter_logger, "f") || this.app.getLogger(this.platform), "f");
|
|
29
|
+
}
|
|
30
|
+
getLogger(uin, version) {
|
|
31
|
+
if (!version)
|
|
32
|
+
return this.app.getLogger(`${this.platform}-${uin}`);
|
|
33
|
+
return this.app.getLogger(`${this.platform}-${version}(${uin})`);
|
|
34
|
+
}
|
|
35
|
+
createOneBot(uin, protocol, versions) {
|
|
36
|
+
const oneBot = new onebot_1.OneBot(this, uin, versions);
|
|
37
|
+
this.oneBots.set(uin, oneBot);
|
|
38
|
+
return oneBot;
|
|
39
|
+
}
|
|
40
|
+
async start(uin) {
|
|
41
|
+
const startOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
42
|
+
return uin ? oneBot.uin === uin : true;
|
|
43
|
+
});
|
|
44
|
+
for (const oneBot of startOneBots) {
|
|
45
|
+
await oneBot.start();
|
|
46
|
+
}
|
|
47
|
+
this.app.emit('adapter.start', this.platform);
|
|
48
|
+
}
|
|
49
|
+
async stop(uin, force) {
|
|
50
|
+
const stopOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
51
|
+
return uin ? oneBot.uin === uin : true;
|
|
52
|
+
});
|
|
53
|
+
for (const oneBot of stopOneBots) {
|
|
54
|
+
await oneBot.stop(force);
|
|
55
|
+
}
|
|
56
|
+
this.app.emit('adapter.stop', this.platform);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Adapter = Adapter;
|
|
60
|
+
_Adapter_logger = new WeakMap();
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Adapter } from "../../adapter";
|
|
2
|
+
import { App } from "../../server/app";
|
|
3
|
+
import { Config as IcqqConfig } from "icqq/lib/client";
|
|
4
|
+
import { Dict } from "@zhinjs/shared";
|
|
5
|
+
import { OneBot } from "../../onebot";
|
|
6
|
+
export default class IcqqAdapter extends Adapter<'icqq'> {
|
|
7
|
+
#private;
|
|
8
|
+
constructor(app: App, config: IcqqAdapter.Config);
|
|
9
|
+
createOneBot(uin: string, protocol: Dict, versions: OneBot.Config[]): OneBot;
|
|
10
|
+
formatEventPayload<V extends OneBot.Version>(version: V, event: string, data: any): OneBot.Payload<V>;
|
|
11
|
+
toMessageElement<V extends OneBot.Version>(event: any): OneBot.MessageElement<V>[];
|
|
12
|
+
sendPrivateMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
13
|
+
sendGroupMessage<V extends OneBot.Version>(uin: string, version: V, args: [string, OneBot.MessageElement<V>[]]): Promise<OneBot.MessageRet<V>>;
|
|
14
|
+
call<V extends OneBot.Version>(uin: string, version: V, method: string, args?: any[]): Promise<any>;
|
|
15
|
+
fromSegment<V extends OneBot.Version>(version: V, segment: OneBot.Segment<V> | OneBot.Segment<V>[]): OneBot.MessageElement<V>[];
|
|
16
|
+
toSegment<V extends OneBot.Version>(version: V, message: OneBot.MessageElement<V>[]): OneBot.Segment<V>[];
|
|
17
|
+
fromCqcode<V extends OneBot.Version>(version: V, message: string): OneBot.MessageElement<V>[];
|
|
18
|
+
toCqcode<V extends OneBot.Version>(version: V, messageArr: OneBot.MessageElement<V>[]): string;
|
|
19
|
+
getSelfInfo<V extends OneBot.Version>(uin: string, version: V): OneBot.SelfInfo<V>;
|
|
20
|
+
startOneBot(oneBot: OneBot): Promise<Function>;
|
|
21
|
+
start(uin?: string): Promise<void>;
|
|
22
|
+
stop(uin?: string, force?: boolean): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
declare module '../../adapter' {
|
|
25
|
+
namespace Adapter {
|
|
26
|
+
interface Configs {
|
|
27
|
+
icqq: IcqqAdapter.Config;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export declare namespace IcqqAdapter {
|
|
32
|
+
interface Config extends Adapter.Config<'icqq'> {
|
|
33
|
+
protocol?: IcqqConfig;
|
|
34
|
+
password?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
var _IcqqAdapter_password, _IcqqAdapter_disposes;
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const adapter_1 = require("../../adapter");
|
|
19
|
+
const icqq_1 = require("icqq");
|
|
20
|
+
const process_1 = __importDefault(require("process"));
|
|
21
|
+
const fs_1 = require("fs");
|
|
22
|
+
const onebot_1 = require("../../onebot");
|
|
23
|
+
class IcqqAdapter extends adapter_1.Adapter {
|
|
24
|
+
constructor(app, config) {
|
|
25
|
+
super(app, 'icqq', config);
|
|
26
|
+
_IcqqAdapter_password.set(this, void 0);
|
|
27
|
+
_IcqqAdapter_disposes.set(this, new Map());
|
|
28
|
+
}
|
|
29
|
+
createOneBot(uin, protocol, versions) {
|
|
30
|
+
const oneBot = super.createOneBot(uin, protocol, versions);
|
|
31
|
+
__classPrivateFieldSet(this, _IcqqAdapter_password, this.app.config[`icqq.${uin}`].password, "f");
|
|
32
|
+
oneBot.internal = new icqq_1.Client(protocol);
|
|
33
|
+
return oneBot;
|
|
34
|
+
}
|
|
35
|
+
formatEventPayload(version, event, data) {
|
|
36
|
+
return {
|
|
37
|
+
id: data.id,
|
|
38
|
+
type: event,
|
|
39
|
+
version: version,
|
|
40
|
+
self: {
|
|
41
|
+
platform: 'icqq',
|
|
42
|
+
user_id: data.self_id
|
|
43
|
+
},
|
|
44
|
+
detail_type: data.message_type || data.notice_type || data.request_type,
|
|
45
|
+
platform: 'icqq',
|
|
46
|
+
...data,
|
|
47
|
+
message: this.toMessageElement(data)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
toMessageElement(event) {
|
|
51
|
+
if (!event || !event.message)
|
|
52
|
+
return null;
|
|
53
|
+
const messageArr = [].concat(event.message);
|
|
54
|
+
const result = [];
|
|
55
|
+
if (event.source) {
|
|
56
|
+
result.push({
|
|
57
|
+
type: 'quote',
|
|
58
|
+
data: {
|
|
59
|
+
id: `${event.source.rand}${event.source.seq}_${event.source.time}`,
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
for (const message of messageArr) {
|
|
64
|
+
if (typeof message === 'string') {
|
|
65
|
+
result.push({
|
|
66
|
+
type: 'text',
|
|
67
|
+
data: {
|
|
68
|
+
text: message
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const { type, ...data } = message;
|
|
74
|
+
result.push({
|
|
75
|
+
type,
|
|
76
|
+
data
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
sendPrivateMessage(uin, version, args) {
|
|
83
|
+
const [user_id, message] = args;
|
|
84
|
+
const result = this.oneBots.get(uin)?.internal.sendPrivateMsg(user_id, message.map(m => {
|
|
85
|
+
return {
|
|
86
|
+
type: m.type,
|
|
87
|
+
...(m.data || {})
|
|
88
|
+
};
|
|
89
|
+
}));
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
sendGroupMessage(uin, version, args) {
|
|
93
|
+
const [group_id, message] = args;
|
|
94
|
+
const result = this.oneBots.get(uin)?.internal.sendGroupMsg(group_id, message.map(m => {
|
|
95
|
+
return {
|
|
96
|
+
type: m.type,
|
|
97
|
+
...(m.data || {})
|
|
98
|
+
};
|
|
99
|
+
}));
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
call(uin, version, method, args = []) {
|
|
103
|
+
try {
|
|
104
|
+
if (this[method])
|
|
105
|
+
return this[method](uin, version, args);
|
|
106
|
+
return this.oneBots.get(uin)?.internal[method](...args);
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
throw onebot_1.OneBot.UnsupportedMethodError;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
fromSegment(version, segment) {
|
|
113
|
+
return [].concat(segment).map(item => {
|
|
114
|
+
if (typeof item === "string")
|
|
115
|
+
return {
|
|
116
|
+
type: 'text',
|
|
117
|
+
data: {
|
|
118
|
+
text: item
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
122
|
+
type: item.type,
|
|
123
|
+
data: item
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
toSegment(version, message) {
|
|
128
|
+
return [].concat(message).map(item => {
|
|
129
|
+
if (!item || typeof item !== "object")
|
|
130
|
+
return {
|
|
131
|
+
type: 'text',
|
|
132
|
+
data: {
|
|
133
|
+
text: item
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const { type, ...data } = item;
|
|
137
|
+
return {
|
|
138
|
+
type,
|
|
139
|
+
data
|
|
140
|
+
};
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
fromCqcode(version, message) {
|
|
144
|
+
const regExpMatchArray = message.match(/\[CQ:([a-z]+),(!])+]/g);
|
|
145
|
+
if (!regExpMatchArray)
|
|
146
|
+
return [
|
|
147
|
+
{
|
|
148
|
+
type: 'text',
|
|
149
|
+
data: {
|
|
150
|
+
text: message
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
];
|
|
154
|
+
const result = [];
|
|
155
|
+
for (const match of regExpMatchArray) {
|
|
156
|
+
const [type, ...valueArr] = match.substring(1, match.length - 1).split(',');
|
|
157
|
+
result.push({
|
|
158
|
+
type: type,
|
|
159
|
+
data: Object.fromEntries(valueArr.map(item => {
|
|
160
|
+
const [key, value] = item.split('=');
|
|
161
|
+
return [key, value];
|
|
162
|
+
}))
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
toCqcode(version, messageArr) {
|
|
168
|
+
return [].concat(messageArr).map(item => {
|
|
169
|
+
const dataStr = Object.entries(item.data).map(([key, value]) => {
|
|
170
|
+
// is Buffer
|
|
171
|
+
if (value instanceof Buffer)
|
|
172
|
+
return `${key}=${value.toString('base64')}`;
|
|
173
|
+
// is Object
|
|
174
|
+
if (value instanceof Object)
|
|
175
|
+
return `${key}=${JSON.stringify(value)}`;
|
|
176
|
+
// is Array
|
|
177
|
+
if (value instanceof Array)
|
|
178
|
+
return `${key}=${value.map(v => JSON.stringify(v)).join(',')}`;
|
|
179
|
+
// is String
|
|
180
|
+
return `${key}=${item.data[key]}`;
|
|
181
|
+
});
|
|
182
|
+
return `[CQ:${item.type},${dataStr.join(',')}]`;
|
|
183
|
+
}).join('');
|
|
184
|
+
}
|
|
185
|
+
getSelfInfo(uin, version) {
|
|
186
|
+
const client = this.oneBots.get(uin).internal;
|
|
187
|
+
return {
|
|
188
|
+
nickname: client.nickname,
|
|
189
|
+
status: this.oneBots.get(uin).status,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
async startOneBot(oneBot) {
|
|
193
|
+
const _this = this;
|
|
194
|
+
const disposeArr = [];
|
|
195
|
+
const client = oneBot.internal;
|
|
196
|
+
client.trap('system.login.qrcode', function qrcodeHelper() {
|
|
197
|
+
_this.logger.log('扫码后回车继续');
|
|
198
|
+
process_1.default.stdin.once('data', () => {
|
|
199
|
+
this.login();
|
|
200
|
+
});
|
|
201
|
+
disposeArr.push(() => {
|
|
202
|
+
this.off('system.login.qrcode', qrcodeHelper);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
client.trap('system.login.device', function deviceHelper(e) {
|
|
206
|
+
_this.logger.mark('请选择验证方式:1.短信验证 2.url验证');
|
|
207
|
+
process_1.default.stdin.once('data', (buf) => {
|
|
208
|
+
const input = buf.toString().trim();
|
|
209
|
+
if (input === '1') {
|
|
210
|
+
this.sendSmsCode();
|
|
211
|
+
_this.logger.mark('请输入短信验证码:');
|
|
212
|
+
process_1.default.stdin.once('data', buf => {
|
|
213
|
+
this.submitSmsCode(buf.toString().trim());
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
_this.logger.mark(`请前往:${e.url} 完成验证后回车继续`);
|
|
218
|
+
process_1.default.stdin.once('data', () => {
|
|
219
|
+
this.login();
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
disposeArr.push(() => {
|
|
224
|
+
this.off('system.login.device', deviceHelper);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
client.trap('system.login.slider', function sliderHelper(e) {
|
|
228
|
+
_this.logger.mark('请输入滑块验证返回的ticket');
|
|
229
|
+
process_1.default.stdin.once('data', (e) => {
|
|
230
|
+
this.submitSlider(e.toString().trim());
|
|
231
|
+
});
|
|
232
|
+
disposeArr.push(() => {
|
|
233
|
+
this.off('system.login.slider', sliderHelper);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
disposeArr.push(client.on('message', (event) => {
|
|
237
|
+
this.emit('message.receive', oneBot.uin, event);
|
|
238
|
+
}));
|
|
239
|
+
disposeArr.push(client.on('notice', (event) => {
|
|
240
|
+
this.emit('notice.receive', oneBot.uin, event);
|
|
241
|
+
}));
|
|
242
|
+
disposeArr.push(client.on('request', (event) => {
|
|
243
|
+
this.emit('request.receive', oneBot.uin, event);
|
|
244
|
+
}));
|
|
245
|
+
await client.login(parseInt(oneBot.uin), __classPrivateFieldGet(this, _IcqqAdapter_password, "f"));
|
|
246
|
+
return new Promise((resolve, reject) => {
|
|
247
|
+
client.trap('system.login.error', function errorHandler(e) {
|
|
248
|
+
if (e.message.includes('密码错误')) {
|
|
249
|
+
process_1.default.stdin.once('data', (e) => {
|
|
250
|
+
this.login(e.toString().trim());
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
_this.logger.error(e.message);
|
|
255
|
+
clean();
|
|
256
|
+
}
|
|
257
|
+
this.off('system.login.error', errorHandler);
|
|
258
|
+
});
|
|
259
|
+
const clean = () => {
|
|
260
|
+
clearTimeout(timer);
|
|
261
|
+
while (disposeArr.length) {
|
|
262
|
+
disposeArr.shift()();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
client.trap('system.online', () => {
|
|
266
|
+
resolve(clean);
|
|
267
|
+
});
|
|
268
|
+
const timer = setTimeout(() => {
|
|
269
|
+
clean();
|
|
270
|
+
reject('登录超时');
|
|
271
|
+
}, this.app.config.timeout * 1000);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
async start(uin) {
|
|
275
|
+
const startOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
276
|
+
return uin ? oneBot.uin === uin : true;
|
|
277
|
+
});
|
|
278
|
+
for (const oneBot of startOneBots) {
|
|
279
|
+
__classPrivateFieldGet(this, _IcqqAdapter_disposes, "f").set(oneBot.uin, await this.startOneBot(oneBot));
|
|
280
|
+
}
|
|
281
|
+
await super.start();
|
|
282
|
+
}
|
|
283
|
+
async stop(uin, force) {
|
|
284
|
+
const stopOneBots = [...this.oneBots.values()].filter(oneBot => {
|
|
285
|
+
return uin ? oneBot.uin === uin : true;
|
|
286
|
+
});
|
|
287
|
+
for (const oneBot of stopOneBots) {
|
|
288
|
+
const dispose = __classPrivateFieldGet(this, _IcqqAdapter_disposes, "f").get(oneBot.uin);
|
|
289
|
+
if (dispose) {
|
|
290
|
+
dispose();
|
|
291
|
+
}
|
|
292
|
+
if (force) {
|
|
293
|
+
(0, fs_1.rmSync)(oneBot.internal.dir, { force: true, recursive: true });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
await super.stop();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
_IcqqAdapter_password = new WeakMap(), _IcqqAdapter_disposes = new WeakMap();
|
|
300
|
+
exports.default = IcqqAdapter;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { QQAdapter } from "../../adapters/qq";
|
|
2
|
+
import { AxiosInstance } from "axios";
|
|
3
|
+
import { WebSocket } from "ws";
|
|
4
|
+
import { OneBot } from "../../onebot";
|
|
5
|
+
import { QQBot } from "../../adapters/qq/qqBot";
|
|
6
|
+
export declare class Bot extends QQBot {
|
|
7
|
+
oneBot: OneBot;
|
|
8
|
+
appId: string;
|
|
9
|
+
request: AxiosInstance;
|
|
10
|
+
self_id: string;
|
|
11
|
+
nickname: string;
|
|
12
|
+
status: number;
|
|
13
|
+
ws: WebSocket;
|
|
14
|
+
constructor(oneBot: OneBot, appId: string, config: QQAdapter.Config['protocol']);
|
|
15
|
+
init(): Promise<void>;
|
|
16
|
+
stop(): void;
|
|
17
|
+
}
|
|
18
|
+
export declare namespace Bot {
|
|
19
|
+
interface Config extends QQBot.Config {
|
|
20
|
+
data_dir?: string;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Bot = void 0;
|
|
4
|
+
const qqBot_1 = require("../../adapters/qq/qqBot");
|
|
5
|
+
class Bot extends qqBot_1.QQBot {
|
|
6
|
+
constructor(oneBot, appId, config) {
|
|
7
|
+
super({
|
|
8
|
+
appid: appId,
|
|
9
|
+
...config
|
|
10
|
+
});
|
|
11
|
+
this.oneBot = oneBot;
|
|
12
|
+
this.appId = appId;
|
|
13
|
+
}
|
|
14
|
+
async init() {
|
|
15
|
+
await this.sessionManager.start();
|
|
16
|
+
}
|
|
17
|
+
stop() {
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Bot = Bot;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare enum OpCode {
|
|
2
|
+
DISPATCH = 0,
|
|
3
|
+
HEARTBEAT = 1,
|
|
4
|
+
IDENTIFY = 2,
|
|
5
|
+
RESUME = 6,
|
|
6
|
+
RECONNECT = 7,
|
|
7
|
+
INVALID_SESSION = 9,
|
|
8
|
+
HELLO = 10,
|
|
9
|
+
HEARTBEAT_ACK = 11
|
|
10
|
+
}
|
|
11
|
+
export declare const SessionEvents: {
|
|
12
|
+
CLOSED: string;
|
|
13
|
+
READY: string;
|
|
14
|
+
ERROR: string;
|
|
15
|
+
INVALID_SESSION: string;
|
|
16
|
+
RECONNECT: string;
|
|
17
|
+
DISCONNECT: string;
|
|
18
|
+
EVENT_WS: string;
|
|
19
|
+
RESUMED: string;
|
|
20
|
+
DEAD: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const WebsocketCloseReason: ({
|
|
23
|
+
code: number;
|
|
24
|
+
reason: string;
|
|
25
|
+
resume?: undefined;
|
|
26
|
+
} | {
|
|
27
|
+
code: number;
|
|
28
|
+
reason: string;
|
|
29
|
+
resume: boolean;
|
|
30
|
+
})[];
|
|
31
|
+
export declare enum Intends {
|
|
32
|
+
GUILDS = 1,
|
|
33
|
+
GUILD_MEMBERS = 2,
|
|
34
|
+
GUILD_MESSAGES = 512,
|
|
35
|
+
GUILD_MESSAGE_REACTIONS = 1024,
|
|
36
|
+
DIRECT_MESSAGE = 4096,
|
|
37
|
+
OPEN_FORUMS_EVENTS = 262144,
|
|
38
|
+
AUDIO_OR_LIVE_CHANNEL_MEMBERS = 524288,
|
|
39
|
+
C2C_MESSAGE_CREATE = 33554432,
|
|
40
|
+
GROUP_AT_MESSAGE_CREATE = 33554432,
|
|
41
|
+
INTERACTION = 67108864,
|
|
42
|
+
MESSAGE_AUDIT = 134217728,
|
|
43
|
+
FORUMS_EVENTS = 268435456,
|
|
44
|
+
AUDIO_ACTIONS = 536870912,
|
|
45
|
+
PUBLIC_GUILD_MESSAGES = 1073741824
|
|
46
|
+
}
|
|
47
|
+
export declare enum ChannelType {
|
|
48
|
+
Content = 0,
|
|
49
|
+
Record = 2,
|
|
50
|
+
ChannelGroup = 4,
|
|
51
|
+
Live = 10005,
|
|
52
|
+
App = 10006,
|
|
53
|
+
Forms = 10007
|
|
54
|
+
}
|
|
55
|
+
export declare enum ChannelSubType {
|
|
56
|
+
Chat = 0,
|
|
57
|
+
Announces = 1,
|
|
58
|
+
Strategy = 2,
|
|
59
|
+
Black = 3
|
|
60
|
+
}
|
|
61
|
+
export declare enum PrivateType {
|
|
62
|
+
Public = 0,
|
|
63
|
+
Admin = 1,
|
|
64
|
+
Some = 2
|
|
65
|
+
}
|
|
66
|
+
export declare enum SpeakPermission {
|
|
67
|
+
All = 1,
|
|
68
|
+
Some = 2
|
|
69
|
+
}
|