mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2026-02-12 16:00:27 +00:00
refactor: Use remote rkey
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
14
src/onebot11/action/extends/GetFriendWithCategory.ts
Normal file
14
src/onebot11/action/extends/GetFriendWithCategory.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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(),
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user