-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.ts
28 lines (25 loc) · 1.13 KB
/
bot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { apiVersion, OpenAPI, v1Setup } from '@src/openapi/v1/openapi';
import { versionMapping } from '@src/openapi/openapi';
import { APIVersion, Config, ConfigLogger } from './types/openapi';
import { GetWsParam } from '@src/types';
import WebsocketClient from './client/client';
import log from 'loglevel';
log.setLevel('info');
log.setLevel('trace');
// 注册v1接口
v1Setup();
let defaultImpl = versionMapping[apiVersion] as typeof OpenAPI;
// SelectOpenAPIVersion 指定使用哪个版本的 api 实现,如果不指定,sdk将默认使用第一个 setup 的 api 实现
export function selectOpenAPIVersion(version: APIVersion) {
if (!versionMapping[version]) return false;
defaultImpl = versionMapping[version];
}
// 如果需要使用其他版本的实现,需要在调用这个方法之前调用 SelectOpenAPIVersion 方法
export function createOpenAPI(config: Config) {
return defaultImpl.newClient(config);
}
// ws连接新建
export function createWebsocket(config: GetWsParam & Partial<ConfigLogger>) {
if (!config.logger) config.logger = log;
return new WebsocketClient(config as GetWsParam & ConfigLogger);
}