mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2024-11-21 09:36:35 +00:00
style:lint
This commit is contained in:
parent
a201461eff
commit
7c20ca9b64
@ -4,6 +4,7 @@ import crypto, { randomUUID } from 'crypto';
|
|||||||
import util from 'util';
|
import util from 'util';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import * as fileType from 'file-type';
|
import * as fileType from 'file-type';
|
||||||
|
import { solveAsyncProblem, solveProblem } from './helper';
|
||||||
|
|
||||||
export function isGIF(path: string) {
|
export function isGIF(path: string) {
|
||||||
const buffer = Buffer.alloc(4);
|
const buffer = Buffer.alloc(4);
|
||||||
@ -185,12 +186,11 @@ export enum FileUriType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function checkUriType(Uri: string) {
|
export async function checkUriType(Uri: string) {
|
||||||
//先判断是否是本地文件
|
|
||||||
try {
|
const LocalFileRet = await solveProblem((Uri) => { if (fs.existsSync(Uri)) return { Uri: Uri, Type: FileUriType.Local }; });
|
||||||
if (fs.existsSync(Uri)) return { Uri: Uri, Type: FileUriType.Local };
|
if (LocalFileRet) return LocalFileRet;
|
||||||
} catch (error) {
|
|
||||||
}
|
const OtherFileRet = await solveProblem((Uri) => {
|
||||||
try {
|
|
||||||
//再判断是否是Http
|
//再判断是否是Http
|
||||||
if (Uri.startsWith('http://') || Uri.startsWith('https://')) {
|
if (Uri.startsWith('http://') || Uri.startsWith('https://')) {
|
||||||
return { Uri: Uri, Type: FileUriType.Remote };
|
return { Uri: Uri, Type: FileUriType.Remote };
|
||||||
@ -200,10 +200,9 @@ export async function checkUriType(Uri: string) {
|
|||||||
return { Uri: Uri, Type: FileUriType.Base64 };
|
return { Uri: Uri, Type: FileUriType.Base64 };
|
||||||
}
|
}
|
||||||
if (Uri.startsWith('file://')) {
|
if (Uri.startsWith('file://')) {
|
||||||
let pathname: string;
|
|
||||||
let filePath: string;
|
let filePath: string;
|
||||||
// await fs.copyFile(url.pathname, filePath);
|
// await fs.copyFile(url.pathname, filePath);
|
||||||
pathname = decodeURIComponent(new URL(Uri).pathname);
|
const pathname = decodeURIComponent(new URL(Uri).pathname);
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
filePath = pathname.slice(1);
|
filePath = pathname.slice(1);
|
||||||
} else {
|
} else {
|
||||||
@ -211,8 +210,9 @@ export async function checkUriType(Uri: string) {
|
|||||||
}
|
}
|
||||||
return { Uri: filePath, Type: FileUriType.Local };
|
return { Uri: filePath, Type: FileUriType.Local };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
});
|
||||||
}
|
if (OtherFileRet) return OtherFileRet;
|
||||||
|
|
||||||
return { Uri: Uri, Type: FileUriType.Unknown };
|
return { Uri: Uri, Type: FileUriType.Unknown };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,7 +232,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und
|
|||||||
//接下来都要有文件名
|
//接下来都要有文件名
|
||||||
if (!filename) filename = randomUUID();
|
if (!filename) filename = randomUUID();
|
||||||
//解析Http和Https协议
|
//解析Http和Https协议
|
||||||
|
|
||||||
if (UriType == FileUriType.Remote) {
|
if (UriType == FileUriType.Remote) {
|
||||||
const pathInfo = path.parse(decodeURIComponent(new URL(HandledUri).pathname));
|
const pathInfo = path.parse(decodeURIComponent(new URL(HandledUri).pathname));
|
||||||
if (pathInfo.name) {
|
if (pathInfo.name) {
|
||||||
|
@ -3,8 +3,28 @@ import fs from 'fs';
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { QQLevel } from '@/core';
|
import { QQLevel } from '@/core';
|
||||||
|
|
||||||
//下面这个类是用于将uid+msgid合并的类
|
export async function solveProblem<T extends (...arg: any[]) => any>(func: T): Promise<ReturnType<T> | undefined> {
|
||||||
|
return new Promise<ReturnType<T> | undefined>(async (resolve) => {
|
||||||
|
try {
|
||||||
|
const result = func();
|
||||||
|
resolve(result);
|
||||||
|
} catch (e) {
|
||||||
|
resolve(undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function solveAsyncProblem<T extends (...arg: any[]) => Promise<any>>(func: T): Promise<Awaited<ReturnType<T>> | undefined> {
|
||||||
|
return new Promise<Awaited<ReturnType<T>> | undefined>(async (resolve) => {
|
||||||
|
try {
|
||||||
|
const result = await func();
|
||||||
|
resolve(result);
|
||||||
|
} catch (e) {
|
||||||
|
resolve(undefined);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//下面这个类是用于将uid+msgid合并的类
|
||||||
export class UUIDConverter {
|
export class UUIDConverter {
|
||||||
static encode(highStr: string, lowStr: string): string {
|
static encode(highStr: string, lowStr: string): string {
|
||||||
const high = BigInt(highStr);
|
const high = BigInt(highStr);
|
||||||
|
@ -74,9 +74,14 @@ export class NTQQFriendApi {
|
|||||||
return this.context.session.getBuddyService().clearBuddyReqUnreadCnt();
|
return this.context.session.getBuddyService().clearBuddyReqUnreadCnt();
|
||||||
}
|
}
|
||||||
async getBuddyReq() {
|
async getBuddyReq() {
|
||||||
const [, ret] = await this.core.eventWrapper.CallNormalEventV2
|
const [, ret] = await this.core.eventWrapper.CallNormalEventV2<
|
||||||
<NodeIKernelBuddyService['getBuddyReq'], NodeIKernelBuddyListener['onBuddyReqChange']>
|
NodeIKernelBuddyService['getBuddyReq'],
|
||||||
('NodeIKernelBuddyService/getBuddyReq', 'NodeIKernelBuddyListener/onBuddyReqChange', 1, 5000);
|
NodeIKernelBuddyListener['onBuddyReqChange']
|
||||||
|
>(
|
||||||
|
'NodeIKernelBuddyService/getBuddyReq',
|
||||||
|
'NodeIKernelBuddyListener/onBuddyReqChange',
|
||||||
|
1,
|
||||||
|
5000);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ import { NodeIKernelProfileListener } from '@/core/listeners';
|
|||||||
import { RequestUtil } from '@/common/utils/request';
|
import { RequestUtil } from '@/common/utils/request';
|
||||||
import { NodeIKernelProfileService, ProfileBizType, UserDetailSource } from '@/core/services';
|
import { NodeIKernelProfileService, ProfileBizType, UserDetailSource } from '@/core/services';
|
||||||
import { InstanceContext, NapCatCore } from '..';
|
import { InstanceContext, NapCatCore } from '..';
|
||||||
|
import { solveAsyncProblem } from '@/common/utils/helper';
|
||||||
|
|
||||||
export class NTQQUserApi {
|
export class NTQQUserApi {
|
||||||
context: InstanceContext;
|
context: InstanceContext;
|
||||||
@ -128,12 +129,9 @@ export class NTQQUserApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getUserDetailInfo(uid: string): Promise<User> {
|
async getUserDetailInfo(uid: string): Promise<User> {
|
||||||
try {
|
const retUser = await solveAsyncProblem(async (uid) => this.fetchUserDetailInfo(uid, UserDetailSource.KDB));
|
||||||
const retUser = await this.fetchUserDetailInfo(uid, UserDetailSource.KDB);
|
if (retUser && retUser.uin !== '0') {
|
||||||
if (retUser.uin !== '0') {
|
return retUser;
|
||||||
return retUser;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
}
|
}
|
||||||
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
this.context.logger.logDebug('[NapCat] [Mark] getUserDetailInfo Mode1 Failed.');
|
||||||
return this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
|
return this.fetchUserDetailInfo(uid, UserDetailSource.KSERVER);
|
||||||
|
@ -848,41 +848,6 @@ export interface MultiForwardMsgElement {
|
|||||||
resId: string;
|
resId: string;
|
||||||
fileName: string;
|
fileName: string;
|
||||||
}
|
}
|
||||||
export enum NTSubMsgType {
|
|
||||||
KMSGSUBTYPEARKGROUPANNOUNCE = 3,
|
|
||||||
KMSGSUBTYPEARKGROUPANNOUNCECONFIRMREQUIRED = 4,
|
|
||||||
KMSGSUBTYPEARKGROUPGIFTATME = 5,
|
|
||||||
KMSGSUBTYPEARKGROUPTASKATALL = 6,
|
|
||||||
KMSGSUBTYPEARKMULTIMSG = 7,
|
|
||||||
KMSGSUBTYPEARKNORMAL = 0,
|
|
||||||
KMSGSUBTYPEARKTENCENTDOCFROMMINIAPP = 1,
|
|
||||||
KMSGSUBTYPEARKTENCENTDOCFROMPLUSPANEL = 2,
|
|
||||||
KMSGSUBTYPEEMOTICON = 15,
|
|
||||||
KMSGSUBTYPEFILEAPP = 11,
|
|
||||||
KMSGSUBTYPEFILEAUDIO = 3,
|
|
||||||
KMSGSUBTYPEFILEDOC = 4,
|
|
||||||
KMSGSUBTYPEFILEEXCEL = 6,
|
|
||||||
KMSGSUBTYPEFILEFOLDER = 13,
|
|
||||||
KMSGSUBTYPEFILEHTML = 10,
|
|
||||||
KMSGSUBTYPEFILEIPA = 14,
|
|
||||||
KMSGSUBTYPEFILENORMAL = 0,
|
|
||||||
KMSGSUBTYPEFILEPDF = 7,
|
|
||||||
KMSGSUBTYPEFILEPIC = 1,
|
|
||||||
KMSGSUBTYPEFILEPPT = 5,
|
|
||||||
KMSGSUBTYPEFILEPSD = 12,
|
|
||||||
KMSGSUBTYPEFILETXT = 8,
|
|
||||||
KMSGSUBTYPEFILEVIDEO = 2,
|
|
||||||
KMSGSUBTYPEFILEZIP = 9,
|
|
||||||
KMSGSUBTYPELINK = 5,
|
|
||||||
KMSGSUBTYPEMARKETFACE = 1,
|
|
||||||
KMSGSUBTYPEMIXEMOTICON = 7,
|
|
||||||
KMSGSUBTYPEMIXFACE = 3,
|
|
||||||
KMSGSUBTYPEMIXMARKETFACE = 2,
|
|
||||||
KMSGSUBTYPEMIXPIC = 1,
|
|
||||||
KMSGSUBTYPEMIXREPLY = 4,
|
|
||||||
KMSGSUBTYPEMIXTEXT = 0,
|
|
||||||
KMSGSUBTYPETENCENTDOC = 6
|
|
||||||
}
|
|
||||||
export enum SendStatusType {
|
export enum SendStatusType {
|
||||||
KSEND_STATUS_FAILED = 0,
|
KSEND_STATUS_FAILED = 0,
|
||||||
KSEND_STATUS_SENDING = 1,
|
KSEND_STATUS_SENDING = 1,
|
||||||
@ -914,7 +879,7 @@ export interface RawMessage {
|
|||||||
|
|
||||||
msgType: NTMsgType;
|
msgType: NTMsgType;
|
||||||
|
|
||||||
subMsgType: NTSubMsgType;
|
subMsgType: number;
|
||||||
|
|
||||||
senderUid: string;
|
senderUid: string;
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ export interface NodeIKernelGroupService {
|
|||||||
uid: string,
|
uid: string,
|
||||||
index: number//0
|
index: number//0
|
||||||
}>,
|
}>,
|
||||||
infos: {},
|
infos: unknown,
|
||||||
finish: true,
|
finish: true,
|
||||||
hasRobot: false
|
hasRobot: false
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ export interface NodeIKernelMsgService {
|
|||||||
|
|
||||||
recallMsg(peer: Peer, msgIds: string[]): Promise<GeneralCallResult>;
|
recallMsg(peer: Peer, msgIds: string[]): Promise<GeneralCallResult>;
|
||||||
|
|
||||||
addKernelMsgImportToolListener(arg: Object): unknown;
|
addKernelMsgImportToolListener(arg: unknown): unknown;
|
||||||
|
|
||||||
removeKernelMsgListener(args: unknown): unknown;
|
removeKernelMsgListener(args: unknown): unknown;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ export interface NodeIKernelMsgService {
|
|||||||
|
|
||||||
getOnLineDev(): void;
|
getOnLineDev(): void;
|
||||||
|
|
||||||
kickOffLine(DevInfo: Object): unknown;
|
kickOffLine(DevInfo: unknown): unknown;
|
||||||
|
|
||||||
setStatus(args: { status: number, extStatus: number, batteryStatus: number }): Promise<GeneralCallResult>;
|
setStatus(args: { status: number, extStatus: number, batteryStatus: number }): Promise<GeneralCallResult>;
|
||||||
|
|
||||||
@ -80,11 +80,11 @@ export interface NodeIKernelMsgService {
|
|||||||
// this.voipToken = bArr2;
|
// this.voipToken = bArr2;
|
||||||
// this.profileId = str;
|
// this.profileId = str;
|
||||||
|
|
||||||
setToken(arg: Object): unknown;
|
setToken(arg: unknown): unknown;
|
||||||
|
|
||||||
switchForeGround(): unknown;
|
switchForeGround(): unknown;
|
||||||
|
|
||||||
switchBackGround(arg: Object): unknown;
|
switchBackGround(arg: unknown): unknown;
|
||||||
|
|
||||||
//hex
|
//hex
|
||||||
setTokenForMqq(token: string): unknown;
|
setTokenForMqq(token: string): unknown;
|
||||||
@ -384,7 +384,7 @@ export interface NodeIKernelMsgService {
|
|||||||
getFileThumbSavePath(...args: unknown[]): unknown;
|
getFileThumbSavePath(...args: unknown[]): unknown;
|
||||||
|
|
||||||
//猜测居多
|
//猜测居多
|
||||||
translatePtt2Text(MsgId: string, Peer: {}, MsgElement: {}): unknown;
|
translatePtt2Text(MsgId: string, Peer: Peer, MsgElement: unknown): unknown;
|
||||||
|
|
||||||
setPttPlayedState(...args: unknown[]): unknown;
|
setPttPlayedState(...args: unknown[]): unknown;
|
||||||
|
|
||||||
@ -668,7 +668,7 @@ export interface NodeIKernelMsgService {
|
|||||||
|
|
||||||
recordEmoji(...args: unknown[]): unknown;
|
recordEmoji(...args: unknown[]): unknown;
|
||||||
|
|
||||||
fetchGetHitEmotionsByWord(args: Object): Promise<unknown>;//表情推荐?
|
fetchGetHitEmotionsByWord(args: unknown): Promise<unknown>;//表情推荐?
|
||||||
|
|
||||||
deleteAllRoamMsgs(...args: unknown[]): unknown;//漫游消息?
|
deleteAllRoamMsgs(...args: unknown[]): unknown;//漫游消息?
|
||||||
|
|
||||||
|
@ -69,9 +69,9 @@ export interface NodeQQNTWrapperUtil {
|
|||||||
|
|
||||||
genFileShaAndMd5Hex(path: string, unknown: number): unknown; //可能是错的
|
genFileShaAndMd5Hex(path: string, unknown: number): unknown; //可能是错的
|
||||||
|
|
||||||
setTraceInfo(unknown: Object): unknown;
|
setTraceInfo(unknown: unknown): unknown;
|
||||||
|
|
||||||
encodeOffLine(unknown: Object): unknown;
|
encodeOffLine(unknown: unknown): unknown;
|
||||||
|
|
||||||
decodeOffLine(arg: string): unknown; //可能是错的 传递hex
|
decodeOffLine(arg: string): unknown; //可能是错的 传递hex
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ export interface NodeQQNTWrapperUtil {
|
|||||||
|
|
||||||
runProcessArgs(arg0: string, arg1: { [key: string]: string }, arg2: boolean): unknown;
|
runProcessArgs(arg0: string, arg1: { [key: string]: string }, arg2: boolean): unknown;
|
||||||
|
|
||||||
calcThumbSize(arg0: number, arg1: number, arg2: Object): unknown;
|
calcThumbSize(arg0: number, arg1: number, arg2: unknown): unknown;
|
||||||
|
|
||||||
fullWordToHalfWord(arg0: string): unknown;
|
fullWordToHalfWord(arg0: string): unknown;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
this.CoreContext.context.logger.logDebug('GetFileBase Mode - 1 Error');
|
||||||
}
|
}
|
||||||
|
|
||||||
const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems;
|
const NTSearchNameResult = (await NTQQFileApi.searchfile([payload.file])).resultItems;
|
||||||
|
@ -24,7 +24,7 @@ export class SetQQProfile extends BaseAction<Payload, any | null> {
|
|||||||
const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid);
|
const OldProfile = await NTQQUserApi.getUserDetailInfo(self.uid);
|
||||||
const ret = await NTQQUserApi.modifySelfProfile({
|
const ret = await NTQQUserApi.modifySelfProfile({
|
||||||
nick: payload.nickname,
|
nick: payload.nickname,
|
||||||
longNick: payload?.personal_note ?? OldProfile?.longNick!,
|
longNick: (payload?.personal_note ?? OldProfile?.longNick) || '',
|
||||||
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
sex: parseInt(payload?.sex ? payload?.sex.toString() : OldProfile?.sex!.toString()),
|
||||||
birthday: { birthday_year: OldProfile?.birthday_year!.toString(), birthday_month: OldProfile?.birthday_month!.toString(), birthday_day: OldProfile?.birthday_day!.toString() },
|
birthday: { birthday_year: OldProfile?.birthday_year!.toString(), birthday_month: OldProfile?.birthday_month!.toString(), birthday_day: OldProfile?.birthday_day!.toString() },
|
||||||
location: undefined,
|
location: undefined,
|
||||||
|
@ -158,7 +158,7 @@ export class SendMsg extends BaseAction<OB11PostSendMsg, ReturnDataType> {
|
|||||||
if (payload.user_id && payload.message_type !== 'group') {
|
if (payload.user_id && payload.message_type !== 'group') {
|
||||||
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
const uid = await NTQQUserApi.getUidByUinV2(payload.user_id.toString());
|
||||||
const isBuddy = await NTQQFriendApi.isBuddy(uid!);
|
const isBuddy = await NTQQFriendApi.isBuddy(uid!);
|
||||||
if (!isBuddy) { }
|
//if (!isBuddy) { }
|
||||||
}
|
}
|
||||||
return { valid: true };
|
return { valid: true };
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user