mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
feat: update
This commit is contained in:
@@ -2,4 +2,6 @@ export const CHANNEL_GET_CONFIG = 'llonebot_get_config'
|
||||
export const CHANNEL_SET_CONFIG = 'llonebot_set_config'
|
||||
export const CHANNEL_LOG = 'llonebot_log'
|
||||
export const CHANNEL_ERROR = 'llonebot_error'
|
||||
export const CHANNEL_UPDATE = 'llonebot_update'
|
||||
export const CHANNEL_REMOTEVERSION = 'llonebot_remoteversion'
|
||||
export const CHANNEL_SELECT_FILE = 'llonebot_select_ffmpeg'
|
||||
|
@@ -1,12 +1,13 @@
|
||||
import * as path from "node:path";
|
||||
import {selfInfo} from "./data";
|
||||
import {ConfigUtil} from "./config";
|
||||
import { selfInfo } from "./data";
|
||||
import { ConfigUtil } from "./config";
|
||||
import util from "util";
|
||||
import {encode, getDuration, isWav} from "silk-wasm";
|
||||
import { encode, getDuration, isWav } from "silk-wasm";
|
||||
import fs from 'fs';
|
||||
import * as crypto from 'crypto';
|
||||
import {v4 as uuidv4} from "uuid";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import ffmpeg from "fluent-ffmpeg"
|
||||
import * as https from "node:https";
|
||||
|
||||
export const DATA_DIR = global.LiteLoader.plugins["LLOneBot"].path.data;
|
||||
|
||||
@@ -35,8 +36,50 @@ function truncateString(obj: any, maxLength = 500) {
|
||||
export function isNumeric(str: string) {
|
||||
return /^\d+$/.test(str);
|
||||
}
|
||||
export async function updateLLOneBot() {
|
||||
let mirrorGithubList = ["https://mirror.ghproxy.com"];
|
||||
return true;
|
||||
}
|
||||
export async function getRemoteVersion() {
|
||||
let mirrorGithubList = ["https://521github.com"];
|
||||
let Version = "";
|
||||
for (let i = 0; i < mirrorGithubList.length; i++) {
|
||||
let mirrorGithub = mirrorGithubList[i];
|
||||
let tVersion = await getRemoteVersionByMirror(mirrorGithub);
|
||||
console.log("tVersion", tVersion);
|
||||
if (tVersion && tVersion != "") {
|
||||
Version = tVersion;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return Version;
|
||||
}
|
||||
export async function getRemoteVersionByMirror(mirrorGithub: string) {
|
||||
let releasePage = "error";
|
||||
let reqPromise = async function (): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
https.get(mirrorGithub + "/LLOneBot/LLOneBot/releases", res => {
|
||||
let list = [];
|
||||
res.on('data', chunk => {
|
||||
list.push(chunk);
|
||||
});
|
||||
res.on('end', () => {
|
||||
resolve(Buffer.concat(list).toString());
|
||||
});
|
||||
}).on('error', err => {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
}
|
||||
try {
|
||||
releasePage = await reqPromise();
|
||||
if (releasePage === "error") return "";
|
||||
return releasePage.match(new RegExp('(?<=(tag/v)).*?(?=("))'))[0];
|
||||
}
|
||||
catch { }
|
||||
return "";
|
||||
|
||||
|
||||
}
|
||||
export function log(...msg: any[]) {
|
||||
if (!getConfigUtil().getConfig().log) {
|
||||
return //console.log(...msg);
|
||||
@@ -265,7 +308,7 @@ export async function encodeSilk(filePath: string) {
|
||||
export async function getVideoInfo(filePath: string) {
|
||||
const size = fs.statSync(filePath).size;
|
||||
return new Promise<{ width: number, height: number, time: number, format: string, size: number, filePath: string }>((resolve, reject) => {
|
||||
ffmpeg(filePath).ffprobe( (err, metadata) => {
|
||||
ffmpeg(filePath).ffprobe((err, metadata) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
@@ -1,17 +1,19 @@
|
||||
// 运行在 Electron 主进程 下的插件入口
|
||||
|
||||
import {BrowserWindow, dialog, ipcMain} from 'electron';
|
||||
import { BrowserWindow, dialog, ipcMain } from 'electron';
|
||||
import * as fs from 'node:fs';
|
||||
import {Config} from "../common/types";
|
||||
import { Config } from "../common/types";
|
||||
import {
|
||||
CHANNEL_ERROR,
|
||||
CHANNEL_GET_CONFIG,
|
||||
CHANNEL_LOG,
|
||||
CHANNEL_REMOTEVERSION,
|
||||
CHANNEL_SELECT_FILE,
|
||||
CHANNEL_SET_CONFIG,
|
||||
CHANNEL_UPDATE,
|
||||
} from "../common/channels";
|
||||
import {ob11WebsocketServer} from "../onebot11/server/ws/WebsocketServer";
|
||||
import {checkFfmpeg, DATA_DIR, getConfigUtil, log} from "../common/utils";
|
||||
import { ob11WebsocketServer } from "../onebot11/server/ws/WebsocketServer";
|
||||
import { checkFfmpeg, DATA_DIR, getConfigUtil, getRemoteVersion, log, updateLLOneBot } from "../common/utils";
|
||||
import {
|
||||
friendRequests,
|
||||
getFriend,
|
||||
@@ -21,21 +23,21 @@ import {
|
||||
refreshGroupMembers,
|
||||
selfInfo
|
||||
} from "../common/data";
|
||||
import {hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook} from "../ntqqapi/hook";
|
||||
import {OB11Constructor} from "../onebot11/constructor";
|
||||
import {NTQQApi} from "../ntqqapi/ntcall";
|
||||
import {ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage} from "../ntqqapi/types";
|
||||
import {ob11HTTPServer} from "../onebot11/server/http";
|
||||
import {OB11FriendRecallNoticeEvent} from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||
import {OB11GroupRecallNoticeEvent} from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
||||
import {postOB11Event} from "../onebot11/server/postOB11Event";
|
||||
import {ob11ReverseWebsockets} from "../onebot11/server/ws/ReverseWebsocket";
|
||||
import {OB11GroupAdminNoticeEvent} from "../onebot11/event/notice/OB11GroupAdminNoticeEvent";
|
||||
import {OB11GroupRequestEvent} from "../onebot11/event/request/OB11GroupRequest";
|
||||
import {OB11FriendRequestEvent} from "../onebot11/event/request/OB11FriendRequest";
|
||||
import { hookNTQQApiCall, hookNTQQApiReceive, ReceiveCmd, registerReceiveHook } from "../ntqqapi/hook";
|
||||
import { OB11Constructor } from "../onebot11/constructor";
|
||||
import { NTQQApi } from "../ntqqapi/ntcall";
|
||||
import { ChatType, FriendRequestNotify, GroupNotifies, GroupNotifyTypes, RawMessage } from "../ntqqapi/types";
|
||||
import { ob11HTTPServer } from "../onebot11/server/http";
|
||||
import { OB11FriendRecallNoticeEvent } from "../onebot11/event/notice/OB11FriendRecallNoticeEvent";
|
||||
import { OB11GroupRecallNoticeEvent } from "../onebot11/event/notice/OB11GroupRecallNoticeEvent";
|
||||
import { postOB11Event } from "../onebot11/server/postOB11Event";
|
||||
import { ob11ReverseWebsockets } from "../onebot11/server/ws/ReverseWebsocket";
|
||||
import { OB11GroupAdminNoticeEvent } from "../onebot11/event/notice/OB11GroupAdminNoticeEvent";
|
||||
import { OB11GroupRequestEvent } from "../onebot11/event/request/OB11GroupRequest";
|
||||
import { OB11FriendRequestEvent } from "../onebot11/event/request/OB11FriendRequest";
|
||||
import * as path from "node:path";
|
||||
import {dbUtil} from "../common/db";
|
||||
import {setConfig} from "./setConfig";
|
||||
import { dbUtil } from "../common/db";
|
||||
import { setConfig } from "./setConfig";
|
||||
|
||||
|
||||
let running = false;
|
||||
@@ -44,7 +46,12 @@ let running = false;
|
||||
// 加载插件时触发
|
||||
function onLoad() {
|
||||
log("llonebot main onLoad");
|
||||
|
||||
ipcMain.handle(CHANNEL_REMOTEVERSION, async (event, arg) => {
|
||||
return getRemoteVersion();
|
||||
});
|
||||
ipcMain.handle(CHANNEL_UPDATE, async (event, arg) => {
|
||||
return updateLLOneBot();
|
||||
});
|
||||
ipcMain.handle(CHANNEL_SELECT_FILE, async (event, arg) => {
|
||||
const selectPath = new Promise<string>((resolve, reject) => {
|
||||
dialog
|
||||
@@ -76,7 +83,7 @@ function onLoad() {
|
||||
}
|
||||
})
|
||||
if (!fs.existsSync(DATA_DIR)) {
|
||||
fs.mkdirSync(DATA_DIR, {recursive: true});
|
||||
fs.mkdirSync(DATA_DIR, { recursive: true });
|
||||
}
|
||||
ipcMain.handle(CHANNEL_ERROR, (event, arg) => {
|
||||
return llonebotError;
|
||||
@@ -94,7 +101,7 @@ function onLoad() {
|
||||
})
|
||||
|
||||
async function postReceiveMsg(msgList: RawMessage[]) {
|
||||
const {debug, reportSelfMessage} = getConfigUtil().getConfig();
|
||||
const { debug, reportSelfMessage } = getConfigUtil().getConfig();
|
||||
for (let message of msgList) {
|
||||
|
||||
// log("收到新消息", message.msgId, message.msgSeq)
|
||||
@@ -167,7 +174,7 @@ function onLoad() {
|
||||
}
|
||||
})
|
||||
registerReceiveHook<{ msgRecord: RawMessage }>(ReceiveCmd.SELF_SEND_MSG, async (payload) => {
|
||||
const {reportSelfMessage} = getConfigUtil().getConfig();
|
||||
const { reportSelfMessage } = getConfigUtil().getConfig();
|
||||
if (!reportSelfMessage) {
|
||||
return
|
||||
}
|
||||
|
@@ -5,8 +5,10 @@ import {
|
||||
CHANNEL_ERROR,
|
||||
CHANNEL_GET_CONFIG,
|
||||
CHANNEL_LOG,
|
||||
CHANNEL_REMOTEVERSION,
|
||||
CHANNEL_SELECT_FILE,
|
||||
CHANNEL_SET_CONFIG,
|
||||
CHANNEL_UPDATE,
|
||||
} from "./common/channels";
|
||||
|
||||
const {contextBridge} = require("electron");
|
||||
@@ -16,6 +18,12 @@ const llonebot = {
|
||||
log: (data: any) => {
|
||||
ipcRenderer.send(CHANNEL_LOG, data);
|
||||
},
|
||||
getRemoteVersion:async (): Promise<string> => {
|
||||
return ipcRenderer.invoke(CHANNEL_REMOTEVERSION);
|
||||
},
|
||||
updateLLOneBot:async (): Promise<boolean> => {
|
||||
return ipcRenderer.invoke(CHANNEL_UPDATE);
|
||||
},
|
||||
setConfig: (config: Config) => {
|
||||
ipcRenderer.send(CHANNEL_SET_CONFIG, config);
|
||||
},
|
||||
|
Reference in New Issue
Block a user