Apply a collection of small code cleanups across the repo for consistency and lint-safety. Changes include: - Use strict equality (===) where appropriate (GetEmojiLikes, about page checks). - Replace Array.map used for side effects with Array.forEach (GetMsg). - Rename unused catch parameters to underscore-prefixed names to avoid lint warnings (multiple backend/middleware files). - Replace void with undefined in an actions.call invocation (builtin plugin index). - Remove an unused loadedCount variable when reading .env (napcat-shell). - Rename promise resolver parameter to `resolve` for clarity in tests and keep setTimeout usage (rpc.test.ts). - Strengthen external shims types by changing generic parameter names to _T and update inversify ServiceIdentifier generic param (external-shims.d.ts). - Simplify post-build script imports and comment out an external-type mapping block; fix a regex character class bug (post-build.mjs). - Prefix several unused test stub variables with underscore to indicate intentional unused status (test-dist.ts). - Minor JSX formatting/indentation fixes in password_login component and UI text indentation in system_info. - Misc: SSE/config and plugin config handlers adjusted to consistent catch parameter naming; update mirror/download error catch variable name. These edits are non-functional refactors focused on code style, lint compliance and small robustness/clarity improvements.
76 lines
3.2 KiB
TypeScript
76 lines
3.2 KiB
TypeScript
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
|
|
import { ActionName } from '@/napcat-onebot/action/router';
|
|
import { MessageUnique } from 'napcat-common/src/message-unique';
|
|
import { Static, Type } from '@sinclair/typebox';
|
|
import { NetworkAdapterConfig } from '@/napcat-onebot/config/config';
|
|
|
|
import { MsgActionsExamples } from './examples';
|
|
|
|
const PayloadSchema = Type.Object({
|
|
message_id: Type.Union([Type.Number(), Type.String()], { description: '消息ID' }),
|
|
});
|
|
|
|
type PayloadType = Static<typeof PayloadSchema>;
|
|
|
|
const ReturnSchema = Type.Object({
|
|
time: Type.Number({ description: '发送时间' }),
|
|
message_type: Type.String({ description: '消息类型' }),
|
|
message_id: Type.Number({ description: '消息ID' }),
|
|
real_id: Type.Number({ description: '真实ID' }),
|
|
message_seq: Type.Number({ description: '消息序号' }),
|
|
sender: Type.Any({ description: '发送者' }),
|
|
message: Type.Any({ description: '消息内容' }),
|
|
raw_message: Type.String({ description: '原始消息内容' }),
|
|
font: Type.Number({ description: '字体' }),
|
|
group_id: Type.Optional(Type.Union([Type.Number(), Type.String()], { description: '群号' })),
|
|
user_id: Type.Union([Type.Number(), Type.String()], { description: '发送者QQ号' }),
|
|
emoji_likes_list: Type.Optional(Type.Array(Type.Any(), { description: '表情回应列表' })),
|
|
}, { description: 'OneBot 11 消息' });
|
|
|
|
type ReturnType = Static<typeof ReturnSchema>;
|
|
|
|
class GetMsg extends OneBotAction<PayloadType, ReturnType> {
|
|
override actionName = ActionName.GetMsg;
|
|
override payloadSchema = PayloadSchema;
|
|
override returnSchema = ReturnSchema;
|
|
override actionSummary = '获取消息';
|
|
override actionDescription = '根据消息 ID 获取消息详细信息';
|
|
override actionTags = ['消息接口'];
|
|
override payloadExample = MsgActionsExamples.GetMsg.payload;
|
|
override returnExample = MsgActionsExamples.GetMsg.response;
|
|
|
|
async _handle (payload: PayloadType, _adapter: string, config: NetworkAdapterConfig) {
|
|
if (!payload.message_id) {
|
|
throw Error('参数message_id不能为空');
|
|
}
|
|
const MsgShortId = MessageUnique.getShortIdByMsgId(payload.message_id.toString());
|
|
const msgIdWithPeer = MessageUnique.getMsgIdAndPeerByShortId(MsgShortId ?? +payload.message_id);
|
|
if (!msgIdWithPeer) {
|
|
throw new Error('消息不存在');
|
|
}
|
|
const peer = { guildId: '', peerUid: msgIdWithPeer?.Peer.peerUid, chatType: msgIdWithPeer.Peer.chatType };
|
|
const msg = (await this.core.apis.MsgApi.getMsgsByMsgId(peer, [msgIdWithPeer?.MsgId || payload.message_id.toString()])).msgList[0];
|
|
if (!msg) throw Error('消息不存在');
|
|
const retMsg = await this.obContext.apis.MsgApi.parseMessage(msg, config.messagePostFormat);
|
|
if (!retMsg) throw Error('消息为空');
|
|
retMsg.emoji_likes_list = [];
|
|
msg.emojiLikesList?.forEach(emoji => {
|
|
retMsg.emoji_likes_list?.push({
|
|
emoji_id: emoji.emojiId,
|
|
emoji_type: emoji.emojiType,
|
|
likes_cnt: emoji.likesCnt,
|
|
});
|
|
});
|
|
try {
|
|
retMsg.message_id = MessageUnique.createUniqueMsgId(peer, msg.msgId)!;
|
|
retMsg.message_seq = retMsg.message_id;
|
|
retMsg.real_id = retMsg.message_id;
|
|
} catch {
|
|
// ignored
|
|
}
|
|
return retMsg;
|
|
}
|
|
}
|
|
|
|
export default GetMsg;
|