refactor: Use remote rkey

This commit is contained in:
linyuchen
2024-05-11 13:41:09 +08:00
parent 698649f981
commit f9aa2d3bce
11 changed files with 23 additions and 86 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -7,7 +7,6 @@ import { postLoginStatus } from '@/common/utils/umami';
import { checkVersion } from '@/common/utils/version';
import { log, logDebug, logError, LogLevel, setLogLevel } from '@/common/utils/log';
import { NapCatOnebot11 } from '@/onebot11/main';
import { hookApi } from '@/core/external/hook';
import { InitWebUi } from './webui/index';
import { WebUiDataRuntime } from './webui/src/helper/Data';
program
@@ -18,11 +17,7 @@ InitWebUi();
const cmdOptions = program.opts();
// console.log(process.argv);
for (let k = 0; k < 30; k++) {
new Promise((r, j) => {
hookApi.getRKey();
}).then();
}
checkVersion().then((remoteVersion: string) => {
const localVersion = require('./package.json').version;
const localVersionList = localVersion.split('.');
@@ -70,7 +65,7 @@ napCatCore.getQuickLoginList().then((res) => {
});
WebUiDataRuntime.setQQQuickLogin(async (uin: string) => {
let QuickLogin: Promise<{ result: boolean, message: string }> = new Promise((resolve, reject) => {
const QuickLogin: Promise<{ result: boolean, message: string }> = new Promise((resolve, reject) => {
if (quickLoginQQ) {
log('正在快速登录 ', quickLoginQQ);
napCatCore.quickLogin(quickLoginQQ).then(res => {
@@ -86,7 +81,7 @@ WebUiDataRuntime.setQQQuickLogin(async (uin: string) => {
resolve({ result: false, message: '快速登录失败' });
}
});
let result = await QuickLogin;
const result = await QuickLogin;
return result;
});

View File

@@ -1,14 +0,0 @@
import { OB11User } from '../../types';
import { OB11Constructor } from '../../constructor';
import { buddyCategory, friends } from '@/core/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { buddyCategorType } from '@/core/entities/';
export class GetFriendCategory extends BaseAction<void, Array<buddyCategorType>> {
actionName = ActionName.GetFriendCategory;
protected async _handle(payload: void) {
return buddyCategory.data;
}
}

View File

@@ -0,0 +1,14 @@
import { OB11User } from '../../types';
import { OB11Constructor } from '../../constructor';
import { rawFriends, friends } from '@/core/data';
import BaseAction from '../BaseAction';
import { ActionName } from '../types';
import { BuddyCategoryType } from '@/core/entities/';
export class GetFriendWithCategory extends BaseAction<void, Array<BuddyCategoryType>> {
actionName = ActionName.GetFriendsWithCategory;
protected async _handle(payload: void) {
return rawFriends;
}
}

View File

@@ -52,7 +52,7 @@ import { SetOnlineStatus } from './extends/SetOnlineStatus';
import { GetGroupNotice } from './group/GetGroupNotice';
import { GetGroupEssence } from './group/GetGroupEssence';
import { ForwardFriendSingleMsg, ForwardGroupSingleMsg } from '@/onebot11/action/msg/ForwardSingleMsg';
import { GetFriendCategory } from './extends/GetFriendCategory';
import { GetFriendWithCategory } from './extends/GetFriendWithCategory';
export const actionHandlers = [
new GetFile(),
@@ -95,7 +95,7 @@ export const actionHandlers = [
//
new SetOnlineStatus(),
new GetRobotUinRange(),
new GetFriendCategory(),
new GetFriendWithCategory(),
//以下为go-cqhttp api
new GetGroupNotice(),
new GetGroupEssence(),

View File

@@ -57,7 +57,7 @@ export enum ActionName {
// 以下为扩展napcat扩展
GetRobotUinRange = 'get_robot_uin_range',
SetOnlineStatus = 'set_online_status',
GetFriendCategory = 'get_friend_category',
GetFriendsWithCategory = 'get_friends_with_category',
// 以下为go-cqhttp api
GoCQHTTP_GetEssenceMsg = 'get_essence_msg_list',
GoCQHTTP_SetGroupNotice = '_send_group_notice',

View File

@@ -1,58 +0,0 @@
//远端rkey获取
class ServerRkeyWrapper {
serverUrl: string = "";
GroupRkey: string = "";
PrivateRkey: string = "";
expired_time: number = 0;
async Init(ServerUrl: string) {
this.serverUrl = ServerUrl;
}
async GetGroupRkey(): Promise<string> {
if (await this.IsRkeyExpired()) {
await this.RefreshRkey();
}
return this.GroupRkey;
}
async GetPrivateRkey(): Promise<string> {
if (await this.IsRkeyExpired()) {
await this.RefreshRkey();
}
return this.PrivateRkey;
}
async IsRkeyExpired(): Promise<boolean> {
return new Promise((resolve, reject) => {
let now = new Date().getTime();
if (now > this.expired_time || this.expired_time == 0) {
resolve(true);
} else {
resolve(false);
}
reject("error");
});
}
async RefreshRkey(): Promise<any> {
//刷新rkey
let data = await this.Internal_RefreshRkey();
this.GroupRkey = data.group_rkey;
this.PrivateRkey = data.private_rkey;
this.expired_time = data.expired_time;
}
async Internal_RefreshRkey(): Promise<any> {
return new Promise((resolve, reject) => {
fetch(this.serverUrl)
.then(response => {
if (!response.ok) {
reject(response.statusText); // 请求失败,返回错误信息
}
return response.json(); // 解析 JSON 格式的响应体
})
.then(data => {
resolve(data);
})
.catch(error => {
reject(error);
});
});
}
}
export const serverRkey = new ServerRkeyWrapper();

View File

@@ -57,7 +57,7 @@ export class ReverseWebsocket {
}
public onclose = () => {
logDebug('反向ws断开', this.url);
logError('反向ws断开', this.url);
unregisterWsEventSender(this.websocket!);
if (this.running) {
this.reconnect();

View File

@@ -48,7 +48,7 @@ const baseConfigPlugin: PluginOption[] = [
{ src: './package.json', dest: 'dist' },
{ src: './README.md', dest: 'dist' },
{ src: './logo.png', dest: 'dist/logs' },
...MoeHooModule,
// ...MoeHooModule,
...(startScripts.map((startScript) => {
return { src: startScript, dest: 'dist' };
})),