refactor: 优化eslint配置,提升代码质量 (#1341)
* feat: 统一并标准化eslint * lint: napcat.webui * lint: napcat.webui * lint: napcat.core * build: fix * lint: napcat.webui * refactor: 重构eslint * Update README.md
This commit is contained in:
1 parent
c9b1d3fafa
commit
2185a884b4
651 files changed
+37978
-37584
No files matched your search
@@ -7,93 +7,93 @@ import { Static, Type } from '@sinclair/typebox';
|
||||
import { NetworkAdapterConfig } from '@/onebot/config/config';
|
||||
|
||||
const SchemaData = Type.Object({
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
group_id: Type.Union([Type.Number(), Type.String()]),
|
||||
});
|
||||
|
||||
type Payload = Static<typeof SchemaData>;
|
||||
|
||||
export class GetGroupEssence extends OneBotAction<Payload, unknown> {
|
||||
override actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||
override payloadSchema = SchemaData;
|
||||
override actionName = ActionName.GoCQHTTP_GetEssenceMsg;
|
||||
override payloadSchema = SchemaData;
|
||||
|
||||
private async msgSeqToMsgId(peer: Peer, msgSeq: string, msgRandom: string) {
|
||||
const replyMsgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(peer, msgSeq, 1, true, true)).msgList.find((msg) => msg.msgSeq === msgSeq && msg.msgRandom === msgRandom);
|
||||
if (!replyMsgList) {
|
||||
return undefined;
|
||||
}
|
||||
private async msgSeqToMsgId (peer: Peer, msgSeq: string, msgRandom: string) {
|
||||
const replyMsgList = (await this.core.apis.MsgApi.getMsgsBySeqAndCount(peer, msgSeq, 1, true, true)).msgList.find((msg) => msg.msgSeq === msgSeq && msg.msgRandom === msgRandom);
|
||||
if (!replyMsgList) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
id: MessageUnique.createUniqueMsgId(peer, replyMsgList.msgId),
|
||||
msg: replyMsgList,
|
||||
};
|
||||
}
|
||||
|
||||
async _handle (payload: Payload, _adapter: string, config: NetworkAdapterConfig) {
|
||||
const msglist = (await this.core.apis.WebApi.getGroupEssenceMsgAll(payload.group_id.toString()))
|
||||
.flatMap((e) => e?.data?.msg_list)
|
||||
// 在群精华回空的时候会出现[null]的情况~ https://github.com/NapNeko/NapCatQQ/issues/1334
|
||||
.filter(Boolean);
|
||||
if (!msglist) {
|
||||
throw new Error('获取失败');
|
||||
}
|
||||
return await Promise.all(msglist.map(async (msg) => {
|
||||
const msgOriginData = await this.msgSeqToMsgId({
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
peerUid: payload.group_id.toString(),
|
||||
}, msg.msg_seq.toString(), msg.msg_random.toString());
|
||||
if (msgOriginData) {
|
||||
const { id: message_id, msg: rawMessage } = msgOriginData;
|
||||
return {
|
||||
id: MessageUnique.createUniqueMsgId(peer, replyMsgList.msgId),
|
||||
msg: replyMsgList
|
||||
msg_seq: msg.msg_seq,
|
||||
msg_random: msg.msg_random,
|
||||
sender_id: +msg.sender_uin,
|
||||
sender_nick: msg.sender_nick,
|
||||
operator_id: +msg.add_digest_uin,
|
||||
operator_nick: msg.add_digest_nick,
|
||||
message_id,
|
||||
operator_time: msg.add_digest_time,
|
||||
content: (await this.obContext.apis.MsgApi.parseMessage(rawMessage, config.messagePostFormat))?.message,
|
||||
};
|
||||
}
|
||||
|
||||
async _handle(payload: Payload, _adapter: string, config: NetworkAdapterConfig) {
|
||||
const msglist = (await this.core.apis.WebApi.getGroupEssenceMsgAll(payload.group_id.toString()))
|
||||
.flatMap((e) => e?.data?.msg_list)
|
||||
// 在群精华回空的时候会出现[null]的情况~ https://github.com/NapNeko/NapCatQQ/issues/1334
|
||||
.filter(Boolean);
|
||||
if (!msglist) {
|
||||
throw new Error('获取失败');
|
||||
}
|
||||
return await Promise.all(msglist.map(async (msg) => {
|
||||
const msgOriginData = await this.msgSeqToMsgId({
|
||||
chatType: ChatType.KCHATTYPEGROUP,
|
||||
peerUid: payload.group_id.toString(),
|
||||
}, msg.msg_seq.toString(), msg.msg_random.toString());
|
||||
if (msgOriginData) {
|
||||
const { id: message_id, msg: rawMessage } = msgOriginData;
|
||||
return {
|
||||
msg_seq: msg.msg_seq,
|
||||
msg_random: msg.msg_random,
|
||||
sender_id: +msg.sender_uin,
|
||||
sender_nick: msg.sender_nick,
|
||||
operator_id: +msg.add_digest_uin,
|
||||
operator_nick: msg.add_digest_nick,
|
||||
message_id: message_id,
|
||||
operator_time: msg.add_digest_time,
|
||||
content: (await this.obContext.apis.MsgApi.parseMessage(rawMessage, config.messagePostFormat))?.message
|
||||
};
|
||||
}
|
||||
const msgTempData = JSON.stringify({
|
||||
msg_seq: msg.msg_seq.toString(),
|
||||
msg_random: msg.msg_random.toString(),
|
||||
group_id: payload.group_id.toString(),
|
||||
});
|
||||
const hash = crypto.createHash('md5').update(msgTempData).digest();
|
||||
//设置第一个bit为0 保证shortId为正数
|
||||
if(hash[0]){
|
||||
hash[0] &= 0x7f;
|
||||
}
|
||||
const shortId = hash.readInt32BE(0);
|
||||
this.core.apis.GroupApi.essenceLRU.set(shortId, msgTempData);
|
||||
}
|
||||
const msgTempData = JSON.stringify({
|
||||
msg_seq: msg.msg_seq.toString(),
|
||||
msg_random: msg.msg_random.toString(),
|
||||
group_id: payload.group_id.toString(),
|
||||
});
|
||||
const hash = crypto.createHash('md5').update(msgTempData).digest();
|
||||
// 设置第一个bit为0 保证shortId为正数
|
||||
if (hash[0]) {
|
||||
hash[0] &= 0x7f;
|
||||
}
|
||||
const shortId = hash.readInt32BE(0);
|
||||
this.core.apis.GroupApi.essenceLRU.set(shortId, msgTempData);
|
||||
return {
|
||||
msg_seq: msg.msg_seq,
|
||||
msg_random: msg.msg_random,
|
||||
sender_id: +msg.sender_uin,
|
||||
sender_nick: msg.sender_nick,
|
||||
operator_id: +msg.add_digest_uin,
|
||||
operator_nick: msg.add_digest_nick,
|
||||
message_id: shortId,
|
||||
operator_time: msg.add_digest_time,
|
||||
content: msg.msg_content.map((msg) => {
|
||||
if (msg.msg_type === 1) {
|
||||
return {
|
||||
msg_seq: msg.msg_seq,
|
||||
msg_random: msg.msg_random,
|
||||
sender_id: +msg.sender_uin,
|
||||
sender_nick: msg.sender_nick,
|
||||
operator_id: +msg.add_digest_uin,
|
||||
operator_nick: msg.add_digest_nick,
|
||||
message_id: shortId,
|
||||
operator_time: msg.add_digest_time,
|
||||
content: msg.msg_content.map((msg) => {
|
||||
if (msg.msg_type === 1) {
|
||||
return {
|
||||
type: 'text',
|
||||
data: {
|
||||
text: msg?.text
|
||||
}
|
||||
};
|
||||
} else if (msg.msg_type === 3) {
|
||||
return {
|
||||
type: 'image',
|
||||
data: {
|
||||
url: msg?.image_url,
|
||||
}
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}).filter(e => e !== undefined),
|
||||
type: 'text',
|
||||
data: {
|
||||
text: msg?.text,
|
||||
},
|
||||
};
|
||||
}));
|
||||
}
|
||||
} else if (msg.msg_type === 3) {
|
||||
return {
|
||||
type: 'image',
|
||||
data: {
|
||||
url: msg?.image_url,
|
||||
},
|
||||
};
|
||||
}
|
||||
return undefined;
|
||||
}).filter(e => e !== undefined),
|
||||
};
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user