lint
This commit is contained in:
977 files changed
+198426
-158324
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -10,18 +10,23 @@ type Timed = { time: number };
|
||||
|
||||
/** notice envelope — `{ time, self_id, post_type: 'notice', ...fields }`. */
|
||||
export function notice(ctx: ConverterContext, event: Timed, fields: JsonObject): JsonObject {
|
||||
return { time: event.time, self_id: ctx.selfId, post_type: 'notice', ...fields };
|
||||
return { time: event.time, self_id: ctx.selfId, post_type: 'notice', ...fields };
|
||||
}
|
||||
|
||||
/** request envelope — `{ time, self_id, post_type: 'request', ...fields }`. */
|
||||
export function request(ctx: ConverterContext, event: Timed, fields: JsonObject): JsonObject {
|
||||
return { time: event.time, self_id: ctx.selfId, post_type: 'request', ...fields };
|
||||
return { time: event.time, self_id: ctx.selfId, post_type: 'request', ...fields };
|
||||
}
|
||||
|
||||
/**
|
||||
* message envelope — `{ time, self_id, post_type, ...fields }`. `postType` is
|
||||
* 'message' or 'message_sent' (self-echo), decided per-message by the caller.
|
||||
*/
|
||||
export function message(ctx: ConverterContext, event: Timed, postType: string, fields: JsonObject): JsonObject {
|
||||
return { time: event.time, self_id: ctx.selfId, post_type: postType, ...fields };
|
||||
export function message(
|
||||
ctx: ConverterContext,
|
||||
event: Timed,
|
||||
postType: string,
|
||||
fields: JsonObject,
|
||||
): JsonObject {
|
||||
return { time: event.time, self_id: ctx.selfId, post_type: postType, ...fields };
|
||||
}
|
||||
@@ -1,70 +1,72 @@
|
||||
import type { MessageElement, QQEventVariant } from '@snowluma/protocol/events';
|
||||
import type { JsonObject } from '../types';
|
||||
import { convertFriendMessage, convertGroupMessage, convertTempMessage } from './to-message';
|
||||
import {
|
||||
convertFriendMessage,
|
||||
convertGroupMessage,
|
||||
convertTempMessage,
|
||||
} from './to-message';
|
||||
import {
|
||||
convertBotOffline,
|
||||
convertFriendAdd,
|
||||
convertFriendInputStatus,
|
||||
convertFriendProfileLike,
|
||||
convertFriendPoke,
|
||||
convertFriendRecall,
|
||||
convertGroupAdmin,
|
||||
convertGroupCardChange,
|
||||
convertGroupEssence,
|
||||
convertGroupFileUpload,
|
||||
convertGroupMemberJoin,
|
||||
convertGroupMemberLeave,
|
||||
convertGroupMsgEmojiLike,
|
||||
convertGroupMute,
|
||||
convertGroupNameChange,
|
||||
convertGroupTitleChange,
|
||||
convertGroupPoke,
|
||||
convertGroupRecall,
|
||||
convertBotOffline,
|
||||
convertFriendAdd,
|
||||
convertFriendInputStatus,
|
||||
convertFriendProfileLike,
|
||||
convertFriendPoke,
|
||||
convertFriendRecall,
|
||||
convertGroupAdmin,
|
||||
convertGroupCardChange,
|
||||
convertGroupEssence,
|
||||
convertGroupFileUpload,
|
||||
convertGroupMemberJoin,
|
||||
convertGroupMemberLeave,
|
||||
convertGroupMsgEmojiLike,
|
||||
convertGroupMute,
|
||||
convertGroupNameChange,
|
||||
convertGroupTitleChange,
|
||||
convertGroupPoke,
|
||||
convertGroupRecall,
|
||||
} from './to-notice';
|
||||
import {
|
||||
convertFriendRequest,
|
||||
convertGroupInvite,
|
||||
} from './to-request';
|
||||
import { convertFriendRequest, convertGroupInvite } from './to-request';
|
||||
export { elementsToOneBotSegments } from './to-segment';
|
||||
|
||||
export type ImageUrlResolver = (element: MessageElement, isGroup: boolean) => string | Promise<string>;
|
||||
export type MediaUrlResolver = (element: MessageElement, isGroup: boolean, sessionId: number) => Promise<string>;
|
||||
export type ImageUrlResolver = (
|
||||
element: MessageElement,
|
||||
isGroup: boolean,
|
||||
) => string | Promise<string>;
|
||||
export type MediaUrlResolver = (
|
||||
element: MessageElement,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
) => Promise<string>;
|
||||
export type MessageIdResolver = (
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
sequence: number,
|
||||
eventName: string,
|
||||
timestamp?: number,
|
||||
replyElements?: readonly MessageElement[],
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
sequence: number,
|
||||
eventName: string,
|
||||
timestamp?: number,
|
||||
replyElements?: readonly MessageElement[],
|
||||
) => number;
|
||||
|
||||
export type MediaSegmentSink = (
|
||||
mediaType: 'image' | 'record' | 'video',
|
||||
element: MessageElement,
|
||||
data: JsonObject,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
mediaType: 'image' | 'record' | 'video',
|
||||
element: MessageElement,
|
||||
data: JsonObject,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
) => void;
|
||||
|
||||
// ─────────────── context ───────────────
|
||||
|
||||
export interface ConverterContext {
|
||||
selfId: number;
|
||||
imageUrlResolver: ImageUrlResolver | null;
|
||||
mediaUrlResolver: MediaUrlResolver | null;
|
||||
messageIdResolver: MessageIdResolver | null;
|
||||
mediaSegmentSink: MediaSegmentSink | null;
|
||||
selfId: number;
|
||||
imageUrlResolver: ImageUrlResolver | null;
|
||||
mediaUrlResolver: MediaUrlResolver | null;
|
||||
messageIdResolver: MessageIdResolver | null;
|
||||
mediaSegmentSink: MediaSegmentSink | null;
|
||||
}
|
||||
|
||||
// ─────────────── dispatcher ───────────────
|
||||
|
||||
/** Converter for one event kind — receives the narrowed event for that kind. */
|
||||
type ConverterFor<K extends QQEventVariant['kind']> =
|
||||
(ctx: ConverterContext, event: Extract<QQEventVariant, { kind: K }>) => JsonObject | Promise<JsonObject>;
|
||||
type ConverterFor<K extends QQEventVariant['kind']> = (
|
||||
ctx: ConverterContext,
|
||||
event: Extract<QQEventVariant, { kind: K }>,
|
||||
) => JsonObject | Promise<JsonObject>;
|
||||
|
||||
/**
|
||||
* Every event kind → its converter (or `null` for kinds intentionally not
|
||||
@@ -75,49 +77,57 @@ type ConverterFor<K extends QQEventVariant['kind']> =
|
||||
export type ConverterRegistry = { [K in QQEventVariant['kind']]: ConverterFor<K> | null };
|
||||
|
||||
export const CONVERTERS = {
|
||||
// Messages.
|
||||
friend_message: convertFriendMessage,
|
||||
group_message: convertGroupMessage,
|
||||
temp_message: convertTempMessage,
|
||||
// Notices.
|
||||
group_member_join: convertGroupMemberJoin,
|
||||
group_member_leave: convertGroupMemberLeave,
|
||||
group_mute: convertGroupMute,
|
||||
group_admin: convertGroupAdmin,
|
||||
friend_recall: convertFriendRecall,
|
||||
group_recall: convertGroupRecall,
|
||||
friend_poke: convertFriendPoke,
|
||||
group_poke: convertGroupPoke,
|
||||
group_essence: convertGroupEssence,
|
||||
group_file_upload: convertGroupFileUpload,
|
||||
friend_add: convertFriendAdd,
|
||||
friend_input_status: convertFriendInputStatus,
|
||||
friend_profile_like: convertFriendProfileLike,
|
||||
bot_offline: convertBotOffline,
|
||||
group_name_change: convertGroupNameChange,
|
||||
group_title_change: convertGroupTitleChange,
|
||||
group_card_change: convertGroupCardChange,
|
||||
group_msg_emoji_like: convertGroupMsgEmojiLike,
|
||||
// Requests.
|
||||
friend_request: convertFriendRequest,
|
||||
group_invite: convertGroupInvite,
|
||||
// Internal-only: async voice-to-text result, correlated by a pending
|
||||
// fetch_ptt_text; never emitted as an OneBot event.
|
||||
ptt_trans_result: null,
|
||||
// Internal-only cache snapshot consumed by Bridge.getOnlineClients().
|
||||
online_devices_changed: null,
|
||||
// Internal-only identity synchronization from another QQ client.
|
||||
friend_remark_changed: null,
|
||||
// Messages.
|
||||
friend_message: convertFriendMessage,
|
||||
group_message: convertGroupMessage,
|
||||
temp_message: convertTempMessage,
|
||||
// Notices.
|
||||
group_member_join: convertGroupMemberJoin,
|
||||
group_member_leave: convertGroupMemberLeave,
|
||||
group_mute: convertGroupMute,
|
||||
group_admin: convertGroupAdmin,
|
||||
friend_recall: convertFriendRecall,
|
||||
group_recall: convertGroupRecall,
|
||||
friend_poke: convertFriendPoke,
|
||||
group_poke: convertGroupPoke,
|
||||
group_essence: convertGroupEssence,
|
||||
group_file_upload: convertGroupFileUpload,
|
||||
friend_add: convertFriendAdd,
|
||||
friend_input_status: convertFriendInputStatus,
|
||||
friend_profile_like: convertFriendProfileLike,
|
||||
bot_offline: convertBotOffline,
|
||||
group_name_change: convertGroupNameChange,
|
||||
group_title_change: convertGroupTitleChange,
|
||||
group_card_change: convertGroupCardChange,
|
||||
group_msg_emoji_like: convertGroupMsgEmojiLike,
|
||||
// Requests.
|
||||
friend_request: convertFriendRequest,
|
||||
group_invite: convertGroupInvite,
|
||||
// Internal-only: async voice-to-text result, correlated by a pending
|
||||
// fetch_ptt_text; never emitted as an OneBot event.
|
||||
ptt_trans_result: null,
|
||||
// Internal-only cache snapshot consumed by Bridge.getOnlineClients().
|
||||
online_devices_changed: null,
|
||||
// Internal-only identity synchronization from another QQ client.
|
||||
friend_remark_changed: null,
|
||||
} satisfies ConverterRegistry;
|
||||
|
||||
export async function convertEvent(
|
||||
ctx: ConverterContext,
|
||||
event: QQEventVariant,
|
||||
ctx: ConverterContext,
|
||||
event: QQEventVariant,
|
||||
): Promise<JsonObject | null> {
|
||||
const converter = CONVERTERS[event.kind];
|
||||
if (!converter) return null;
|
||||
// The registry ties each key to its own event kind, but indexing by a
|
||||
// runtime `event.kind` loses that correlation — one localized cast restores it.
|
||||
return (converter as (ctx: ConverterContext, event: QQEventVariant) => JsonObject | Promise<JsonObject>)(ctx, event);
|
||||
}
|
||||
const converter = CONVERTERS[event.kind];
|
||||
|
||||
if (!converter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The registry ties each key to its own event kind, but indexing by a
|
||||
// runtime `event.kind` loses that correlation — one localized cast restores it.
|
||||
return (
|
||||
converter as (
|
||||
ctx: ConverterContext,
|
||||
event: QQEventVariant,
|
||||
) => JsonObject | Promise<JsonObject>
|
||||
)(ctx, event);
|
||||
}
|
||||
@@ -1,10 +1,6 @@
|
||||
import type { MessageElement, QQEventVariant } from '@snowluma/protocol/events';
|
||||
import { segmentsToRawMessage } from '../helper/cq';
|
||||
import {
|
||||
GROUP_MESSAGE_EVENT,
|
||||
PRIVATE_MESSAGE_EVENT,
|
||||
privateMessageEventName,
|
||||
} from '../message-id';
|
||||
import { GROUP_MESSAGE_EVENT, PRIVATE_MESSAGE_EVENT, privateMessageEventName } from '../message-id';
|
||||
import type { JsonObject } from '../types';
|
||||
import type { ConverterContext } from './index';
|
||||
import { elementsToOneBotSegments } from './to-segment';
|
||||
@@ -15,8 +11,13 @@ type FriendMessage = Extract<QQEventVariant, { kind: 'friend_message' }>;
|
||||
type GroupMessage = Extract<QQEventVariant, { kind: 'group_message' }>;
|
||||
type TempMessage = Extract<QQEventVariant, { kind: 'temp_message' }>;
|
||||
|
||||
function toSegments(ctx: ConverterContext, elements: MessageElement[], isGroup: boolean, sessionId: number) {
|
||||
return elementsToOneBotSegments(ctx, elements, isGroup, sessionId);
|
||||
function toSegments(
|
||||
ctx: ConverterContext,
|
||||
elements: MessageElement[],
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
) {
|
||||
return elementsToOneBotSegments(ctx, elements, isGroup, sessionId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,90 +26,111 @@ function toSegments(ctx: ConverterContext, elements: MessageElement[], isGroup:
|
||||
* which differs from senderUin on a self-sent echo.
|
||||
*/
|
||||
async function convertPrivateMessage(
|
||||
ctx: ConverterContext,
|
||||
event: FriendMessage | TempMessage,
|
||||
subType: 'friend' | 'group',
|
||||
ctx: ConverterContext,
|
||||
event: FriendMessage | TempMessage,
|
||||
subType: 'friend' | 'group',
|
||||
): Promise<JsonObject> {
|
||||
const isSelf = event.senderUin === ctx.selfId;
|
||||
const postType = isSelf ? 'message_sent' : 'message';
|
||||
const sessionId = event.kind === 'friend_message' && event.peerUin && event.peerUin > 0
|
||||
? event.peerUin
|
||||
: event.senderUin;
|
||||
// ContentHead field 5 (`msgSeq`) is sender-local in C2C and can collide in
|
||||
// both directions. Friend history/pushes expose field 11 (`ntMsgSeq`), which
|
||||
// is conversation-wide and therefore the canonical OneBot id input.
|
||||
const ntSequence = event.kind === 'friend_message' ? (event.ntMsgSeq ?? 0) : 0;
|
||||
const hasCanonicalNtSequence = ntSequence > 0
|
||||
&& event.sequenceAuthoritative !== false;
|
||||
const messageIdSequence = hasCanonicalNtSequence ? ntSequence : event.msgSeq;
|
||||
const eventName = event.kind === 'friend_message'
|
||||
? privateMessageEventName(isSelf, hasCanonicalNtSequence)
|
||||
: PRIVATE_MESSAGE_EVENT;
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver, false, sessionId, messageIdSequence, eventName,
|
||||
);
|
||||
const segments = await toSegments(ctx, event.elements, false, sessionId);
|
||||
const sender: JsonObject = {
|
||||
user_id: event.senderUin,
|
||||
nickname: event.senderNick,
|
||||
sex: 'unknown',
|
||||
age: 0,
|
||||
};
|
||||
// A temp (group-originated) message carries its source group so a client can
|
||||
// reply via send_private_msg(user_id, group_id=sender.group_id). Mirrors
|
||||
// go-cqhttp / NapCat, which expose it on sender.group_id.
|
||||
if (subType === 'group' && 'groupId' in event && event.groupId > 0) {
|
||||
sender.group_id = event.groupId;
|
||||
}
|
||||
const fields: JsonObject = {
|
||||
message_type: 'private',
|
||||
sub_type: subType,
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
user_id: event.senderUin,
|
||||
message: segments,
|
||||
raw_message: segmentsToRawMessage(segments),
|
||||
font: 0,
|
||||
sender,
|
||||
};
|
||||
if (isSelf && sessionId > 0 && sessionId !== ctx.selfId) fields.target_id = sessionId;
|
||||
return message(ctx, event, postType, fields);
|
||||
const isSelf = event.senderUin === ctx.selfId;
|
||||
const postType = isSelf ? 'message_sent' : 'message';
|
||||
const sessionId =
|
||||
event.kind === 'friend_message' && event.peerUin && event.peerUin > 0
|
||||
? event.peerUin
|
||||
: event.senderUin;
|
||||
// ContentHead field 5 (`msgSeq`) is sender-local in C2C and can collide in
|
||||
// both directions. Friend history/pushes expose field 11 (`ntMsgSeq`), which
|
||||
// is conversation-wide and therefore the canonical OneBot id input.
|
||||
const ntSequence = event.kind === 'friend_message' ? (event.ntMsgSeq ?? 0) : 0;
|
||||
const hasCanonicalNtSequence = ntSequence > 0 && event.sequenceAuthoritative !== false;
|
||||
const messageIdSequence = hasCanonicalNtSequence ? ntSequence : event.msgSeq;
|
||||
const eventName =
|
||||
event.kind === 'friend_message'
|
||||
? privateMessageEventName(isSelf, hasCanonicalNtSequence)
|
||||
: PRIVATE_MESSAGE_EVENT;
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
false,
|
||||
sessionId,
|
||||
messageIdSequence,
|
||||
eventName,
|
||||
);
|
||||
const segments = await toSegments(ctx, event.elements, false, sessionId);
|
||||
const sender: JsonObject = {
|
||||
user_id: event.senderUin,
|
||||
nickname: event.senderNick,
|
||||
sex: 'unknown',
|
||||
age: 0,
|
||||
};
|
||||
|
||||
// A temp (group-originated) message carries its source group so a client can
|
||||
// reply via send_private_msg(user_id, group_id=sender.group_id). Mirrors
|
||||
// go-cqhttp / NapCat, which expose it on sender.group_id.
|
||||
if (subType === 'group' && 'groupId' in event && event.groupId > 0) {
|
||||
sender.group_id = event.groupId;
|
||||
}
|
||||
|
||||
const fields: JsonObject = {
|
||||
message_type: 'private',
|
||||
sub_type: subType,
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
user_id: event.senderUin,
|
||||
message: segments,
|
||||
raw_message: segmentsToRawMessage(segments),
|
||||
font: 0,
|
||||
sender,
|
||||
};
|
||||
|
||||
if (isSelf && sessionId > 0 && sessionId !== ctx.selfId) {
|
||||
fields.target_id = sessionId;
|
||||
}
|
||||
|
||||
return message(ctx, event, postType, fields);
|
||||
}
|
||||
|
||||
export function convertFriendMessage(ctx: ConverterContext, event: FriendMessage): Promise<JsonObject> {
|
||||
return convertPrivateMessage(ctx, event, 'friend');
|
||||
export function convertFriendMessage(
|
||||
ctx: ConverterContext,
|
||||
event: FriendMessage,
|
||||
): Promise<JsonObject> {
|
||||
return convertPrivateMessage(ctx, event, 'friend');
|
||||
}
|
||||
|
||||
export function convertTempMessage(ctx: ConverterContext, event: TempMessage): Promise<JsonObject> {
|
||||
return convertPrivateMessage(ctx, event, 'group');
|
||||
return convertPrivateMessage(ctx, event, 'group');
|
||||
}
|
||||
|
||||
export async function convertGroupMessage(ctx: ConverterContext, event: GroupMessage): Promise<JsonObject> {
|
||||
const isSelf = event.senderUin === ctx.selfId;
|
||||
const postType = isSelf ? 'message_sent' : 'message';
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver, true, event.groupId, event.msgSeq, GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
const segments = await toSegments(ctx, event.elements, true, event.groupId);
|
||||
return message(ctx, event, postType, {
|
||||
message_type: 'group',
|
||||
sub_type: 'normal',
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
group_id: event.groupId,
|
||||
group_name: event.groupName,
|
||||
user_id: event.senderUin,
|
||||
message: segments,
|
||||
raw_message: segmentsToRawMessage(segments),
|
||||
font: 0,
|
||||
sender: {
|
||||
user_id: event.senderUin,
|
||||
nickname: event.senderNick,
|
||||
card: event.senderCard,
|
||||
role: event.senderRole || 'member',
|
||||
sex: 'unknown',
|
||||
age: 0,
|
||||
},
|
||||
anonymous: null,
|
||||
});
|
||||
export async function convertGroupMessage(
|
||||
ctx: ConverterContext,
|
||||
event: GroupMessage,
|
||||
): Promise<JsonObject> {
|
||||
const isSelf = event.senderUin === ctx.selfId;
|
||||
const postType = isSelf ? 'message_sent' : 'message';
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
true,
|
||||
event.groupId,
|
||||
event.msgSeq,
|
||||
GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
const segments = await toSegments(ctx, event.elements, true, event.groupId);
|
||||
return message(ctx, event, postType, {
|
||||
message_type: 'group',
|
||||
sub_type: 'normal',
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
group_id: event.groupId,
|
||||
group_name: event.groupName,
|
||||
user_id: event.senderUin,
|
||||
message: segments,
|
||||
raw_message: segmentsToRawMessage(segments),
|
||||
font: 0,
|
||||
sender: {
|
||||
user_id: event.senderUin,
|
||||
nickname: event.senderNick,
|
||||
card: event.senderCard,
|
||||
role: event.senderRole || 'member',
|
||||
sex: 'unknown',
|
||||
age: 0,
|
||||
},
|
||||
anonymous: null,
|
||||
});
|
||||
}
|
||||
@@ -25,235 +25,265 @@ type FriendProfileLike = Extract<QQEventVariant, { kind: 'friend_profile_like' }
|
||||
type BotOffline = Extract<QQEventVariant, { kind: 'bot_offline' }>;
|
||||
|
||||
export function convertGroupMemberJoin(ctx: ConverterContext, event: GroupMemberJoin): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_increase',
|
||||
sub_type: event.joinType
|
||||
?? (isSameActor(event.operatorUin, event.operatorUid, event.userUin, event.userUid)
|
||||
? 'approve'
|
||||
: 'invite'),
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_increase',
|
||||
sub_type:
|
||||
event.joinType ??
|
||||
(isSameActor(event.operatorUin, event.operatorUid, event.userUin, event.userUid)
|
||||
? 'approve'
|
||||
: 'invite'),
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupMemberLeave(ctx: ConverterContext, event: GroupMemberLeave): JsonObject {
|
||||
let subType: string;
|
||||
switch (event.leaveType) {
|
||||
case 'disband':
|
||||
subType = 'disband';
|
||||
break;
|
||||
case 'kick':
|
||||
subType = event.userUin === ctx.selfId ? 'kick_me' : 'kick';
|
||||
break;
|
||||
default:
|
||||
subType = 'leave';
|
||||
}
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_decrease',
|
||||
sub_type: subType,
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
});
|
||||
export function convertGroupMemberLeave(
|
||||
ctx: ConverterContext,
|
||||
event: GroupMemberLeave,
|
||||
): JsonObject {
|
||||
let subType: string;
|
||||
|
||||
switch (event.leaveType) {
|
||||
case 'disband':
|
||||
subType = 'disband';
|
||||
break;
|
||||
case 'kick':
|
||||
subType = event.userUin === ctx.selfId ? 'kick_me' : 'kick';
|
||||
break;
|
||||
default:
|
||||
subType = 'leave';
|
||||
}
|
||||
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_decrease',
|
||||
sub_type: subType,
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupMute(ctx: ConverterContext, event: GroupMute): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_ban',
|
||||
sub_type: event.duration > 0 ? 'ban' : 'lift_ban',
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
duration: event.duration,
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_ban',
|
||||
sub_type: event.duration > 0 ? 'ban' : 'lift_ban',
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.userUin,
|
||||
duration: event.duration,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupAdmin(ctx: ConverterContext, event: GroupAdmin): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_admin',
|
||||
sub_type: event.set ? 'set' : 'unset',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_admin',
|
||||
sub_type: event.set ? 'set' : 'unset',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertFriendRecall(ctx: ConverterContext, event: FriendRecall): JsonObject {
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
false,
|
||||
event.userUin,
|
||||
event.msgSeq,
|
||||
privateMessageEventName(event.recalledBySelf === true, false),
|
||||
event.time,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'friend_recall',
|
||||
user_id: event.userUin,
|
||||
message_id: messageId,
|
||||
});
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
false,
|
||||
event.userUin,
|
||||
event.msgSeq,
|
||||
privateMessageEventName(event.recalledBySelf === true, false),
|
||||
event.time,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'friend_recall',
|
||||
user_id: event.userUin,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupRecall(ctx: ConverterContext, event: GroupRecall): JsonObject {
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver, true, event.groupId, event.msgSeq, GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_recall',
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.authorUin,
|
||||
message_id: messageId,
|
||||
});
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
true,
|
||||
event.groupId,
|
||||
event.msgSeq,
|
||||
GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_recall',
|
||||
group_id: event.groupId,
|
||||
operator_id: event.operatorUin,
|
||||
user_id: event.authorUin,
|
||||
message_id: messageId,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertFriendPoke(ctx: ConverterContext, event: FriendPoke): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'poke',
|
||||
user_id: event.peerUin,
|
||||
sender_id: event.senderUin,
|
||||
target_id: event.targetUin,
|
||||
action: event.action,
|
||||
suffix: event.suffix,
|
||||
action_img_url: event.actionImgUrl,
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'poke',
|
||||
user_id: event.peerUin,
|
||||
sender_id: event.senderUin,
|
||||
target_id: event.targetUin,
|
||||
action: event.action,
|
||||
suffix: event.suffix,
|
||||
action_img_url: event.actionImgUrl,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupPoke(ctx: ConverterContext, event: GroupPoke): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'poke',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
target_id: event.targetUin,
|
||||
action: event.action,
|
||||
suffix: event.suffix,
|
||||
action_img_url: event.actionImgUrl,
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'poke',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
target_id: event.targetUin,
|
||||
action: event.action,
|
||||
suffix: event.suffix,
|
||||
action_img_url: event.actionImgUrl,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupEssence(ctx: ConverterContext, event: GroupEssence): JsonObject {
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver, true, event.groupId, event.msgSeq, GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'essence',
|
||||
sub_type: event.set ? 'add' : 'delete',
|
||||
group_id: event.groupId,
|
||||
user_id: event.senderUin,
|
||||
sender_id: event.senderUin,
|
||||
operator_id: event.operatorUin,
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
random: event.random,
|
||||
});
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
true,
|
||||
event.groupId,
|
||||
event.msgSeq,
|
||||
GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'essence',
|
||||
sub_type: event.set ? 'add' : 'delete',
|
||||
group_id: event.groupId,
|
||||
user_id: event.senderUin,
|
||||
sender_id: event.senderUin,
|
||||
operator_id: event.operatorUin,
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
random: event.random,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupFileUpload(ctx: ConverterContext, event: GroupFileUpload): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_upload',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
file: {
|
||||
id: event.fileId,
|
||||
name: event.fileName,
|
||||
size: event.fileSize,
|
||||
busid: event.busId,
|
||||
},
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_upload',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
file: {
|
||||
id: event.fileId,
|
||||
name: event.fileName,
|
||||
size: event.fileSize,
|
||||
busid: event.busId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function convertFriendAdd(ctx: ConverterContext, event: FriendAdd): JsonObject {
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'friend_add',
|
||||
user_id: event.userUin,
|
||||
});
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'friend_add',
|
||||
user_id: event.userUin,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupCardChange(ctx: ConverterContext, event: GroupCardChange): JsonObject {
|
||||
// Mirrors NapCat's OB11GroupCardEvent: notice_type group_card with the new and
|
||||
// old group cards.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_card',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
card_new: event.cardNew,
|
||||
card_old: event.cardOld,
|
||||
});
|
||||
// Mirrors NapCat's OB11GroupCardEvent: notice_type group_card with the new and
|
||||
// old group cards.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_card',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
card_new: event.cardNew,
|
||||
card_old: event.cardOld,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertBotOffline(ctx: ConverterContext, event: BotOffline): JsonObject {
|
||||
// Mirrors NapCat's OB11BotOfflineEvent: notice_type bot_offline with the bot's
|
||||
// own uin plus the tag/message describing why it went offline.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'bot_offline',
|
||||
user_id: event.selfUin,
|
||||
tag: event.tag,
|
||||
message: event.message,
|
||||
});
|
||||
// Mirrors NapCat's OB11BotOfflineEvent: notice_type bot_offline with the bot's
|
||||
// own uin plus the tag/message describing why it went offline.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'bot_offline',
|
||||
user_id: event.selfUin,
|
||||
tag: event.tag,
|
||||
message: event.message,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertFriendProfileLike(ctx: ConverterContext, event: FriendProfileLike): JsonObject {
|
||||
// Mirrors NapCat's OB11ProfileLikeEvent: notify/profile_like with the liker's
|
||||
// uin, nickname and like count.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'profile_like',
|
||||
operator_id: event.operatorUin,
|
||||
operator_nick: event.operatorNick,
|
||||
times: event.times,
|
||||
});
|
||||
export function convertFriendProfileLike(
|
||||
ctx: ConverterContext,
|
||||
event: FriendProfileLike,
|
||||
): JsonObject {
|
||||
// Mirrors NapCat's OB11ProfileLikeEvent: notify/profile_like with the liker's
|
||||
// uin, nickname and like count.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'profile_like',
|
||||
operator_id: event.operatorUin,
|
||||
operator_nick: event.operatorNick,
|
||||
times: event.times,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupTitleChange(ctx: ConverterContext, event: GroupTitleChange): JsonObject {
|
||||
// Mirrors NapCat's OB11GroupTitleEvent: notify/title with the recipient's uin
|
||||
// and the granted title text.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'title',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
title: event.title,
|
||||
});
|
||||
export function convertGroupTitleChange(
|
||||
ctx: ConverterContext,
|
||||
event: GroupTitleChange,
|
||||
): JsonObject {
|
||||
// Mirrors NapCat's OB11GroupTitleEvent: notify/title with the recipient's uin
|
||||
// and the granted title text.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'title',
|
||||
group_id: event.groupId,
|
||||
user_id: event.userUin,
|
||||
title: event.title,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupNameChange(ctx: ConverterContext, event: GroupNameChange): JsonObject {
|
||||
// Mirrors NapCat's OB11GroupNameEvent: notify/group_name with the operator's
|
||||
// uin as user_id and the new name in `name_new`.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'group_name',
|
||||
group_id: event.groupId,
|
||||
user_id: event.operatorUin,
|
||||
name_new: event.name,
|
||||
});
|
||||
// Mirrors NapCat's OB11GroupNameEvent: notify/group_name with the operator's
|
||||
// uin as user_id and the new name in `name_new`.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'group_name',
|
||||
group_id: event.groupId,
|
||||
user_id: event.operatorUin,
|
||||
name_new: event.name,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertFriendInputStatus(ctx: ConverterContext, event: FriendInputStatus): JsonObject {
|
||||
// Mirrors NapCat's OB11InputStatusEvent: notify/input_status with the peer's
|
||||
// uin, the raw event_type (1 = typing, 3 = recording voice) and status_text.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'input_status',
|
||||
user_id: event.userUin,
|
||||
event_type: event.eventType,
|
||||
status_text: event.statusText,
|
||||
});
|
||||
export function convertFriendInputStatus(
|
||||
ctx: ConverterContext,
|
||||
event: FriendInputStatus,
|
||||
): JsonObject {
|
||||
// Mirrors NapCat's OB11InputStatusEvent: notify/input_status with the peer's
|
||||
// uin, the raw event_type (1 = typing, 3 = recording voice) and status_text.
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'notify',
|
||||
sub_type: 'input_status',
|
||||
user_id: event.userUin,
|
||||
event_type: event.eventType,
|
||||
status_text: event.statusText,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupMsgEmojiLike(ctx: ConverterContext, event: GroupMsgEmojiLike): JsonObject {
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver, true, event.groupId, event.msgSeq, GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_msg_emoji_like',
|
||||
sub_type: event.isAdd ? 'add' : 'remove',
|
||||
group_id: event.groupId,
|
||||
user_id: event.operatorUin,
|
||||
operator_id: event.operatorUin,
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
likes: [{ emoji_id: event.emojiId, count: event.count }],
|
||||
});
|
||||
export function convertGroupMsgEmojiLike(
|
||||
ctx: ConverterContext,
|
||||
event: GroupMsgEmojiLike,
|
||||
): JsonObject {
|
||||
const messageId = applyMessageIdResolver(
|
||||
ctx.messageIdResolver,
|
||||
true,
|
||||
event.groupId,
|
||||
event.msgSeq,
|
||||
GROUP_MESSAGE_EVENT,
|
||||
);
|
||||
return notice(ctx, event, {
|
||||
notice_type: 'group_msg_emoji_like',
|
||||
sub_type: event.isAdd ? 'add' : 'remove',
|
||||
group_id: event.groupId,
|
||||
user_id: event.operatorUin,
|
||||
operator_id: event.operatorUin,
|
||||
message_id: messageId,
|
||||
message_seq: event.msgSeq,
|
||||
likes: [{ emoji_id: event.emojiId, count: event.count }],
|
||||
});
|
||||
}
|
||||
@@ -7,23 +7,23 @@ type FriendRequest = Extract<QQEventVariant, { kind: 'friend_request' }>;
|
||||
type GroupInvite = Extract<QQEventVariant, { kind: 'group_invite' }>;
|
||||
|
||||
export function convertFriendRequest(ctx: ConverterContext, event: FriendRequest): JsonObject {
|
||||
return request(ctx, event, {
|
||||
request_type: 'friend',
|
||||
user_id: event.fromUin,
|
||||
comment: event.message,
|
||||
flag: event.flag,
|
||||
});
|
||||
return request(ctx, event, {
|
||||
request_type: 'friend',
|
||||
user_id: event.fromUin,
|
||||
comment: event.message,
|
||||
flag: event.flag,
|
||||
});
|
||||
}
|
||||
|
||||
export function convertGroupInvite(ctx: ConverterContext, event: GroupInvite): JsonObject {
|
||||
const invitedId = event.invitedUin ?? 0;
|
||||
return request(ctx, event, {
|
||||
request_type: 'group',
|
||||
sub_type: event.subType || 'invite',
|
||||
group_id: event.groupId,
|
||||
user_id: event.fromUin,
|
||||
...(invitedId > 0 ? { invited_id: invitedId } : {}),
|
||||
comment: event.message,
|
||||
flag: event.flag,
|
||||
});
|
||||
const invitedId = event.invitedUin ?? 0;
|
||||
return request(ctx, event, {
|
||||
request_type: 'group',
|
||||
sub_type: event.subType || 'invite',
|
||||
group_id: event.groupId,
|
||||
user_id: event.fromUin,
|
||||
...(invitedId > 0 ? { invited_id: invitedId } : {}),
|
||||
comment: event.message,
|
||||
flag: event.flag,
|
||||
});
|
||||
}
|
||||
@@ -9,62 +9,80 @@ import { attachMessageMedia } from '../message-media';
|
||||
const log = createLogger('OneBot');
|
||||
|
||||
function toSegmentContext(
|
||||
ctx: ConverterContext,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
ctx: ConverterContext,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
): ToSegmentContext {
|
||||
return {
|
||||
isGroup,
|
||||
sessionId,
|
||||
selfId: ctx.selfId,
|
||||
imageUrlResolver: ctx.imageUrlResolver,
|
||||
mediaUrlResolver: ctx.mediaUrlResolver,
|
||||
messageIdResolver: ctx.messageIdResolver,
|
||||
mediaSegmentSink: ctx.mediaSegmentSink,
|
||||
};
|
||||
return {
|
||||
isGroup,
|
||||
sessionId,
|
||||
selfId: ctx.selfId,
|
||||
imageUrlResolver: ctx.imageUrlResolver,
|
||||
mediaUrlResolver: ctx.mediaUrlResolver,
|
||||
messageIdResolver: ctx.messageIdResolver,
|
||||
mediaSegmentSink: ctx.mediaSegmentSink,
|
||||
};
|
||||
}
|
||||
|
||||
export async function elementsToOneBotSegments(
|
||||
ctx: ConverterContext,
|
||||
elements: MessageElement[],
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
ctx: ConverterContext,
|
||||
elements: MessageElement[],
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
): Promise<JsonArray> {
|
||||
const segmentCtx = toSegmentContext(ctx, isGroup, sessionId);
|
||||
const result: JsonArray = [];
|
||||
for (const element of elements) {
|
||||
let segment: JsonObject;
|
||||
// One malformed element shouldn't drop the whole message — skip it (with a
|
||||
// breadcrumb) and keep converting the rest.
|
||||
try {
|
||||
segment = await elementToSegment(element, { ...segmentCtx, mediaSegmentSink: null });
|
||||
} catch (err) {
|
||||
log.warn('segment convert skipped type=%s (%s)', element.type,
|
||||
err instanceof Error ? err.message : String(err));
|
||||
continue;
|
||||
const segmentCtx = toSegmentContext(ctx, isGroup, sessionId);
|
||||
const result: JsonArray = [];
|
||||
|
||||
for (const element of elements) {
|
||||
let segment: JsonObject;
|
||||
|
||||
// One malformed element shouldn't drop the whole message — skip it (with a
|
||||
// breadcrumb) and keep converting the rest.
|
||||
try {
|
||||
segment = await elementToSegment(element, { ...segmentCtx, mediaSegmentSink: null });
|
||||
} catch (err) {
|
||||
log.warn(
|
||||
'segment convert skipped type=%s (%s)',
|
||||
element.type,
|
||||
err instanceof Error ? err.message : String(err),
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Persistence failures must propagate, not masquerade as bad wire elements.
|
||||
attachMessageMedia(segment, element);
|
||||
|
||||
if (element.type === 'image' || element.type === 'record' || element.type === 'video') {
|
||||
ctx.mediaSegmentSink?.(
|
||||
element.type,
|
||||
element,
|
||||
segment.data as JsonObject,
|
||||
isGroup,
|
||||
sessionId,
|
||||
);
|
||||
}
|
||||
|
||||
result.push(segment);
|
||||
|
||||
if (element.type === 'markdown' && element.text) {
|
||||
result.push({ type: 'text', data: { text: element.text } });
|
||||
}
|
||||
}
|
||||
// Persistence failures must propagate, not masquerade as bad wire elements.
|
||||
attachMessageMedia(segment, element);
|
||||
if (element.type === 'image' || element.type === 'record' || element.type === 'video') {
|
||||
ctx.mediaSegmentSink?.(element.type, element, segment.data as JsonObject, isGroup, sessionId);
|
||||
}
|
||||
result.push(segment);
|
||||
if (element.type === 'markdown' && element.text) {
|
||||
result.push({ type: 'text', data: { text: element.text } });
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function elementToSegment(
|
||||
element: MessageElement,
|
||||
ctx: ToSegmentContext,
|
||||
element: MessageElement,
|
||||
ctx: ToSegmentContext,
|
||||
): Promise<JsonObject> {
|
||||
// S 收·转:按 element.type 查 codec 表;缺条目则走 default 透传(保持原兜底)。
|
||||
const codec = getElementCodec(element.type);
|
||||
if (codec?.toSegment) {
|
||||
return codec.toSegment(element, ctx);
|
||||
}
|
||||
log.warn('segment convert fallback type=%s reason=no receive-side codec', element.type);
|
||||
return { type: element.type, data: {} };
|
||||
// S 收·转:按 element.type 查 codec 表;缺条目则走 default 透传(保持原兜底)。
|
||||
const codec = getElementCodec(element.type);
|
||||
|
||||
if (codec?.toSegment) {
|
||||
return codec.toSegment(element, ctx);
|
||||
}
|
||||
|
||||
log.warn('segment convert fallback type=%s reason=no receive-side codec', element.type);
|
||||
return { type: element.type, data: {} };
|
||||
}
|
||||
@@ -3,52 +3,65 @@ import type { MessageIdResolver } from './index';
|
||||
import type { MessageElement } from '@snowluma/protocol/events';
|
||||
|
||||
export function parseSelfId(instanceUin: string): number {
|
||||
const parsed = Number.parseInt(instanceUin, 10);
|
||||
return Number.isNaN(parsed) ? 0 : parsed;
|
||||
const parsed = Number.parseInt(instanceUin, 10);
|
||||
return Number.isNaN(parsed) ? 0 : parsed;
|
||||
}
|
||||
|
||||
export function isSameActor(
|
||||
leftUin: number,
|
||||
leftUid: string | undefined,
|
||||
rightUin: number,
|
||||
rightUid: string | undefined,
|
||||
leftUin: number,
|
||||
leftUid: string | undefined,
|
||||
rightUin: number,
|
||||
rightUid: string | undefined,
|
||||
): boolean {
|
||||
if (leftUin > 0 && rightUin > 0) return leftUin === rightUin;
|
||||
return Boolean(leftUid) && leftUid === rightUid;
|
||||
if (leftUin > 0 && rightUin > 0) {
|
||||
return leftUin === rightUin;
|
||||
}
|
||||
|
||||
return Boolean(leftUid) && leftUid === rightUid;
|
||||
}
|
||||
|
||||
export function applyMessageIdResolver(
|
||||
resolver: MessageIdResolver | null,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
sequence: number,
|
||||
eventName: string,
|
||||
timestamp?: number,
|
||||
resolver: MessageIdResolver | null,
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
sequence: number,
|
||||
eventName: string,
|
||||
timestamp?: number,
|
||||
): number {
|
||||
if (resolver) {
|
||||
const resolved = resolver(isGroup, sessionId, sequence, eventName, timestamp);
|
||||
if (Number.isInteger(resolved) && resolved !== 0) return resolved;
|
||||
}
|
||||
const seq = Math.trunc(sequence);
|
||||
return seq === 0 ? 0 : seq;
|
||||
if (resolver) {
|
||||
const resolved = resolver(isGroup, sessionId, sequence, eventName, timestamp);
|
||||
|
||||
if (Number.isInteger(resolved) && resolved !== 0) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
|
||||
const seq = Math.trunc(sequence);
|
||||
return seq === 0 ? 0 : seq;
|
||||
}
|
||||
|
||||
export function resolveReplyId(
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
sequence: number,
|
||||
resolver?: MessageIdResolver | null,
|
||||
eventName = isGroup ? GROUP_MESSAGE_EVENT : PRIVATE_MESSAGE_EVENT,
|
||||
timestamp?: number,
|
||||
replyElements?: readonly MessageElement[],
|
||||
isGroup: boolean,
|
||||
sessionId: number,
|
||||
sequence: number,
|
||||
resolver?: MessageIdResolver | null,
|
||||
eventName = isGroup ? GROUP_MESSAGE_EVENT : PRIVATE_MESSAGE_EVENT,
|
||||
timestamp?: number,
|
||||
replyElements?: readonly MessageElement[],
|
||||
): number {
|
||||
const seq = Math.trunc(sequence);
|
||||
if (seq === 0) return 0;
|
||||
const seq = Math.trunc(sequence);
|
||||
|
||||
if (resolver) {
|
||||
const resolved = resolver(isGroup, sessionId, seq, eventName, timestamp, replyElements);
|
||||
if (Number.isInteger(resolved) && resolved !== 0) return resolved;
|
||||
}
|
||||
if (seq === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return seq;
|
||||
if (resolver) {
|
||||
const resolved = resolver(isGroup, sessionId, seq, eventName, timestamp, replyElements);
|
||||
|
||||
if (Number.isInteger(resolved) && resolved !== 0) {
|
||||
return resolved;
|
||||
}
|
||||
}
|
||||
|
||||
return seq;
|
||||
}
|
||||
Reference in new issue
Block a user