chore: run eslint --fix in onebot module

This commit is contained in:
Wesley F. Young
2024-08-09 20:35:03 +08:00
parent f5b6fa31a7
commit af01a073ef
110 changed files with 3832 additions and 3829 deletions

View File

@@ -7,65 +7,65 @@ interface Response {
bkn: string
}
const SchemaData = {
type: 'object',
properties: {
domain: { type: 'string' }
},
required: ['domain']
type: 'object',
properties: {
domain: { type: 'string' }
},
required: ['domain']
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export class GetCookies extends BaseAction<Payload, Response> {
actionName = ActionName.GetCookies;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
// if (!payload.domain) {
// throw new Error('缺少参数 domain');
// }
// if (payload.domain.endsWith('qzone.qq.com')) {
// // 兼容整个 *.qzone.qq.com
// const data = (await NTQQUserApi.getQzoneCookies());
// const Bkn = WebApi.genBkn(data.p_skey);
// const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
// return { cookies: CookieValue };
// }
// // 取Skey
// // 先NodeIKernelTicketService.forceFetchClientKey('')
// // 返回值
// // {
// // result: 0,
// // errMsg: '',
// // url: '',
// // keyIndex: '19',
// // clientKey: 'clientKey',
// // expireTime: '7200'
// // }
// // request https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=1627126029&clientkey=key
// // &u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=keyIndex
// const _PSkey = (await NTQQUserApi.getPSkey([payload.domain]))[payload.domain];
// // 取Pskey
// // NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
// // {
// // domainPskeyMap: 0,
// // errMsg: 'success',
// // domainPskeyMap: Map(1) {
// // 'qun.qq.com' => 'pskey'
// // }
// // }
// if (!_PSkey || !_Skey) {
// throw new Error('获取Cookies失败');
// }
// const cookies = `p_skey=${_PSkey}; skey=${_Skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
// return {
// cookies
// };
const cookiesObject = await NTQQUserApi.getCookies(payload.domain);
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
const bkn = NTQQWebApi.getBknFromCookie(cookiesObject.p_skey);
return { cookies, bkn };
}
actionName = ActionName.GetCookies;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQWebApi = this.CoreContext.getApiContext().WebApi;
// if (!payload.domain) {
// throw new Error('缺少参数 domain');
// }
// if (payload.domain.endsWith('qzone.qq.com')) {
// // 兼容整个 *.qzone.qq.com
// const data = (await NTQQUserApi.getQzoneCookies());
// const Bkn = WebApi.genBkn(data.p_skey);
// const CookieValue = 'p_skey=' + data.p_skey + '; skey=' + data.skey + '; p_uin=o' + selfInfo.uin + '; uin=o' + selfInfo.uin;
// return { cookies: CookieValue };
// }
// // 取Skey
// // 先NodeIKernelTicketService.forceFetchClientKey('')
// // 返回值
// // {
// // result: 0,
// // errMsg: '',
// // url: '',
// // keyIndex: '19',
// // clientKey: 'clientKey',
// // expireTime: '7200'
// // }
// // request https://ssl.ptlogin2.qq.com/jump?ptlang=1033&clientuin=1627126029&clientkey=key
// // &u1=https%3A%2F%2Fh5.qzone.qq.com%2Fqqnt%2Fqzoneinpcqq%2Ffriend%3Frefresh%3D0%26clientuin%3D0%26darkMode%3D0&keyindex=keyIndex
// const _PSkey = (await NTQQUserApi.getPSkey([payload.domain]))[payload.domain];
// // 取Pskey
// // NodeIKernelTipOffService.getPskey([ 'qun.qq.com' ], true )
// // {
// // domainPskeyMap: 0,
// // errMsg: 'success',
// // domainPskeyMap: Map(1) {
// // 'qun.qq.com' => 'pskey'
// // }
// // }
// if (!_PSkey || !_Skey) {
// throw new Error('获取Cookies失败');
// }
// const cookies = `p_skey=${_PSkey}; skey=${_Skey}; p_uin=o${selfInfo.uin}; uin=o${selfInfo.uin}`;
// return {
// cookies
// };
const cookiesObject = await NTQQUserApi.getCookies(payload.domain);
//把获取到的cookiesObject转换成 k=v; 格式字符串拼接在一起
const cookies = Object.entries(cookiesObject).map(([key, value]) => `${key}=${value}`).join('; ');
const bkn = NTQQWebApi.getBknFromCookie(cookiesObject.p_skey);
return { cookies, bkn };
}
}

View File

@@ -6,19 +6,19 @@ import { FromSchema, JSONSchema } from 'json-schema-to-ts';
// no_cache get时传字符串
const SchemaData = {
type: 'object',
properties: {
no_cache: { type: ['boolean', 'string'] },
}
type: 'object',
properties: {
no_cache: { type: ['boolean', 'string'] },
}
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class GetFriendList extends BaseAction<Payload, OB11User[]> {
actionName = ActionName.GetFriendList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
//全新逻辑
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
}
actionName = ActionName.GetFriendList;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
//全新逻辑
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
return OB11Constructor.friendsV2(await NTQQFriendApi.getBuddyV2(payload?.no_cache === true || payload?.no_cache === 'true'));
}
}

