mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
Merge branch 'config-api' into dev
# Conflicts: # src/onebot11/action/index.ts
This commit is contained in:
commit
b3ea8fbc0c
@ -13,34 +13,29 @@ import {
|
|||||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
||||||
import {
|
import {
|
||||||
friendRequests, getFriend,
|
friendRequests,
|
||||||
|
getFriend,
|
||||||
getGroup,
|
getGroup,
|
||||||
getGroupMember,
|
getGroupMember,
|
||||||
llonebotError, refreshGroupMembers,
|
llonebotError,
|
||||||
|
refreshGroupMembers,
|
||||||
selfInfo
|
selfInfo
|
||||||
} from "../common/data";
|
} from "../common/data";
|
||||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
|
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
|
||||||
import {OB11Constructor} from "../onebot11/constructor";
|
import {OB11Constructor} from "../onebot11/constructor";
|
||||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
import {NTQQApi} from "../ntqqapi/ntcall";
|
||||||
import {
|
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
||||||
ChatType,
|
|
||||||
FriendRequestNotify,
|
|
||||||
GroupMember,
|
|
||||||
GroupNotifies,
|
|
||||||
GroupNotifyTypes,
|
|
||||||
RawMessage
|
|
||||||
} from "../ntqqapi/types";
|
|
||||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||||
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||||
import {OB11GroupRecallNoticeEvent} from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
import {OB11GroupRecallNoticeEvent} from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
||||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||||
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
import {OB11GroupAdminNoticeEvent} from "../onebot11/event/notice/OB11GroupAdminNoticeEvent";
|
import {OB11GroupAdminNoticeEvent} from "../onebot11/event/notice/OB11GroupAdminNoticeEvent";
|
||||||
import {OB11GroupDecreaseEvent} from "../onebot11/event/notice/OB11GroupDecreaseEvent";
|
|
||||||
import {OB11GroupRequestEvent} from "../onebot11/event/request/OB11GroupRequest";
|
import {OB11GroupRequestEvent} from "../onebot11/event/request/OB11GroupRequest";
|
||||||
import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendRequest";
|
import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendRequest";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import {dbUtil} from "../common/db";
|
import {dbUtil} from "../common/db";
|
||||||
|
import {setConfig} from "./setConfig";
|
||||||
|
|
||||||
|
|
||||||
let running = false;
|
let running = false;
|
||||||
@ -90,61 +85,8 @@ function onLoad() {
|
|||||||
const config = getConfigUtil().getConfig()
|
const config = getConfigUtil().getConfig()
|
||||||
return config;
|
return config;
|
||||||
})
|
})
|
||||||
ipcMain.on(CHANNEL_SET_CONFIG, (event, arg: Config) => {
|
ipcMain.on(CHANNEL_SET_CONFIG, (event, config: Config) => {
|
||||||
let oldConfig = getConfigUtil().getConfig();
|
setConfig(config).then();
|
||||||
getConfigUtil().setConfig(arg)
|
|
||||||
if (arg.ob11.httpPort != oldConfig.ob11.httpPort && arg.ob11.enableHttp) {
|
|
||||||
ob11HTTPServer.restart(arg.ob11.httpPort);
|
|
||||||
}
|
|
||||||
// 判断是否启用或关闭HTTP服务
|
|
||||||
if (!arg.ob11.enableHttp) {
|
|
||||||
ob11HTTPServer.stop();
|
|
||||||
} else {
|
|
||||||
ob11HTTPServer.start(arg.ob11.httpPort);
|
|
||||||
}
|
|
||||||
// 正向ws端口变化,重启服务
|
|
||||||
if (arg.ob11.wsPort != oldConfig.ob11.wsPort) {
|
|
||||||
ob11WebsocketServer.restart(arg.ob11.wsPort);
|
|
||||||
}
|
|
||||||
// 判断是否启用或关闭正向ws
|
|
||||||
if (arg.ob11.enableWs != oldConfig.ob11.enableWs) {
|
|
||||||
if (arg.ob11.enableWs) {
|
|
||||||
ob11WebsocketServer.start(arg.ob11.wsPort);
|
|
||||||
} else {
|
|
||||||
ob11WebsocketServer.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 判断是否启用或关闭反向ws
|
|
||||||
if (arg.ob11.enableWsReverse != oldConfig.ob11.enableWsReverse) {
|
|
||||||
if (arg.ob11.enableWsReverse) {
|
|
||||||
ob11ReverseWebsockets.start();
|
|
||||||
} else {
|
|
||||||
ob11ReverseWebsockets.stop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (arg.ob11.enableWsReverse) {
|
|
||||||
// 判断反向ws地址有变化
|
|
||||||
if (arg.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
|
|
||||||
ob11ReverseWebsockets.restart();
|
|
||||||
} else {
|
|
||||||
for (const newHost of arg.ob11.wsHosts) {
|
|
||||||
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
|
|
||||||
ob11ReverseWebsockets.restart();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查ffmpeg
|
|
||||||
if (arg.ffmpeg) {
|
|
||||||
checkFfmpeg(arg.ffmpeg).then(success => {
|
|
||||||
if (success) {
|
|
||||||
llonebotError.ffmpegError = ''
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
ipcMain.on(CHANNEL_LOG, (event, arg) => {
|
||||||
|
63
src/main/setConfig.ts
Normal file
63
src/main/setConfig.ts
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
import {Config} from "../common/types";
|
||||||
|
import {checkFfmpeg, getConfigUtil} from "../common/utils";
|
||||||
|
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||||
|
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||||
|
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||||
|
import {llonebotError} from "../common/data";
|
||||||
|
|
||||||
|
export async function setConfig(config: Config) {
|
||||||
|
let oldConfig = getConfigUtil().getConfig();
|
||||||
|
getConfigUtil().setConfig(config)
|
||||||
|
if (config.ob11.httpPort != oldConfig.ob11.httpPort && config.ob11.enableHttp) {
|
||||||
|
ob11HTTPServer.restart(config.ob11.httpPort);
|
||||||
|
}
|
||||||
|
// 判断是否启用或关闭HTTP服务
|
||||||
|
if (!config.ob11.enableHttp) {
|
||||||
|
ob11HTTPServer.stop();
|
||||||
|
} else {
|
||||||
|
ob11HTTPServer.start(config.ob11.httpPort);
|
||||||
|
}
|
||||||
|
// 正向ws端口变化,重启服务
|
||||||
|
if (config.ob11.wsPort != oldConfig.ob11.wsPort) {
|
||||||
|
ob11WebsocketServer.restart(config.ob11.wsPort);
|
||||||
|
}
|
||||||
|
// 判断是否启用或关闭正向ws
|
||||||
|
if (config.ob11.enableWs != oldConfig.ob11.enableWs) {
|
||||||
|
if (config.ob11.enableWs) {
|
||||||
|
ob11WebsocketServer.start(config.ob11.wsPort);
|
||||||
|
} else {
|
||||||
|
ob11WebsocketServer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 判断是否启用或关闭反向ws
|
||||||
|
if (config.ob11.enableWsReverse != oldConfig.ob11.enableWsReverse) {
|
||||||
|
if (config.ob11.enableWsReverse) {
|
||||||
|
ob11ReverseWebsockets.start();
|
||||||
|
} else {
|
||||||
|
ob11ReverseWebsockets.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (config.ob11.enableWsReverse) {
|
||||||
|
// 判断反向ws地址有变化
|
||||||
|
if (config.ob11.wsHosts.length != oldConfig.ob11.wsHosts.length) {
|
||||||
|
ob11ReverseWebsockets.restart();
|
||||||
|
} else {
|
||||||
|
for (const newHost of config.ob11.wsHosts) {
|
||||||
|
if (!oldConfig.ob11.wsHosts.includes(newHost)) {
|
||||||
|
ob11ReverseWebsockets.restart();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查ffmpeg
|
||||||
|
if (config.ffmpeg) {
|
||||||
|
checkFfmpeg(config.ffmpeg).then(success => {
|
||||||
|
if (success) {
|
||||||
|
llonebotError.ffmpegError = ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -33,9 +33,13 @@ import GetRecord from "./GetRecord";
|
|||||||
import GoCQHTTPMarkMsgAsRead from "./MarkMsgAsRead";
|
import GoCQHTTPMarkMsgAsRead from "./MarkMsgAsRead";
|
||||||
import CleanCache from "./CleanCache";
|
import CleanCache from "./CleanCache";
|
||||||
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
import GoCQHTTPUploadGroupFile from "./go-cqhttp/UploadGroupFile";
|
||||||
|
import {GetConfigAction, SetConfigAction} from "./llonebot/Config";
|
||||||
|
|
||||||
export const actionHandlers = [
|
export const actionHandlers = [
|
||||||
new Debug(),
|
new Debug(),
|
||||||
|
new GetConfigAction(),
|
||||||
|
new SetConfigAction(),
|
||||||
|
// onebot11
|
||||||
new SendLike(),
|
new SendLike(),
|
||||||
new GetMsg(),
|
new GetMsg(),
|
||||||
new GetLoginInfo(),
|
new GetLoginInfo(),
|
||||||
|
20
src/onebot11/action/llonebot/Config.ts
Normal file
20
src/onebot11/action/llonebot/Config.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import BaseAction from "../BaseAction";
|
||||||
|
import {Config} from "../../../common/types";
|
||||||
|
import {getConfigUtil} from "../../../common/utils";
|
||||||
|
import {ActionName} from "../types";
|
||||||
|
import {setConfig} from "../../../main/setConfig";
|
||||||
|
|
||||||
|
|
||||||
|
export class GetConfigAction extends BaseAction<null, Config> {
|
||||||
|
actionName = ActionName.GetConfig
|
||||||
|
protected async _handle(payload: null): Promise<Config> {
|
||||||
|
return getConfigUtil().getConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class SetConfigAction extends BaseAction<Config, void> {
|
||||||
|
actionName = ActionName.SetConfig
|
||||||
|
protected async _handle(payload: Config): Promise<void> {
|
||||||
|
setConfig(payload).then();
|
||||||
|
}
|
||||||
|
}
|
@ -14,6 +14,8 @@ export interface InvalidCheckResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum ActionName {
|
export enum ActionName {
|
||||||
|
GetConfig = "get_config",
|
||||||
|
SetConfig = "set_config",
|
||||||
Debug = "llonebot_debug",
|
Debug = "llonebot_debug",
|
||||||
SendLike = "send_like",
|
SendLike = "send_like",
|
||||||
GetLoginInfo = "get_login_info",
|
GetLoginInfo = "get_login_info",
|
||||||
|
@ -20,8 +20,10 @@ class OB11HTTPServer extends HttpServerBase {
|
|||||||
|
|
||||||
export const ob11HTTPServer = new OB11HTTPServer();
|
export const ob11HTTPServer = new OB11HTTPServer();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
for (const action of actionHandlers) {
|
for (const action of actionHandlers) {
|
||||||
for (const method of ["post", "get"]) {
|
for (const method of ["post", "get"]) {
|
||||||
ob11HTTPServer.registerRouter(method, action.actionName, (res, payload) => action.handle(payload))
|
ob11HTTPServer.registerRouter(method, action.actionName, (res, payload) => action.handle(payload))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, 0)
|
Loading…
x
Reference in New Issue
Block a user