onebots 0.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/LICENSE +21 -0
- package/README.md +59 -0
- package/lib/bin.d.ts +2 -0
- package/lib/bin.js +5 -0
- package/lib/config.sample.yaml +31 -0
- package/lib/db.d.ts +19 -0
- package/lib/db.js +91 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +21 -0
- package/lib/onebot.d.ts +43 -0
- package/lib/onebot.js +85 -0
- package/lib/server/app.d.ts +52 -0
- package/lib/server/app.js +232 -0
- package/lib/server/router.d.ts +9 -0
- package/lib/server/router.js +32 -0
- package/lib/service/V11/action/common.d.ts +64 -0
- package/lib/service/V11/action/common.js +115 -0
- package/lib/service/V11/action/friend.d.ts +38 -0
- package/lib/service/V11/action/friend.js +44 -0
- package/lib/service/V11/action/group.d.ts +104 -0
- package/lib/service/V11/action/group.js +138 -0
- package/lib/service/V11/action/index.d.ts +9 -0
- package/lib/service/V11/action/index.js +10 -0
- package/lib/service/V11/config.d.ts +10 -0
- package/lib/service/V11/config.js +2 -0
- package/lib/service/V11/index.d.ts +95 -0
- package/lib/service/V11/index.js +481 -0
- package/lib/service/V12/action/common.d.ts +32 -0
- package/lib/service/V12/action/common.js +105 -0
- package/lib/service/V12/action/friend.d.ts +13 -0
- package/lib/service/V12/action/friend.js +15 -0
- package/lib/service/V12/action/group.d.ts +104 -0
- package/lib/service/V12/action/group.js +138 -0
- package/lib/service/V12/action/guild.d.ts +2 -0
- package/lib/service/V12/action/guild.js +6 -0
- package/lib/service/V12/action/index.d.ts +10 -0
- package/lib/service/V12/action/index.js +11 -0
- package/lib/service/V12/config.d.ts +17 -0
- package/lib/service/V12/config.js +2 -0
- package/lib/service/V12/index.d.ts +102 -0
- package/lib/service/V12/index.js +530 -0
- package/lib/types.d.ts +3 -0
- package/lib/types.js +2 -0
- package/lib/utils.d.ts +13 -0
- package/lib/utils.js +139 -0
- package/package.json +58 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
var _a;
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.defineConfig = exports.createApp = exports.App = void 0;
|
|
31
|
+
const koa_1 = __importDefault(require("koa"));
|
|
32
|
+
const os = __importStar(require("os"));
|
|
33
|
+
const fs_1 = require("fs");
|
|
34
|
+
const log4js_1 = require("log4js");
|
|
35
|
+
const path_1 = require("path");
|
|
36
|
+
const http_1 = require("http");
|
|
37
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
38
|
+
const koa_bodyparser_1 = __importDefault(require("koa-bodyparser"));
|
|
39
|
+
const onebot_1 = require("../onebot");
|
|
40
|
+
const mime = require('mime-types');
|
|
41
|
+
const utils_1 = require("../utils");
|
|
42
|
+
const router_1 = require("./router");
|
|
43
|
+
const fs_2 = require("fs");
|
|
44
|
+
const V11_1 = require("../service/V11");
|
|
45
|
+
const V12_1 = require("../service/V12");
|
|
46
|
+
class App extends koa_1.default {
|
|
47
|
+
constructor(config = {}) {
|
|
48
|
+
super(config);
|
|
49
|
+
this.oneBots = [];
|
|
50
|
+
this.config = (0, utils_1.deepMerge)((0, utils_1.deepClone)(App.defaultConfig), config);
|
|
51
|
+
this.logger = (0, log4js_1.getLogger)('[icqq-oneBot]');
|
|
52
|
+
this.logger.level = this.config.log_level;
|
|
53
|
+
this.router = new router_1.Router({ prefix: config.path });
|
|
54
|
+
this.use((0, koa_bodyparser_1.default)())
|
|
55
|
+
.use(this.router.routes())
|
|
56
|
+
.use(this.router.allowedMethods());
|
|
57
|
+
this.httpServer = (0, http_1.createServer)(this.callback());
|
|
58
|
+
this.createOneBots();
|
|
59
|
+
}
|
|
60
|
+
getLogger(uin, version = '') {
|
|
61
|
+
const logger = (0, log4js_1.getLogger)(`[icqq-oneBot${version}:${uin}]`);
|
|
62
|
+
logger.level = this.config.log_level;
|
|
63
|
+
return logger;
|
|
64
|
+
}
|
|
65
|
+
getBots() {
|
|
66
|
+
const result = new Map();
|
|
67
|
+
Object.entries(this.config).forEach(([key, value]) => {
|
|
68
|
+
if (parseInt(key).toString() === key && value && typeof value === 'object') {
|
|
69
|
+
result.set(parseInt(key), value);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
createOneBots() {
|
|
75
|
+
for (const [uin, config] of this.getBots()) {
|
|
76
|
+
this.createOneBot(uin, config);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
addAccount(uin, config) {
|
|
80
|
+
if (typeof uin !== "number")
|
|
81
|
+
uin = Number(uin);
|
|
82
|
+
if (Number.isNaN(uin))
|
|
83
|
+
throw new Error('无效的账号');
|
|
84
|
+
if (this.oneBots.find(oneBot => oneBot.uin === uin))
|
|
85
|
+
throw new Error('账户已存在');
|
|
86
|
+
this.config[uin] = config;
|
|
87
|
+
const oneBot = this.createOneBot(uin, config);
|
|
88
|
+
oneBot.startListen();
|
|
89
|
+
(0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump((0, utils_1.deepClone)(this.config)));
|
|
90
|
+
}
|
|
91
|
+
updateAccount(uin, config) {
|
|
92
|
+
if (typeof uin !== "number")
|
|
93
|
+
uin = Number(uin);
|
|
94
|
+
if (Number.isNaN(uin))
|
|
95
|
+
throw new Error('无效的账号');
|
|
96
|
+
const oneBot = this.oneBots.find(oneBot => oneBot.uin === uin);
|
|
97
|
+
if (!oneBot)
|
|
98
|
+
return this.addAccount(uin, config);
|
|
99
|
+
const newConfig = (0, utils_1.deepMerge)(this.config[uin], config);
|
|
100
|
+
this.removeAccount(uin);
|
|
101
|
+
this.addAccount(uin, newConfig);
|
|
102
|
+
}
|
|
103
|
+
removeAccount(uin) {
|
|
104
|
+
if (typeof uin !== "number")
|
|
105
|
+
uin = Number(uin);
|
|
106
|
+
if (Number.isNaN(uin))
|
|
107
|
+
throw new Error('无效的账号');
|
|
108
|
+
const currentIdx = this.oneBots.findIndex(oneBot => oneBot.uin === uin);
|
|
109
|
+
if (currentIdx < 0)
|
|
110
|
+
throw new Error('账户不存在');
|
|
111
|
+
const oneBot = this.oneBots[currentIdx];
|
|
112
|
+
oneBot.stop();
|
|
113
|
+
delete this.config[uin];
|
|
114
|
+
this.oneBots.splice(currentIdx, 1);
|
|
115
|
+
(0, fs_1.writeFileSync)(App.configPath, js_yaml_1.default.dump(this.config));
|
|
116
|
+
}
|
|
117
|
+
createOneBot(uin, config) {
|
|
118
|
+
const oneBot = new onebot_1.OneBot(this, uin, config);
|
|
119
|
+
this.oneBots.push(oneBot);
|
|
120
|
+
return oneBot;
|
|
121
|
+
}
|
|
122
|
+
start() {
|
|
123
|
+
for (const oneBot of this.oneBots) {
|
|
124
|
+
oneBot.start();
|
|
125
|
+
}
|
|
126
|
+
this.httpServer.listen(this.config.port);
|
|
127
|
+
this.router.get('/list', (ctx) => {
|
|
128
|
+
ctx.body = this.oneBots.map(bot => {
|
|
129
|
+
return {
|
|
130
|
+
uin: bot.uin,
|
|
131
|
+
config: bot.config,
|
|
132
|
+
urls: bot.config.map(c => `/${c.version}/${bot.uin}`)
|
|
133
|
+
};
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
this.router.get('/qrcode', (ctx) => {
|
|
137
|
+
const { uin } = ctx.query;
|
|
138
|
+
const uinUrl = (0, path_1.join)(App.configDir, 'data', uin);
|
|
139
|
+
if (!(0, fs_1.existsSync)(uinUrl)) {
|
|
140
|
+
return ctx.res.writeHead(400).end('未登录');
|
|
141
|
+
}
|
|
142
|
+
const qrcodePath = (0, path_1.join)(App.configDir, 'data', uin, 'qrcode.png');
|
|
143
|
+
let file = null;
|
|
144
|
+
try {
|
|
145
|
+
file = (0, fs_2.readFileSync)(qrcodePath); //读取文件
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
return ctx.res.writeHead(404).end(error.message);
|
|
149
|
+
}
|
|
150
|
+
let mimeType = mime.lookup(qrcodePath); //读取图片文件类型
|
|
151
|
+
ctx.set('content-type', mimeType); //设置返回类型
|
|
152
|
+
ctx.body = file; //返回图片
|
|
153
|
+
});
|
|
154
|
+
this.router.get('/detail', (ctx) => {
|
|
155
|
+
let { uin } = ctx.request.query;
|
|
156
|
+
const oneBot = this.oneBots.find(bot => bot.uin === Number(uin));
|
|
157
|
+
ctx.body = {
|
|
158
|
+
uin,
|
|
159
|
+
config: oneBot.config,
|
|
160
|
+
urls: oneBot.config.map(c => `/${uin}/${c.version}`)
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
this.router.post('/add', (ctx, next) => {
|
|
164
|
+
const { uin, ...config } = ctx.request.body;
|
|
165
|
+
try {
|
|
166
|
+
this.addAccount(uin, config);
|
|
167
|
+
ctx.body = `添加成功`;
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
ctx.body = e.message;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
this.router.get('/edit', (ctx, next) => {
|
|
174
|
+
const { uin, ...config } = ctx.request.body;
|
|
175
|
+
try {
|
|
176
|
+
this.updateAccount(Number(uin), config);
|
|
177
|
+
ctx.body = `修改成功`;
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
ctx.body = e.message;
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
this.router.get('/remove', (ctx, next) => {
|
|
184
|
+
const { uin } = ctx.request.query;
|
|
185
|
+
try {
|
|
186
|
+
this.removeAccount(Number(uin));
|
|
187
|
+
ctx.body = `移除成功`;
|
|
188
|
+
}
|
|
189
|
+
catch (e) {
|
|
190
|
+
console.log(e);
|
|
191
|
+
ctx.body = e.message;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
this.logger.mark(`server listen at http://0.0.0.0:${this.config.port}/${this.config.path ? this.config.path : ''}`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
exports.App = App;
|
|
198
|
+
_a = App;
|
|
199
|
+
App.configDir = (0, path_1.join)(os.homedir(), '.onebots');
|
|
200
|
+
App.configPath = (0, path_1.join)(_a.configDir, 'config.yaml');
|
|
201
|
+
function createApp(config = 'config.yaml') {
|
|
202
|
+
if (typeof config === 'string') {
|
|
203
|
+
if (!(0, fs_1.existsSync)(App.configDir)) {
|
|
204
|
+
(0, fs_1.mkdirSync)(App.configDir);
|
|
205
|
+
}
|
|
206
|
+
App.configPath = (0, path_1.join)(App.configDir, config);
|
|
207
|
+
if (!(0, fs_1.existsSync)(App.configPath)) {
|
|
208
|
+
(0, fs_1.copyFileSync)((0, path_1.resolve)(__dirname, '../config.sample.yaml'), App.configPath);
|
|
209
|
+
console.log('未找到对应配置文件,已自动生成默认配置文件,请修改配置文件后重新启动');
|
|
210
|
+
console.log(`配置文件在: ${App.configPath}`);
|
|
211
|
+
process.exit();
|
|
212
|
+
}
|
|
213
|
+
config = js_yaml_1.default.load((0, fs_2.readFileSync)(App.configPath, 'utf8'));
|
|
214
|
+
}
|
|
215
|
+
return new App(config);
|
|
216
|
+
}
|
|
217
|
+
exports.createApp = createApp;
|
|
218
|
+
function defineConfig(config) {
|
|
219
|
+
return config;
|
|
220
|
+
}
|
|
221
|
+
exports.defineConfig = defineConfig;
|
|
222
|
+
(function (App) {
|
|
223
|
+
App.defaultConfig = {
|
|
224
|
+
port: 6727,
|
|
225
|
+
platform: 5,
|
|
226
|
+
general: {
|
|
227
|
+
V11: V11_1.V11.defaultConfig,
|
|
228
|
+
V12: V12_1.V12.defaultConfig
|
|
229
|
+
},
|
|
230
|
+
log_level: 'info',
|
|
231
|
+
};
|
|
232
|
+
})(App = exports.App || (exports.App = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="koa__router" />
|
|
3
|
+
import KoaRouter from '@koa/router';
|
|
4
|
+
import { WebSocketServer } from "ws";
|
|
5
|
+
import http from "http";
|
|
6
|
+
export declare class Router extends KoaRouter {
|
|
7
|
+
wsStack: WebSocketServer[];
|
|
8
|
+
ws(path: string, server: http.Server): import("ws").Server<import("ws").WebSocket>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Router = void 0;
|
|
7
|
+
const router_1 = __importDefault(require("@koa/router"));
|
|
8
|
+
const ws_1 = require("ws");
|
|
9
|
+
const url_1 = require("url");
|
|
10
|
+
class Router extends router_1.default {
|
|
11
|
+
constructor() {
|
|
12
|
+
super(...arguments);
|
|
13
|
+
this.wsStack = [];
|
|
14
|
+
}
|
|
15
|
+
ws(path, server) {
|
|
16
|
+
const wsServer = new ws_1.WebSocketServer({ noServer: true, path });
|
|
17
|
+
this.wsStack.push(wsServer);
|
|
18
|
+
server.on('upgrade', (request, socket, head) => {
|
|
19
|
+
const { pathname } = (0, url_1.parse)(request.url);
|
|
20
|
+
if (this.wsStack.findIndex(wss => wss.options.path === path) === -1) {
|
|
21
|
+
socket.destroy();
|
|
22
|
+
}
|
|
23
|
+
else if (pathname === path) {
|
|
24
|
+
wsServer.handleUpgrade(request, socket, head, function done(ws) {
|
|
25
|
+
wsServer.emit('connection', ws, request);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return wsServer;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.Router = Router;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { OnlineStatus } from "icqq";
|
|
2
|
+
import { V11 } from "../../../service/V11";
|
|
3
|
+
export declare class CommonAction {
|
|
4
|
+
/**
|
|
5
|
+
* 获取登录信息
|
|
6
|
+
*/
|
|
7
|
+
getLoginInfo(this: V11): {
|
|
8
|
+
user_id: number;
|
|
9
|
+
nickname: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* 撤回消息
|
|
13
|
+
* @param message_id {string} 消息id
|
|
14
|
+
*/
|
|
15
|
+
deleteMsg(this: V11, message_id: string): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* 获取消息
|
|
18
|
+
* @param message_id {string} 消息id
|
|
19
|
+
*/
|
|
20
|
+
getMsg(this: V11, message_id: string): Promise<import("icqq").GroupMessage | import("icqq").PrivateMessage>;
|
|
21
|
+
/**
|
|
22
|
+
* 获取合并消息
|
|
23
|
+
* @param id {string} 合并id
|
|
24
|
+
*/
|
|
25
|
+
getForwardMsg(this: V11, id: string): Promise<import("icqq").ForwardMessage[]>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取 Cookies
|
|
28
|
+
* @param domain {string} 域名
|
|
29
|
+
*/
|
|
30
|
+
getCookies(this: V11, domain: string): any;
|
|
31
|
+
/**
|
|
32
|
+
* 获取 CSRF Token
|
|
33
|
+
*/
|
|
34
|
+
getCsrfToken(this: V11): number;
|
|
35
|
+
/**
|
|
36
|
+
* 获取 QQ 相关接口凭证
|
|
37
|
+
* @param domain
|
|
38
|
+
*/
|
|
39
|
+
getCredentials(this: V11, domain: string): {
|
|
40
|
+
cookies: any;
|
|
41
|
+
csrf_token: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* 获取版本信息
|
|
45
|
+
*/
|
|
46
|
+
getVersion(this: V11): {
|
|
47
|
+
app_name: string;
|
|
48
|
+
app_version: string;
|
|
49
|
+
protocol_version: string;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* 重启OneBot实现
|
|
53
|
+
* @param delay {number} 要延迟的毫秒数
|
|
54
|
+
*/
|
|
55
|
+
setRestart(this: V11, delay: number): boolean;
|
|
56
|
+
getStatus(this: V11): {
|
|
57
|
+
online: OnlineStatus;
|
|
58
|
+
good: boolean;
|
|
59
|
+
};
|
|
60
|
+
login(this: V11, password?: string): Promise<unknown>;
|
|
61
|
+
submitSlider(this: V11, ticket: string): void;
|
|
62
|
+
submitSmsCode(this: V11, code: string): void;
|
|
63
|
+
sendSmsCode(this: V11): void;
|
|
64
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CommonAction = void 0;
|
|
4
|
+
const icqq_1 = require("icqq");
|
|
5
|
+
const onebot_1 = require("../../../onebot");
|
|
6
|
+
class CommonAction {
|
|
7
|
+
/**
|
|
8
|
+
* 获取登录信息
|
|
9
|
+
*/
|
|
10
|
+
getLoginInfo() {
|
|
11
|
+
return {
|
|
12
|
+
user_id: this.client.uin,
|
|
13
|
+
nickname: this.client.nickname
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* 撤回消息
|
|
18
|
+
* @param message_id {string} 消息id
|
|
19
|
+
*/
|
|
20
|
+
deleteMsg(message_id) {
|
|
21
|
+
return this.client.deleteMsg(message_id);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 获取消息
|
|
25
|
+
* @param message_id {string} 消息id
|
|
26
|
+
*/
|
|
27
|
+
getMsg(message_id) {
|
|
28
|
+
return this.client.getMsg(message_id);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 获取合并消息
|
|
32
|
+
* @param id {string} 合并id
|
|
33
|
+
*/
|
|
34
|
+
getForwardMsg(id) {
|
|
35
|
+
return this.client.getForwardMsg(id);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 获取 Cookies
|
|
39
|
+
* @param domain {string} 域名
|
|
40
|
+
*/
|
|
41
|
+
getCookies(domain) {
|
|
42
|
+
return this.client.cookies[domain];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 获取 CSRF Token
|
|
46
|
+
*/
|
|
47
|
+
getCsrfToken() {
|
|
48
|
+
return this.client.getCsrfToken();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 获取 QQ 相关接口凭证
|
|
52
|
+
* @param domain
|
|
53
|
+
*/
|
|
54
|
+
getCredentials(domain) {
|
|
55
|
+
return {
|
|
56
|
+
cookies: this.client.cookies[domain],
|
|
57
|
+
csrf_token: this.client.getCsrfToken()
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 获取版本信息
|
|
62
|
+
*/
|
|
63
|
+
getVersion() {
|
|
64
|
+
return {
|
|
65
|
+
app_name: 'icqq',
|
|
66
|
+
app_version: '2.x',
|
|
67
|
+
protocol_version: 'v11'
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* 重启OneBot实现
|
|
72
|
+
* @param delay {number} 要延迟的毫秒数
|
|
73
|
+
*/
|
|
74
|
+
setRestart(delay) {
|
|
75
|
+
return this.emit('restart', delay);
|
|
76
|
+
}
|
|
77
|
+
getStatus() {
|
|
78
|
+
return {
|
|
79
|
+
online: this.client.status = icqq_1.OnlineStatus.Online,
|
|
80
|
+
good: this.oneBot.status === onebot_1.OneBotStatus.Good
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
login(password) {
|
|
84
|
+
const _this = this;
|
|
85
|
+
return new Promise(async (resolve) => {
|
|
86
|
+
const timer = setTimeout(() => {
|
|
87
|
+
receiveResult('登录超时');
|
|
88
|
+
}, 5000);
|
|
89
|
+
function receiveResult(event) {
|
|
90
|
+
_this.client.off('system.login.qrcode', receiveResult);
|
|
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);
|
|
95
|
+
resolve(event);
|
|
96
|
+
}
|
|
97
|
+
this.client.on('system.login.qrcode', receiveResult);
|
|
98
|
+
this.client.on('system.login.device', receiveResult);
|
|
99
|
+
this.client.on('system.login.slider', receiveResult);
|
|
100
|
+
this.client.on('system.login.error', receiveResult);
|
|
101
|
+
this.client.on('system.online', receiveResult);
|
|
102
|
+
await this.client.login(password).catch(() => resolve('登录失败'));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
submitSlider(ticket) {
|
|
106
|
+
return this.client.submitSlider(ticket);
|
|
107
|
+
}
|
|
108
|
+
submitSmsCode(code) {
|
|
109
|
+
return this.client.submitSmsCode(code);
|
|
110
|
+
}
|
|
111
|
+
sendSmsCode() {
|
|
112
|
+
return this.client.sendSmsCode();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
exports.CommonAction = CommonAction;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { OneBot } from "../../../onebot";
|
|
2
|
+
import { Sendable } from "icqq";
|
|
3
|
+
export declare class FriendAction {
|
|
4
|
+
/**
|
|
5
|
+
* 发送私聊消息
|
|
6
|
+
* @param user_id {number} 用户id
|
|
7
|
+
* @param message {import('icqq').Sendable} 发送的消息
|
|
8
|
+
*/
|
|
9
|
+
sendPrivateMsg(this: OneBot<'V11'>, user_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
|
|
10
|
+
/**
|
|
11
|
+
* 获取好友列表
|
|
12
|
+
*/
|
|
13
|
+
getFriendList(this: OneBot<'V11'>): Promise<import("icqq").FriendInfo[]>;
|
|
14
|
+
/**
|
|
15
|
+
* 处理好友添加请求
|
|
16
|
+
* @param flag {string} 请求flag
|
|
17
|
+
* @param approve {boolean} 是否同意
|
|
18
|
+
* @param remark {string} 添加后的备注
|
|
19
|
+
*/
|
|
20
|
+
setFriendAddRequest(this: OneBot<'V11'>, flag: string, approve?: boolean, remark?: string): Promise<boolean>;
|
|
21
|
+
/**
|
|
22
|
+
* 获取陌生人信息
|
|
23
|
+
* @param user_id {number} 用户id
|
|
24
|
+
*/
|
|
25
|
+
getStrangerInfo(this: OneBot<'V11'>, user_id: number): Promise<{
|
|
26
|
+
user_id: number;
|
|
27
|
+
nickname: string;
|
|
28
|
+
sex: import("icqq").Gender;
|
|
29
|
+
age: number;
|
|
30
|
+
area: string;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* 发送好友赞
|
|
34
|
+
* @param user_id {number} 用户id
|
|
35
|
+
* @param times 点赞次数
|
|
36
|
+
*/
|
|
37
|
+
sendLike(this: OneBot<'V11'>, user_id: number, times?: number): Promise<boolean>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FriendAction = void 0;
|
|
4
|
+
class FriendAction {
|
|
5
|
+
/**
|
|
6
|
+
* 发送私聊消息
|
|
7
|
+
* @param user_id {number} 用户id
|
|
8
|
+
* @param message {import('icqq').Sendable} 发送的消息
|
|
9
|
+
*/
|
|
10
|
+
sendPrivateMsg(user_id, message) {
|
|
11
|
+
return this.client.sendPrivateMsg(user_id, message);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 获取好友列表
|
|
15
|
+
*/
|
|
16
|
+
async getFriendList() {
|
|
17
|
+
return [...(await this.client.getFriendList()).values()];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 处理好友添加请求
|
|
21
|
+
* @param flag {string} 请求flag
|
|
22
|
+
* @param approve {boolean} 是否同意
|
|
23
|
+
* @param remark {string} 添加后的备注
|
|
24
|
+
*/
|
|
25
|
+
async setFriendAddRequest(flag, approve = true, remark = '') {
|
|
26
|
+
return await this.client.setFriendAddRequest(flag, approve, remark);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 获取陌生人信息
|
|
30
|
+
* @param user_id {number} 用户id
|
|
31
|
+
*/
|
|
32
|
+
async getStrangerInfo(user_id) {
|
|
33
|
+
return await this.client.getStrangerInfo(user_id);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 发送好友赞
|
|
37
|
+
* @param user_id {number} 用户id
|
|
38
|
+
* @param times 点赞次数
|
|
39
|
+
*/
|
|
40
|
+
async sendLike(user_id, times) {
|
|
41
|
+
return this.client.sendLike(user_id, times);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.FriendAction = FriendAction;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Sendable } from "icqq";
|
|
2
|
+
import { V11 } from "../../../service/V11";
|
|
3
|
+
export declare class GroupAction {
|
|
4
|
+
/**
|
|
5
|
+
* 发送群聊消息
|
|
6
|
+
* @param group_id {number} 群id
|
|
7
|
+
* @param message {import('icqq').Sendable} 消息
|
|
8
|
+
*/
|
|
9
|
+
sendGroupMsg(this: V11, group_id: number, message: Sendable): Promise<import("icqq").MessageRet>;
|
|
10
|
+
/**
|
|
11
|
+
* 群组踢人
|
|
12
|
+
* @param group_id {number} 群id
|
|
13
|
+
* @param user_id {number} 成员id
|
|
14
|
+
* @param reject_add_request {boolean} 是否禁止此人加群请求
|
|
15
|
+
*/
|
|
16
|
+
setGroupKick(this: V11, group_id: number, user_id: number, reject_add_request?: boolean): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* 群禁言指定人
|
|
19
|
+
* @param group_id {number} 群id
|
|
20
|
+
* @param user_id {number} 成员id
|
|
21
|
+
* @param duration {number} 禁言时长(单位:秒)
|
|
22
|
+
*/
|
|
23
|
+
setGroupBan(this: V11, group_id: number, user_id: number, duration?: number): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 群禁言匿名者
|
|
26
|
+
* @param group_id {number} 群id
|
|
27
|
+
* @param flag {string} 匿名者flag
|
|
28
|
+
* @param duration {number} 禁言时长(单位:秒)
|
|
29
|
+
*/
|
|
30
|
+
setGroupAnonymousBan(this: V11, group_id: number, flag: string, duration?: number): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* 群全体禁言
|
|
33
|
+
* @param group_id {number} 群id
|
|
34
|
+
* @param enable {boolean} 是否禁言
|
|
35
|
+
*/
|
|
36
|
+
setGroupWholeBan(this: V11, group_id: number, enable?: boolean): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* 群匿名聊天
|
|
39
|
+
* @param group_id {number} 群id
|
|
40
|
+
* @param enable {boolean} 是否开启
|
|
41
|
+
*/
|
|
42
|
+
setGroupAnonymous(this: V11, group_id: number, enable?: boolean): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* 设置群管
|
|
45
|
+
* @param group_id {number} 群id
|
|
46
|
+
* @param user_id {number} 成员id
|
|
47
|
+
* @param enable {boolean} true 设为管理,false 取消管理
|
|
48
|
+
*/
|
|
49
|
+
setGroupAdmin(this: V11, group_id: number, user_id: number, enable?: boolean): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* 设置群成员名片(成员备注)
|
|
52
|
+
* @param group_id {number} 群id
|
|
53
|
+
* @param user_id {number} 成员id
|
|
54
|
+
* @param card {string} 名片信息,不传或传空串则为 删除名片
|
|
55
|
+
*/
|
|
56
|
+
setGroupCard(this: V11, group_id: number, user_id: number, card?: string): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* 设置群名
|
|
59
|
+
* @param group_id {number} 群id
|
|
60
|
+
* @param name {string} 新群名
|
|
61
|
+
*/
|
|
62
|
+
setGroupName(this: V11, group_id: number, name: string): Promise<boolean>;
|
|
63
|
+
/**
|
|
64
|
+
* 退出指定群聊
|
|
65
|
+
* @param group_id {number} 群id
|
|
66
|
+
*/
|
|
67
|
+
setGroupLeave(this: V11, group_id: number): Promise<boolean>;
|
|
68
|
+
/**
|
|
69
|
+
* 设置群成员头衔
|
|
70
|
+
* @param group_id {number} 群id
|
|
71
|
+
* @param user_id {number} 成员id
|
|
72
|
+
* @param special_title {string} 头衔
|
|
73
|
+
* @param duration {number} 持有时长 不传则永久
|
|
74
|
+
*/
|
|
75
|
+
setGroupSpecialTitle(this: V11, group_id: number, user_id: number, special_title: string, duration?: number): Promise<boolean>;
|
|
76
|
+
/**
|
|
77
|
+
* 处理加群请求
|
|
78
|
+
* @param flag {string} 加群flag
|
|
79
|
+
* @param approve {boolean} 是否同意(默认:true)
|
|
80
|
+
* @param reason {string} 拒绝理由,approve为false时有效(默认为空)
|
|
81
|
+
* @param block {boolean} 拒绝时是否加入黑名单,(默认:false)
|
|
82
|
+
*/
|
|
83
|
+
setGroupAddRequest(this: V11, flag: string, approve?: boolean, reason?: string, block?: boolean): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* 获取群列表
|
|
86
|
+
*/
|
|
87
|
+
getGroupList(this: V11): Promise<Map<number, import("icqq").GroupInfo>>;
|
|
88
|
+
/**
|
|
89
|
+
* 获取指定群信息
|
|
90
|
+
* @param group_id
|
|
91
|
+
*/
|
|
92
|
+
getGroupInfo(this: V11, group_id: number): Promise<import("icqq").GroupInfo>;
|
|
93
|
+
/**
|
|
94
|
+
* 获取群成员列表
|
|
95
|
+
* @param group_id
|
|
96
|
+
*/
|
|
97
|
+
getGroupMemberList(this: V11, group_id: number): Promise<Map<number, import("icqq").MemberInfo>>;
|
|
98
|
+
/**
|
|
99
|
+
* 获取指定群成员信息
|
|
100
|
+
* @param group_id
|
|
101
|
+
* @param user_id
|
|
102
|
+
*/
|
|
103
|
+
getGroupMemberInfo(this: V11, group_id: number, user_id: number): Promise<import("icqq").MemberInfo>;
|
|
104
|
+
}
|