onebots 0.0.6 → 0.0.8
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 +6 -3
- package/lib/onebot.d.ts +2 -1
- package/lib/onebot.js +3 -2
- package/lib/server/app.d.ts +1 -1
- package/lib/server/app.js +2 -2
- package/lib/service/V11/action/common.d.ts +5 -4
- package/lib/service/V11/action/common.js +22 -21
- package/lib/service/V11/action/friend.d.ts +5 -5
- package/lib/service/V11/action/friend.js +1 -1
- package/lib/service/V11/action/group.d.ts +7 -7
- package/lib/service/V11/action/group.js +1 -1
- package/lib/service/V11/index.d.ts +1 -1
- package/lib/service/V11/index.js +4 -4
- package/lib/service/V12/action/common.d.ts +6 -4
- package/lib/service/V12/action/common.js +29 -52
- package/lib/service/V12/action/friend.d.ts +4 -4
- package/lib/service/V12/action/group.d.ts +7 -7
- package/lib/service/V12/action/group.js +1 -1
- package/lib/service/V12/index.d.ts +2 -2
- package/lib/service/V12/index.js +4 -4
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<h1>基于
|
|
2
|
+
<h1>基于oicq的oneBot实现</h1>
|
|
3
3
|
<p>
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/onebots)
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
[](https://nodejs.org)
|
|
9
9
|
[](https://jq.qq.com/?_wv=1027&k=B22VGXov)
|
|
10
10
|
|
|
11
|
+
[](https://star-history.com/#lc-cn/onebots&Date)
|
|
12
|
+
|
|
13
|
+
|
|
11
14
|
[Type Docs](https://lc-cn.github.io/onebots)
|
|
12
15
|
|
|
13
16
|
|
|
@@ -25,7 +28,7 @@ npm install onebots
|
|
|
25
28
|
```
|
|
26
29
|
3. 在项目跟目录添加配置文件config.yaml
|
|
27
30
|
```yaml
|
|
28
|
-
port: 6727 # 项目
|
|
31
|
+
port: 6727 # 项目onebots监听的端口(默认:6727)
|
|
29
32
|
1472258369: # 你的机器人账户
|
|
30
33
|
version: V11 # oneBot版本(V11 或 V12)
|
|
31
34
|
```
|
|
@@ -56,5 +59,5 @@ onebots
|
|
|
56
59
|
| /remove | get | uin | 移除机器人 |
|
|
57
60
|
|
|
58
61
|
# 鸣谢
|
|
59
|
-
1. [
|
|
62
|
+
1. [takayama-lily/oicq](https://github.com/takayama-lily/oicq) 底层服务支持
|
|
60
63
|
2. [takayama-lily/onebot](https://github.com/takayama-lily/node-onebot) oneBots原先版本
|
package/lib/onebot.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import 'oicq2-cq-enable';
|
|
2
3
|
import { EventEmitter } from 'events';
|
|
3
4
|
import { App } from "./server/app";
|
|
4
|
-
import { Client } from "
|
|
5
|
+
import { Client } from "oicq";
|
|
5
6
|
import { V11 } from "./service/V11";
|
|
6
7
|
import { V12 } from "./service/V12";
|
|
7
8
|
import { MayBeArray } from "./types";
|
package/lib/onebot.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BOOLS = exports.OneBotStatus = exports.OneBot = exports.NotFoundError = void 0;
|
|
4
|
+
require("oicq2-cq-enable");
|
|
4
5
|
const events_1 = require("events");
|
|
5
6
|
const app_1 = require("./server/app");
|
|
6
7
|
const utils_1 = require("./utils");
|
|
7
8
|
const path_1 = require("path");
|
|
8
|
-
const
|
|
9
|
+
const oicq_1 = require("oicq");
|
|
9
10
|
const V11_1 = require("./service/V11");
|
|
10
11
|
const V12_1 = require("./service/V12");
|
|
11
12
|
class NotFoundError extends Error {
|
|
@@ -36,7 +37,7 @@ class OneBot extends events_1.EventEmitter {
|
|
|
36
37
|
throw new Error('不支持的oneBot版本:' + c.version);
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
|
-
this.client = new
|
|
40
|
+
this.client = new oicq_1.Client(uin, { platform: this.app.config.platform, data_dir: (0, path_1.join)(app_1.App.configDir, 'data') });
|
|
40
41
|
this.instances = this.config.map(c => {
|
|
41
42
|
switch (c.version) {
|
|
42
43
|
case 'V11':
|
package/lib/server/app.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { Router } from "./router";
|
|
|
8
8
|
import { V11 } from "../service/V11";
|
|
9
9
|
import { V12 } from "../service/V12";
|
|
10
10
|
import { LogLevel, MayBeArray } from "../types";
|
|
11
|
-
import { Platform } from "
|
|
11
|
+
import { Platform } from "oicq";
|
|
12
12
|
export interface KoaOptions {
|
|
13
13
|
env?: string;
|
|
14
14
|
keys?: string[];
|
package/lib/server/app.js
CHANGED
|
@@ -48,7 +48,7 @@ class App extends koa_1.default {
|
|
|
48
48
|
super(config);
|
|
49
49
|
this.oneBots = [];
|
|
50
50
|
this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
|
|
51
|
-
this.logger = (0, log4js_1.getLogger)('[
|
|
51
|
+
this.logger = (0, log4js_1.getLogger)('[oicq-oneBot]');
|
|
52
52
|
this.logger.level = this.config.log_level;
|
|
53
53
|
this.router = new router_1.Router({ prefix: config.path });
|
|
54
54
|
this.use((0, koa_bodyparser_1.default)())
|
|
@@ -58,7 +58,7 @@ class App extends koa_1.default {
|
|
|
58
58
|
this.createOneBots();
|
|
59
59
|
}
|
|
60
60
|
getLogger(uin, version = '') {
|
|
61
|
-
const logger = (0, log4js_1.getLogger)(`[
|
|
61
|
+
const logger = (0, log4js_1.getLogger)(`[oicq-oneBot${version}:${uin}]`);
|
|
62
62
|
logger.level = this.config.log_level;
|
|
63
63
|
return logger;
|
|
64
64
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OnlineStatus } from "
|
|
1
|
+
import { OnlineStatus } from "oicq";
|
|
2
2
|
import { V11 } from "../../../service/V11";
|
|
3
3
|
export declare class CommonAction {
|
|
4
4
|
/**
|
|
@@ -17,12 +17,12 @@ export declare class CommonAction {
|
|
|
17
17
|
* 获取消息
|
|
18
18
|
* @param message_id {string} 消息id
|
|
19
19
|
*/
|
|
20
|
-
getMsg(this: V11, message_id: string): Promise<import("
|
|
20
|
+
getMsg(this: V11, message_id: string): Promise<import("oicq").GroupMessage | import("oicq").PrivateMessage>;
|
|
21
21
|
/**
|
|
22
22
|
* 获取合并消息
|
|
23
23
|
* @param id {string} 合并id
|
|
24
24
|
*/
|
|
25
|
-
getForwardMsg(this: V11, id: string): Promise<import("
|
|
25
|
+
getForwardMsg(this: V11, id: string): Promise<import("oicq").ForwardMessage[]>;
|
|
26
26
|
/**
|
|
27
27
|
* 获取 Cookies
|
|
28
28
|
* @param domain {string} 域名
|
|
@@ -57,8 +57,9 @@ export declare class CommonAction {
|
|
|
57
57
|
online: OnlineStatus;
|
|
58
58
|
good: boolean;
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
callLogin(this: V11, func: string, ...args: any[]): Promise<unknown>;
|
|
61
61
|
submitSlider(this: V11, ticket: string): Promise<any>;
|
|
62
|
+
login(this: V11, password?: string): any;
|
|
62
63
|
submitSmsCode(this: V11, code: string): Promise<any>;
|
|
63
64
|
sendSmsCode(this: V11): void;
|
|
64
65
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonAction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const oicq_1 = require("oicq");
|
|
5
5
|
const onebot_1 = require("../../../onebot");
|
|
6
6
|
class CommonAction {
|
|
7
7
|
/**
|
|
@@ -62,7 +62,7 @@ class CommonAction {
|
|
|
62
62
|
*/
|
|
63
63
|
getVersion() {
|
|
64
64
|
return {
|
|
65
|
-
app_name: '
|
|
65
|
+
app_name: 'oicq',
|
|
66
66
|
app_version: '2.x',
|
|
67
67
|
protocol_version: 'v11'
|
|
68
68
|
};
|
|
@@ -76,39 +76,40 @@ class CommonAction {
|
|
|
76
76
|
}
|
|
77
77
|
getStatus() {
|
|
78
78
|
return {
|
|
79
|
-
online: this.client.status =
|
|
79
|
+
online: this.client.status = oicq_1.OnlineStatus.Online,
|
|
80
80
|
good: this.oneBot.status === onebot_1.OneBotStatus.Good
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
const _this = this;
|
|
83
|
+
callLogin(func, ...args) {
|
|
85
84
|
return new Promise(async (resolve) => {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
_this.client.off('system.login.device', receiveResult);
|
|
92
|
-
_this.client.off('system.login.slider', receiveResult);
|
|
93
|
-
_this.client.off('system.login.error', receiveResult);
|
|
94
|
-
clearTimeout(timer);
|
|
85
|
+
const receiveResult = (event) => {
|
|
86
|
+
this.client.off('system.login.qrcode', receiveResult);
|
|
87
|
+
this.client.off('system.login.device', receiveResult);
|
|
88
|
+
this.client.off('system.login.slider', receiveResult);
|
|
89
|
+
this.client.off('system.login.error', receiveResult);
|
|
95
90
|
resolve(event);
|
|
96
|
-
}
|
|
91
|
+
};
|
|
97
92
|
this.client.on('system.login.qrcode', receiveResult);
|
|
98
93
|
this.client.on('system.login.device', receiveResult);
|
|
99
94
|
this.client.on('system.login.slider', receiveResult);
|
|
100
95
|
this.client.on('system.login.error', receiveResult);
|
|
101
|
-
this.client.
|
|
102
|
-
|
|
96
|
+
this.client.once('system.online', receiveResult);
|
|
97
|
+
try {
|
|
98
|
+
await this.client[func](...args);
|
|
99
|
+
}
|
|
100
|
+
catch (reason) {
|
|
101
|
+
receiveResult(reason);
|
|
102
|
+
}
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
async submitSlider(ticket) {
|
|
106
|
-
this.
|
|
107
|
-
|
|
106
|
+
return this.action.callLogin.apply(this, ['submitSlider', ticket]);
|
|
107
|
+
}
|
|
108
|
+
login(password) {
|
|
109
|
+
return this.action.callLogin.apply(this, ['login', password]);
|
|
108
110
|
}
|
|
109
111
|
async submitSmsCode(code) {
|
|
110
|
-
|
|
111
|
-
return this.action.login.apply(this, []);
|
|
112
|
+
return this.action.callLogin.apply(this, ['submitSmsCode', code]);
|
|
112
113
|
}
|
|
113
114
|
sendSmsCode() {
|
|
114
115
|
return this.client.sendSmsCode();
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { OneBot } from "../../../onebot";
|
|
2
|
-
import { Sendable } from "
|
|
2
|
+
import { Sendable } from "oicq";
|
|
3
3
|
export declare class FriendAction {
|
|
4
4
|
/**
|
|
5
5
|
* 发送私聊消息
|
|
6
6
|
* @param user_id {number} 用户id
|
|
7
|
-
* @param message {import('
|
|
7
|
+
* @param message {import('oicq').Sendable} 发送的消息
|
|
8
8
|
*/
|
|
9
|
-
sendPrivateMsg(this: OneBot<'V11'>, user_id: number, message: Sendable): Promise<import("
|
|
9
|
+
sendPrivateMsg(this: OneBot<'V11'>, user_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
|
|
10
10
|
/**
|
|
11
11
|
* 获取好友列表
|
|
12
12
|
*/
|
|
13
|
-
getFriendList(this: OneBot<'V11'>): Promise<import("
|
|
13
|
+
getFriendList(this: OneBot<'V11'>): Promise<import("oicq").FriendInfo[]>;
|
|
14
14
|
/**
|
|
15
15
|
* 处理好友添加请求
|
|
16
16
|
* @param flag {string} 请求flag
|
|
@@ -25,7 +25,7 @@ export declare class FriendAction {
|
|
|
25
25
|
getStrangerInfo(this: OneBot<'V11'>, user_id: number): Promise<{
|
|
26
26
|
user_id: number;
|
|
27
27
|
nickname: string;
|
|
28
|
-
sex: import("
|
|
28
|
+
sex: import("oicq").Gender;
|
|
29
29
|
age: number;
|
|
30
30
|
area: string;
|
|
31
31
|
}>;
|
|
@@ -5,7 +5,7 @@ class FriendAction {
|
|
|
5
5
|
/**
|
|
6
6
|
* 发送私聊消息
|
|
7
7
|
* @param user_id {number} 用户id
|
|
8
|
-
* @param message {import('
|
|
8
|
+
* @param message {import('oicq').Sendable} 发送的消息
|
|
9
9
|
*/
|
|
10
10
|
sendPrivateMsg(user_id, message) {
|
|
11
11
|
return this.client.sendPrivateMsg(user_id, message);
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Sendable } from "
|
|
1
|
+
import { Sendable } from "oicq";
|
|
2
2
|
import { V11 } from "../../../service/V11";
|
|
3
3
|
export declare class GroupAction {
|
|
4
4
|
/**
|
|
5
5
|
* 发送群聊消息
|
|
6
6
|
* @param group_id {number} 群id
|
|
7
|
-
* @param message {import('
|
|
7
|
+
* @param message {import('oicq').Sendable} 消息
|
|
8
8
|
*/
|
|
9
|
-
sendGroupMsg(this: V11, group_id: number, message: Sendable): Promise<import("
|
|
9
|
+
sendGroupMsg(this: V11, group_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
|
|
10
10
|
/**
|
|
11
11
|
* 群组踢人
|
|
12
12
|
* @param group_id {number} 群id
|
|
@@ -84,21 +84,21 @@ export declare class GroupAction {
|
|
|
84
84
|
/**
|
|
85
85
|
* 获取群列表
|
|
86
86
|
*/
|
|
87
|
-
getGroupList(this: V11): Promise<Map<number, import("
|
|
87
|
+
getGroupList(this: V11): Promise<Map<number, import("oicq").GroupInfo>>;
|
|
88
88
|
/**
|
|
89
89
|
* 获取指定群信息
|
|
90
90
|
* @param group_id
|
|
91
91
|
*/
|
|
92
|
-
getGroupInfo(this: V11, group_id: number): Promise<import("
|
|
92
|
+
getGroupInfo(this: V11, group_id: number): Promise<import("oicq").GroupInfo>;
|
|
93
93
|
/**
|
|
94
94
|
* 获取群成员列表
|
|
95
95
|
* @param group_id
|
|
96
96
|
*/
|
|
97
|
-
getGroupMemberList(this: V11, group_id: number): Promise<Map<number, import("
|
|
97
|
+
getGroupMemberList(this: V11, group_id: number): Promise<Map<number, import("oicq").MemberInfo>>;
|
|
98
98
|
/**
|
|
99
99
|
* 获取指定群成员信息
|
|
100
100
|
* @param group_id
|
|
101
101
|
* @param user_id
|
|
102
102
|
*/
|
|
103
|
-
getGroupMemberInfo(this: V11, group_id: number, user_id: number): Promise<import("
|
|
103
|
+
getGroupMemberInfo(this: V11, group_id: number, user_id: number): Promise<import("oicq").MemberInfo>;
|
|
104
104
|
}
|
package/lib/service/V11/index.js
CHANGED
|
@@ -8,7 +8,7 @@ const action_1 = require("./action");
|
|
|
8
8
|
const ws_1 = require("ws");
|
|
9
9
|
const url_1 = require("url");
|
|
10
10
|
const utils_1 = require("../../utils");
|
|
11
|
-
const
|
|
11
|
+
const oicq2_cq_enable_1 = require("oicq2-cq-enable");
|
|
12
12
|
const onebot_1 = require("../../onebot");
|
|
13
13
|
const http_1 = __importDefault(require("http"));
|
|
14
14
|
const https_1 = __importDefault(require("https"));
|
|
@@ -170,7 +170,7 @@ class V11 extends events_1.EventEmitter {
|
|
|
170
170
|
if (data.post_type === 'system') {
|
|
171
171
|
}
|
|
172
172
|
if (data.message && data.post_type === 'message') {
|
|
173
|
-
data.message = this.config.post_message_format === 'array' ? (0,
|
|
173
|
+
data.message = this.config.post_message_format === 'array' ? (0, oicq2_cq_enable_1.toSegment)(data.message) : (0, oicq2_cq_enable_1.toCqcode)(data);
|
|
174
174
|
}
|
|
175
175
|
this.emit('dispatch', JSON.stringify(data));
|
|
176
176
|
}
|
|
@@ -372,10 +372,10 @@ class V11 extends events_1.EventEmitter {
|
|
|
372
372
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
373
373
|
if (k === 'message') {
|
|
374
374
|
if (typeof params[k] === 'string') {
|
|
375
|
-
params[k] = (0,
|
|
375
|
+
params[k] = (0, oicq2_cq_enable_1.fromCqcode)(params[k]);
|
|
376
376
|
}
|
|
377
377
|
else {
|
|
378
|
-
params[k] = (0,
|
|
378
|
+
params[k] = (0, oicq2_cq_enable_1.fromSegment)(params[k]);
|
|
379
379
|
}
|
|
380
380
|
}
|
|
381
381
|
args.push(params[k]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { V12 } from '../../../service/V12';
|
|
2
|
-
import { OnlineStatus } from "
|
|
2
|
+
import { OnlineStatus } from "oicq";
|
|
3
3
|
import { Action } from "./";
|
|
4
|
+
import { V11 } from "../../../service/V11";
|
|
4
5
|
export declare class CommonAction {
|
|
5
6
|
sendMsg(): void;
|
|
6
7
|
/**
|
|
@@ -23,9 +24,10 @@ export declare class CommonAction {
|
|
|
23
24
|
version: string;
|
|
24
25
|
onebot_version: string;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
callLogin(this: V11, func: string, ...args: any[]): Promise<unknown>;
|
|
28
|
+
submitSlider(this: V11, ticket: string): Promise<any>;
|
|
29
|
+
login(this: V11, password?: string): any;
|
|
30
|
+
submitSmsCode(this: V11, code: string): Promise<any>;
|
|
28
31
|
sendSmsCode(this: V12): void;
|
|
29
|
-
login(this: V12, password?: string): Promise<unknown>;
|
|
30
32
|
getSupportedActions(this: V12): string[];
|
|
31
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonAction = void 0;
|
|
4
|
-
const
|
|
4
|
+
const oicq_1 = require("oicq");
|
|
5
5
|
const onebot_1 = require("../../../onebot");
|
|
6
6
|
const utils_1 = require("../../../utils");
|
|
7
7
|
class CommonAction {
|
|
@@ -21,7 +21,7 @@ class CommonAction {
|
|
|
21
21
|
}
|
|
22
22
|
getStatus() {
|
|
23
23
|
return {
|
|
24
|
-
online: this.client.status =
|
|
24
|
+
online: this.client.status = oicq_1.OnlineStatus.Online,
|
|
25
25
|
good: this.oneBot.status === onebot_1.OneBotStatus.Good
|
|
26
26
|
};
|
|
27
27
|
}
|
|
@@ -41,63 +41,40 @@ class CommonAction {
|
|
|
41
41
|
onebot_version: '12'
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
+
callLogin(func, ...args) {
|
|
45
|
+
return new Promise(async (resolve) => {
|
|
46
|
+
const receiveResult = (event) => {
|
|
47
|
+
this.client.off('system.login.qrcode', receiveResult);
|
|
48
|
+
this.client.off('system.login.device', receiveResult);
|
|
49
|
+
this.client.off('system.login.slider', receiveResult);
|
|
50
|
+
this.client.off('system.login.error', receiveResult);
|
|
51
|
+
resolve(event);
|
|
52
|
+
};
|
|
53
|
+
this.client.on('system.login.qrcode', receiveResult);
|
|
54
|
+
this.client.on('system.login.device', receiveResult);
|
|
55
|
+
this.client.on('system.login.slider', receiveResult);
|
|
56
|
+
this.client.on('system.login.error', receiveResult);
|
|
57
|
+
this.client.once('system.online', receiveResult);
|
|
58
|
+
try {
|
|
59
|
+
await this.client[func](...args);
|
|
60
|
+
}
|
|
61
|
+
catch (reason) {
|
|
62
|
+
receiveResult(reason);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
44
66
|
async submitSlider(ticket) {
|
|
45
|
-
|
|
46
|
-
|
|
67
|
+
return this.action.callLogin.apply(this, ['submitSlider', ticket]);
|
|
68
|
+
}
|
|
69
|
+
login(password) {
|
|
70
|
+
return this.action.callLogin.apply(this, ['login', password]);
|
|
47
71
|
}
|
|
48
72
|
async submitSmsCode(code) {
|
|
49
|
-
|
|
50
|
-
return this.action.login.apply(this, []);
|
|
73
|
+
return this.action.callLogin.apply(this, ['submitSmsCode', code]);
|
|
51
74
|
}
|
|
52
75
|
sendSmsCode() {
|
|
53
76
|
return this.client.sendSmsCode();
|
|
54
77
|
}
|
|
55
|
-
login(password) {
|
|
56
|
-
const _this = this;
|
|
57
|
-
return new Promise(async (resolve) => {
|
|
58
|
-
const timer = setTimeout(() => {
|
|
59
|
-
resolve('登录超时');
|
|
60
|
-
}, 5000);
|
|
61
|
-
function receiveQrcode(event) {
|
|
62
|
-
_this.client.off('system.login.device', receiveDevice);
|
|
63
|
-
_this.client.off('system.login.slider', receiveSlider);
|
|
64
|
-
_this.client.off('system.online', closeListen);
|
|
65
|
-
clearTimeout(timer);
|
|
66
|
-
resolve(event);
|
|
67
|
-
}
|
|
68
|
-
function receiveDevice(event) {
|
|
69
|
-
_this.client.off('system.login.qrcode', receiveQrcode);
|
|
70
|
-
_this.client.off('system.login.slider', receiveSlider);
|
|
71
|
-
_this.client.off('system.online', closeListen);
|
|
72
|
-
clearTimeout(timer);
|
|
73
|
-
resolve(event);
|
|
74
|
-
}
|
|
75
|
-
function receiveError(event) {
|
|
76
|
-
clearTimeout(timer);
|
|
77
|
-
resolve(event);
|
|
78
|
-
}
|
|
79
|
-
function receiveSlider(event) {
|
|
80
|
-
_this.client.off('system.login.qrcode', receiveQrcode);
|
|
81
|
-
_this.client.off('system.login.device', receiveDevice);
|
|
82
|
-
_this.client.off('system.online', closeListen);
|
|
83
|
-
clearTimeout(timer);
|
|
84
|
-
resolve(event);
|
|
85
|
-
}
|
|
86
|
-
function closeListen() {
|
|
87
|
-
_this.client.off('system.login.slider', receiveSlider);
|
|
88
|
-
_this.client.off('system.login.qrcode', receiveQrcode);
|
|
89
|
-
_this.client.off('system.login.device', receiveDevice);
|
|
90
|
-
clearTimeout(timer);
|
|
91
|
-
resolve('登录成功');
|
|
92
|
-
}
|
|
93
|
-
this.client.once('system.login.qrcode', receiveQrcode);
|
|
94
|
-
this.client.once('system.login.device', receiveDevice);
|
|
95
|
-
this.client.once('system.login.slider', receiveSlider);
|
|
96
|
-
this.client.once('system.login.error', receiveError);
|
|
97
|
-
this.client.once('system.online', closeListen);
|
|
98
|
-
await this.client.login(password).catch(() => resolve('登录失败'));
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
78
|
getSupportedActions() {
|
|
102
79
|
return [...new Set((0, utils_1.getProperties)(this.action))].filter(key => {
|
|
103
80
|
return key !== 'constructor';
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { V12 } from "../index";
|
|
2
|
-
import { Sendable } from "
|
|
2
|
+
import { Sendable } from "oicq";
|
|
3
3
|
export declare class FriendAction {
|
|
4
4
|
getUserInfo(this: V12, user_id: number): Promise<{
|
|
5
5
|
user_id: number;
|
|
6
6
|
nickname: string;
|
|
7
|
-
sex: import("
|
|
7
|
+
sex: import("oicq").Gender;
|
|
8
8
|
age: number;
|
|
9
9
|
area: string;
|
|
10
10
|
}>;
|
|
11
|
-
getFriendList(this: V12): Map<number, import("
|
|
12
|
-
sendPrivateMsg(this: V12, user_id: number, message: Sendable): Promise<import("
|
|
11
|
+
getFriendList(this: V12): Map<number, import("oicq").FriendInfo>;
|
|
12
|
+
sendPrivateMsg(this: V12, user_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
|
|
13
13
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { V12 } from "../index";
|
|
2
|
-
import { Sendable } from "
|
|
2
|
+
import { Sendable } from "oicq";
|
|
3
3
|
export declare class GroupAction {
|
|
4
4
|
/**
|
|
5
5
|
* 发送群聊消息
|
|
6
6
|
* @param group_id {number} 群id
|
|
7
|
-
* @param message {import('
|
|
7
|
+
* @param message {import('oicq').Sendable} 消息
|
|
8
8
|
*/
|
|
9
|
-
sendGroupMsg(this: V12, group_id: number, message: Sendable): Promise<import("
|
|
9
|
+
sendGroupMsg(this: V12, group_id: number, message: Sendable): Promise<import("oicq").MessageRet>;
|
|
10
10
|
/**
|
|
11
11
|
* 群组踢人
|
|
12
12
|
* @param group_id {number} 群id
|
|
@@ -84,21 +84,21 @@ export declare class GroupAction {
|
|
|
84
84
|
/**
|
|
85
85
|
* 获取群列表
|
|
86
86
|
*/
|
|
87
|
-
getGroupList(this: V12): Promise<Map<number, import("
|
|
87
|
+
getGroupList(this: V12): Promise<Map<number, import("oicq").GroupInfo>>;
|
|
88
88
|
/**
|
|
89
89
|
* 获取指定群信息
|
|
90
90
|
* @param group_id
|
|
91
91
|
*/
|
|
92
|
-
getGroupInfo(this: V12, group_id: number): Promise<import("
|
|
92
|
+
getGroupInfo(this: V12, group_id: number): Promise<import("oicq").GroupInfo>;
|
|
93
93
|
/**
|
|
94
94
|
* 获取群成员列表
|
|
95
95
|
* @param group_id
|
|
96
96
|
*/
|
|
97
|
-
getGroupMemberList(this: V12, group_id: number): Promise<Map<number, import("
|
|
97
|
+
getGroupMemberList(this: V12, group_id: number): Promise<Map<number, import("oicq").MemberInfo>>;
|
|
98
98
|
/**
|
|
99
99
|
* 获取指定群成员信息
|
|
100
100
|
* @param group_id
|
|
101
101
|
* @param user_id
|
|
102
102
|
*/
|
|
103
|
-
getGroupMemberInfo(this: V12, group_id: number, user_id: number): Promise<import("
|
|
103
|
+
getGroupMemberInfo(this: V12, group_id: number, user_id: number): Promise<import("oicq").MemberInfo>;
|
|
104
104
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
import { Client } from "
|
|
3
|
+
import { Client } from "oicq";
|
|
4
4
|
import { Config } from './config';
|
|
5
5
|
import { OneBot } from "../../onebot";
|
|
6
6
|
import { Action } from "./action";
|
|
@@ -77,7 +77,7 @@ export declare namespace V12 {
|
|
|
77
77
|
const defaultConfig: Config;
|
|
78
78
|
type Payload<T extends any> = {
|
|
79
79
|
id: string;
|
|
80
|
-
impl: '
|
|
80
|
+
impl: 'oicq_onebot';
|
|
81
81
|
platform: 'qq';
|
|
82
82
|
self_id: `${number}`;
|
|
83
83
|
time: number;
|
package/lib/service/V12/index.js
CHANGED
|
@@ -12,7 +12,7 @@ const url_1 = require("url");
|
|
|
12
12
|
const http_1 = __importDefault(require("http"));
|
|
13
13
|
const https_1 = __importDefault(require("https"));
|
|
14
14
|
const ws_1 = require("ws");
|
|
15
|
-
const
|
|
15
|
+
const oicq2_cq_enable_1 = require("oicq2-cq-enable");
|
|
16
16
|
const utils_1 = require("../../utils");
|
|
17
17
|
const db_1 = require("../../db");
|
|
18
18
|
const app_1 = require("../../server/app");
|
|
@@ -231,7 +231,7 @@ class V12 extends events_1.EventEmitter {
|
|
|
231
231
|
}
|
|
232
232
|
const payload = {
|
|
233
233
|
id: (0, utils_1.uuid)(),
|
|
234
|
-
impl: '
|
|
234
|
+
impl: 'oicq_onebot',
|
|
235
235
|
platform: 'qq',
|
|
236
236
|
self_id: `${this.client.uin}`,
|
|
237
237
|
type: data.post_type || 'meta',
|
|
@@ -287,10 +287,10 @@ class V12 extends events_1.EventEmitter {
|
|
|
287
287
|
params[k] = (0, utils_1.toBool)(params[k]);
|
|
288
288
|
if (k === 'message') {
|
|
289
289
|
if (typeof params[k] === 'string') {
|
|
290
|
-
params[k] = (0,
|
|
290
|
+
params[k] = (0, oicq2_cq_enable_1.fromCqcode)(params[k]);
|
|
291
291
|
}
|
|
292
292
|
else {
|
|
293
|
-
params[k] = (0,
|
|
293
|
+
params[k] = (0, oicq2_cq_enable_1.fromSegment)(params[k]);
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
args.push(params[k]);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "onebots",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "基于
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "基于oicq的多例oneBot实现",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"onebots": "./lib/bin.js"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
21
21
|
"onebot",
|
|
22
|
-
"
|
|
22
|
+
"oicq",
|
|
23
23
|
"cq-http"
|
|
24
24
|
],
|
|
25
25
|
"author": "凉菜",
|
|
@@ -47,12 +47,12 @@
|
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"@koa/router": "^10.1.1",
|
|
50
|
-
"icqq": "^0.0.1",
|
|
51
|
-
"icqq-cq-enable": "^1.0.0",
|
|
52
50
|
"js-yaml": "^4.1.0",
|
|
53
51
|
"koa": "^2.13.4",
|
|
54
52
|
"koa-bodyparser": "^4.3.0",
|
|
55
53
|
"log4js": "^6.5.2",
|
|
54
|
+
"oicq": "^2.3.1",
|
|
55
|
+
"oicq2-cq-enable": "^1.0.6",
|
|
56
56
|
"ws": "^8.8.0"
|
|
57
57
|
}
|
|
58
58
|
}
|