View File

@@ -5,49 +5,49 @@ import { ActionName } from '../types';
import { OB11Constructor } from '@/onebot/helper/data';
const SchemaData = {
type: 'object',
properties: {
count: { type: ['number', 'string'] }
}
type: 'object',
properties: {
count: { type: ['number', 'string'] }
}
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class GetRecentContact extends BaseAction<Payload, any> {
actionName = ActionName.GetRecentContact;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
const data = await Promise.all(ret.info.changedList.map(async (t) => {
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
if (FastMsg.msgList.length > 0) {
//扩展ret.info.changedList
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], "array");
return {
lastestMsg: lastestMsg,
peerUin: t.peerUin,
remark: t.remark,
msgTime: t.msgTime,
chatType: t.chatType,
msgId: t.msgId,
sendNickName: t.sendNickName,
sendMemberName: t.sendMemberName,
peerName: t.peerName
};
}
return {
peerUin: t.peerUin,
remark: t.remark,
msgTime: t.msgTime,
chatType: t.chatType,
msgId: t.msgId,
sendNickName: t.sendNickName,
sendMemberName: t.sendMemberName,
peerName: t.peerName
};
}));
return data;
}
actionName = ActionName.GetRecentContact;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload) {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
const NTQQMsgApi = this.CoreContext.getApiContext().MsgApi;
const ret = await NTQQUserApi.getRecentContactListSnapShot(parseInt((payload.count || 10).toString()));
const data = await Promise.all(ret.info.changedList.map(async (t) => {
const FastMsg = await NTQQMsgApi.getMsgsByMsgId({ chatType: t.chatType, peerUid: t.peerUid }, [t.msgId]);
if (FastMsg.msgList.length > 0) {
//扩展ret.info.changedList
const lastestMsg = await OB11Constructor.message(this.CoreContext, FastMsg.msgList[0], "array");
return {
lastestMsg: lastestMsg,
peerUin: t.peerUin,
remark: t.remark,
msgTime: t.msgTime,
chatType: t.chatType,
msgId: t.msgId,
sendNickName: t.sendNickName,
sendMemberName: t.sendMemberName,
peerName: t.peerName
};
}
return {
peerUin: t.peerUin,
remark: t.remark,
msgTime: t.msgTime,
chatType: t.chatType,
msgId: t.msgId,
sendNickName: t.sendNickName,
sendMemberName: t.sendMemberName,
peerName: t.peerName
};
}));
return data;
}
}

View File

@@ -4,33 +4,33 @@ import { ActionName } from '../types';
import { FromSchema, JSONSchema } from 'json-schema-to-ts';
const SchemaData = {
type: 'object',
properties: {
user_id: { type: ['number', 'string'] },
times: { type: ['number', 'string'] }
},
required: ['user_id', 'times']
type: 'object',
properties: {
user_id: { type: ['number', 'string'] },
times: { type: ['number', 'string'] }
},
required: ['user_id', 'times']
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class SendLike extends BaseAction<Payload, null> {
actionName = ActionName.SendLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
//logDebug('点赞参数', payload);
try {
const qq = payload.user_id.toString();
const uid: string = await NTQQUserApi.getUidByUin(qq) || '';
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
//logDebug('点赞结果', result);
if (result.result !== 0) {
throw Error(result.errMsg);
}
} catch (e) {
throw `点赞失败 ${e}`;
actionName = ActionName.SendLike;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQUserApi = this.CoreContext.getApiContext().UserApi;
//logDebug('点赞参数', payload);
try {
const qq = payload.user_id.toString();
const uid: string = await NTQQUserApi.getUidByUin(qq) || '';
const result = await NTQQUserApi.like(uid, parseInt(payload.times?.toString()) || 1);
//logDebug('点赞结果', result);
if (result.result !== 0) {
throw Error(result.errMsg);
}
} catch (e) {
throw `点赞失败 ${e}`;
}
return null;
}
return null;
}
}

View File

@@ -4,24 +4,24 @@ import { ActionName } from '../types';
import { NTQQFriendApi } from '@/core/apis/friend';
const SchemaData = {
type: 'object',
properties: {
flag: { type: 'string' },
approve: { type: ['string', 'boolean'] },
remark: { type: 'string' }
},
required: ['flag']
type: 'object',
properties: {
flag: { type: 'string' },
approve: { type: ['string', 'boolean'] },
remark: { type: 'string' }
},
required: ['flag']
} as const satisfies JSONSchema;
type Payload = FromSchema<typeof SchemaData>;
export default class SetFriendAddRequest extends BaseAction<Payload, null> {
actionName = ActionName.SetFriendAddRequest;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
const approve = payload.approve?.toString() !== 'false';
await NTQQFriendApi.handleFriendRequest(payload.flag, approve);
return null;
}
actionName = ActionName.SetFriendAddRequest;
PayloadSchema = SchemaData;
protected async _handle(payload: Payload): Promise<null> {
const NTQQFriendApi = this.CoreContext.getApiContext().FriendApi;
const approve = payload.approve?.toString() !== 'false';
await NTQQFriendApi.handleFriendRequest(payload.flag, approve);
return null;
}
}