Fix merge conflict and remove one group avatar implement
This commit is contained in:
commit
16bdf1be1e
111 files changed
+6830
-2916
No files matched your search
@@ -36,7 +36,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const times = asNumber(params.times) || 1;
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
await ctx.sendLike(userId, times);
|
||||
await ctx.bridge.sendLike(userId, times);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -94,9 +94,9 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const essenceDataAll = await ctx.getGroupEssenceAll(groupId);
|
||||
const essenceDataAll = await ctx.bridge.getGroupEssenceAll(groupId);
|
||||
|
||||
const allMsgs = essenceDataAll.flatMap(res => res.data?.msg_list || []);
|
||||
const allMsgs = essenceDataAll.flatMap((res: any) => res.data?.msg_list || []);
|
||||
|
||||
return okResponse(allMsgs);
|
||||
} catch (e) {
|
||||
@@ -125,7 +125,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id does not match message session');
|
||||
}
|
||||
|
||||
await ctx.setGroupReaction(meta.targetId, meta.sequence, code, isSet);
|
||||
await ctx.bridge.setGroupReaction(meta.targetId, meta.sequence, code, isSet);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -168,7 +168,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
|
||||
|
||||
await ctx.markGroupMsgAsRead(groupId, meta.sequence);
|
||||
await ctx.bridge.markGroupMsgAsRead(groupId, meta.sequence);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -191,7 +191,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
|
||||
|
||||
await ctx.markPrivateMsgAsRead(userId, meta.sequence);
|
||||
await ctx.bridge.markPrivateMsgAsRead(userId, meta.sequence);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -211,9 +211,9 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
|
||||
if (meta.isGroup) {
|
||||
await ctx.markGroupMsgAsRead(targetId, meta.sequence);
|
||||
await ctx.bridge.markGroupMsgAsRead(targetId, meta.sequence);
|
||||
} else {
|
||||
await ctx.markPrivateMsgAsRead(targetId, meta.sequence);
|
||||
await ctx.bridge.markPrivateMsgAsRead(targetId, meta.sequence);
|
||||
}
|
||||
return okResponse();
|
||||
});
|
||||
@@ -221,12 +221,16 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
// --- RKey ---
|
||||
|
||||
h.registerAction('get_rkey', async () => {
|
||||
const handleGetRkey = async () => {
|
||||
if (ctx.getDownloadRKeys) {
|
||||
return okResponse(await ctx.getDownloadRKeys());
|
||||
}
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
});
|
||||
};
|
||||
h.registerAction('get_rkey', handleGetRkey);
|
||||
// napcat exposes the same payload under `nc_get_rkey`; mirror the alias
|
||||
// so clients that follow napcat's docs work out-of-the-box.
|
||||
h.registerAction('nc_get_rkey', handleGetRkey);
|
||||
|
||||
// --- OCR stubs ---
|
||||
|
||||
@@ -258,7 +262,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
confirm_required: params.confirm_required !== undefined ? Number(params.confirm_required) : 1,
|
||||
};
|
||||
|
||||
await ctx.sendGroupNotice(groupId, content, options);
|
||||
await ctx.bridge.sendGroupNotice(groupId, content, options);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -271,7 +275,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const notices = await ctx.getGroupNotice(groupId);
|
||||
const notices = await ctx.bridge.getGroupNotice(groupId);
|
||||
return okResponse(notices);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -288,7 +292,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const success = await ctx.deleteGroupNotice(groupId, fid);
|
||||
const success = await ctx.bridge.deleteGroupNotice(groupId, fid);
|
||||
if (success) {
|
||||
return okResponse();
|
||||
} else {
|
||||
@@ -427,7 +431,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const cookies = await ctx.getCookiesStr(domain);
|
||||
const cookies = await ctx.bridge.getCookiesStr(domain);
|
||||
return okResponse({ cookies });
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -437,7 +441,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_csrf_token', async () => {
|
||||
|
||||
try {
|
||||
const token = await ctx.getCsrfToken();
|
||||
const token = await ctx.bridge.getCsrfToken();
|
||||
return okResponse({ token });
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -449,7 +453,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const creds = await ctx.getCredentials(domain);
|
||||
const creds = await ctx.bridge.getCredentials(domain);
|
||||
return okResponse(creds);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -480,7 +484,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const remark = asString(params.remark) ?? '';
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
await ctx.setFriendRemark(userId, remark);
|
||||
await ctx.bridge.setFriendRemark(userId, remark);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -488,7 +492,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const remark = asString(params.remark) ?? '';
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.setGroupRemark(groupId, remark);
|
||||
await ctx.bridge.setGroupRemark(groupId, remark);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -570,7 +574,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.setProfile(nickname, personalNote);
|
||||
await ctx.bridge.setProfile(nickname, personalNote);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -590,17 +594,81 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.setOnlineStatus(status, extStatus, batteryStatus);
|
||||
await ctx.bridge.setOnlineStatus(status, extStatus, batteryStatus);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('get_group_ignored_notifies', async () => {
|
||||
return okResponse([]);
|
||||
// DIY status — same wire packet as set_online_status, only the
|
||||
// customExt sub-message is populated and status/extStatus are forced
|
||||
// to the QQ-defined "I have a custom status" values (10 / 2000).
|
||||
// face_id / face_type accept either number or numeric string (napcat
|
||||
// parity); wording is the human-readable text shown next to the icon.
|
||||
h.registerAction('set_diy_online_status', async (params) => {
|
||||
const faceId = asNumber(params.face_id);
|
||||
const faceType = asNumber(params.face_type) || 1;
|
||||
const wording = asString(params.wording);
|
||||
if (!faceId) return failedResponse(RETCODE.BAD_REQUEST, 'face_id is required');
|
||||
try {
|
||||
await ctx.bridge.setDiyOnlineStatus(faceId, wording, faceType);
|
||||
return okResponse();
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
});
|
||||
|
||||
// Filtered (机器人/被忽略) group join requests. SnowLuma already
|
||||
// implements the underlying oidb 0x10c8_2 fetch via fetchGroupRequests;
|
||||
// these three actions just rename / project the same data for the
|
||||
// OneBot dialects clients use in the wild.
|
||||
const fetchFilteredGroupRequests = async () => {
|
||||
try {
|
||||
return await ctx.bridge.fetchGroupRequests(true);
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
h.registerAction('get_group_ignored_notifies', async () => {
|
||||
const reqs = await fetchFilteredGroupRequests();
|
||||
return okResponse(reqs.map((r) => ({
|
||||
group_id: r.groupId,
|
||||
group_name: r.groupName,
|
||||
request_id: r.sequence,
|
||||
requester_uin: r.targetUin,
|
||||
requester_nick: r.targetName,
|
||||
message: r.comment,
|
||||
checked: r.state !== 1,
|
||||
actor: r.operatorUin,
|
||||
invitor_uin: r.invitorUin,
|
||||
invitor_nick: r.invitorName,
|
||||
flag: `${r.eventType}:${r.groupId}:${r.targetUid}:filtered`,
|
||||
})));
|
||||
});
|
||||
|
||||
// napcat name for the subset of ignored notifies that are join requests
|
||||
// (notify type==7). We map every entry that flowed through filtered
|
||||
// 0x10c8_2 into napcat's shape — eventType already encodes the request
|
||||
// category in our pipeline.
|
||||
h.registerAction('get_group_ignore_add_request', async () => {
|
||||
const reqs = await fetchFilteredGroupRequests();
|
||||
return okResponse(reqs.map((r) => ({
|
||||
request_id: r.sequence,
|
||||
invitor_uin: r.invitorUin,
|
||||
invitor_nick: r.invitorName,
|
||||
group_id: r.groupId,
|
||||
message: r.comment,
|
||||
group_name: r.groupName,
|
||||
checked: r.state !== 1,
|
||||
actor: r.operatorUin,
|
||||
requester_nick: r.targetName,
|
||||
})));
|
||||
});
|
||||
|
||||
// get_group_shut_list lives behind an oidb we don't yet wrap; honour
|
||||
// the napcat contract (empty list) so callers don't blow up.
|
||||
h.registerAction('get_group_shut_list', async () => {
|
||||
return okResponse([]);
|
||||
});
|
||||
@@ -653,7 +721,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('fetch_custom_face', async (params) => {
|
||||
const count = asNumber(params.count) || 10;
|
||||
try {
|
||||
const urls = await ctx.fetchCustomFace(count);
|
||||
const urls = await ctx.bridge.fetchCustomFace(count);
|
||||
return okResponse(urls);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -667,7 +735,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
try {
|
||||
const meta = ctx.getMessageMeta(messageId);
|
||||
if (!meta?.isGroup || !meta?.sequence) return failedResponse(RETCODE.BAD_REQUEST, 'message not found or not a group message');
|
||||
const result = await ctx.getEmojiLikes(meta.targetId, meta.sequence, emojiId);
|
||||
const result = await ctx.bridge.getEmojiLikes(meta.targetId, meta.sequence, emojiId);
|
||||
return okResponse({ emoji_like_list: result.users.map(u => ({ user_id: String(u.uin), nick_name: '' })) });
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -684,7 +752,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
try {
|
||||
const meta = ctx.getMessageMeta(messageId);
|
||||
if (!meta?.isGroup || !meta?.sequence) return failedResponse(RETCODE.BAD_REQUEST, 'message not found or not a group message');
|
||||
const result = await ctx.getEmojiLikes(meta.targetId, meta.sequence, emojiId, emojiType, count, cookie);
|
||||
const result = await ctx.bridge.getEmojiLikes(meta.targetId, meta.sequence, emojiId, emojiType, count, cookie);
|
||||
return okResponse({
|
||||
result: 0,
|
||||
errMsg: '',
|
||||
@@ -733,7 +801,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const data = await ctx.getGroupAtAllRemain(groupId);
|
||||
const data = await ctx.bridge.getGroupAtAllRemain(groupId);
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -743,7 +811,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_unidirectional_friend_list', async () => {
|
||||
|
||||
try {
|
||||
const data = await ctx.getUnidirectionalFriendList();
|
||||
const data = await ctx.bridge.getUnidirectionalFriendList();
|
||||
return okResponse(data);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -759,7 +827,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.setSelfLongNick(longNick);
|
||||
await ctx.bridge.setSelfLongNick(longNick);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -780,7 +848,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.setAvatar(file);
|
||||
await ctx.bridge.setAvatar(file);
|
||||
return okResponse();
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -802,7 +870,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.setInputStatus(userId, eventType);
|
||||
await ctx.bridge.setInputStatus(userId, eventType);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -820,7 +888,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const translated = await ctx.translateEn2Zh(words);
|
||||
const translated = await ctx.bridge.translateEn2Zh(words);
|
||||
return okResponse({ words: translated });
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -828,11 +896,11 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
});
|
||||
|
||||
h.registerAction('get_clientkey', async () => {
|
||||
const clientKeyInfo = await ctx.forceFetchClientKey();
|
||||
const clientKeyInfo = await ctx.bridge.forceFetchClientKey();
|
||||
if (!clientKeyInfo.clientKey) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'get clientkey error');
|
||||
}
|
||||
return okResponse(clientKeyInfo);
|
||||
return okResponse({ ...clientKeyInfo });
|
||||
});
|
||||
|
||||
h.registerAction('get_mini_app_ark', async (params) => {
|
||||
@@ -844,7 +912,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const data = await ctx.getMiniAppArk(
|
||||
const data = await ctx.bridge.getMiniAppArk(
|
||||
String(type),
|
||||
String(title),
|
||||
String(desc),
|
||||
@@ -870,7 +938,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
const data = await ctx.clickInlineKeyboardButton(
|
||||
const data = await ctx.bridge.clickInlineKeyboardButton(
|
||||
groupId,
|
||||
botAppid,
|
||||
String(buttonId),
|
||||
@@ -892,7 +960,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
|
||||
try {
|
||||
await ctx.sendGroupSign(groupId);
|
||||
await ctx.bridge.sendGroupSign(groupId);
|
||||
return okResponse({});
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, String(e));
|
||||
@@ -934,9 +1002,170 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
});
|
||||
|
||||
h.registerAction('.send_packet', async () => {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
// --- Raw packet escape hatch (napcat parity) ---
|
||||
//
|
||||
// napcat exposes both names; the dot-prefix variant is the original
|
||||
// gocqhttp-era backdoor, the no-prefix one is the modern API. They do
|
||||
// the same thing in SnowLuma: encode hex → Bridge.sendRawPacket → hex.
|
||||
const handleSendPacket = async (params: import('../types').JsonObject) => {
|
||||
const cmd = asString(params.cmd);
|
||||
const dataHex = asString(params.data);
|
||||
const rsp = asBoolean(params.rsp, true);
|
||||
if (!cmd) return failedResponse(RETCODE.BAD_REQUEST, 'cmd is required');
|
||||
if (!/^[0-9a-fA-F]*$/.test(dataHex) || dataHex.length % 2 !== 0) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'data must be a hex string of even length');
|
||||
}
|
||||
try {
|
||||
const body = hexToBytes(dataHex);
|
||||
const result = await ctx.bridge.sendRawPacket(cmd, body);
|
||||
if (!result.success) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, result.errorMessage || 'send failed');
|
||||
}
|
||||
if (!rsp) return okResponse(null);
|
||||
const respHex = result.responseData ? bytesToHex(result.responseData) : '';
|
||||
return okResponse(respHex);
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
};
|
||||
h.registerAction('send_packet', handleSendPacket);
|
||||
h.registerAction('.send_packet', handleSendPacket);
|
||||
|
||||
// --- Bot lifecycle (napcat parity) ---
|
||||
|
||||
h.registerAction('bot_exit', async () => {
|
||||
// Defer so the OK response actually flushes before the process dies.
|
||||
setTimeout(() => process.exit(0), 50);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
// SnowLuma has no separate packet-backend process (napcat's packet
|
||||
// service runs out-of-process and can fail independently). Always
|
||||
// report healthy.
|
||||
h.registerAction('nc_get_packet_status', async () => {
|
||||
return okResponse(null);
|
||||
});
|
||||
|
||||
// napcat exposes `delete_group_folder`; SnowLuma's existing
|
||||
// `delete_group_file_folder` is the same operation. Alias so clients
|
||||
// following napcat docs work without rewriting payloads.
|
||||
h.registerAction('delete_group_folder', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const folderId = asString(params.folder_id);
|
||||
if (!groupId || !folderId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and folder_id are required');
|
||||
}
|
||||
await ctx.bridge.deleteGroupFileFolder(groupId, folderId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
// --- Group todo (oidb 0xF90) ---
|
||||
//
|
||||
// The three subcommands share an identical payload (group + msgSeq);
|
||||
// we extract once and dispatch by action name. msgSeq comes from the
|
||||
// message metadata cache (set/complete/cancel always target a real
|
||||
// message the bot has seen).
|
||||
type GroupTodoOp = (groupId: number, msgSeq: bigint | number | string) => Promise<void>;
|
||||
const handleGroupTodo = (op: GroupTodoOp) => async (params: import('../types').JsonObject) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const messageId = asNumber(params.message_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!messageId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
const meta = ctx.getMessageMeta(messageId);
|
||||
if (!meta) return failedResponse(RETCODE.ACTION_FAILED, 'message not found');
|
||||
if (!meta.isGroup || meta.targetId !== groupId) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'message does not belong to this group');
|
||||
}
|
||||
try {
|
||||
await op(groupId, BigInt(meta.sequence));
|
||||
return okResponse();
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
};
|
||||
h.registerAction('set_group_todo', handleGroupTodo((g, s) => ctx.bridge.setGroupTodo(g, s)));
|
||||
h.registerAction('complete_group_todo', handleGroupTodo((g, s) => ctx.bridge.completeGroupTodo(g, s)));
|
||||
h.registerAction('cancel_group_todo', handleGroupTodo((g, s) => ctx.bridge.cancelGroupTodo(g, s)));
|
||||
|
||||
// --- User online/ext status (napcat: nc_get_user_status) ---
|
||||
|
||||
h.registerAction('nc_get_user_status', async (params) => {
|
||||
const userId = asNumber(params.user_id);
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
const status = await ctx.bridge.getStrangerStatus(userId);
|
||||
if (!status) return failedResponse(RETCODE.ACTION_FAILED, 'failed to fetch user status');
|
||||
return okResponse(status);
|
||||
});
|
||||
|
||||
// --- AI voice (oidb 0x929D / 0x929B) ---
|
||||
|
||||
h.registerAction('get_ai_characters', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const chatType = asNumber(params.chat_type) || 1;
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
try {
|
||||
const list = await ctx.bridge.fetchAiVoiceList(groupId, chatType);
|
||||
return okResponse(list.map((cat) => ({
|
||||
type: cat.category,
|
||||
characters: cat.voices.map((v) => ({
|
||||
character_id: v.voiceId,
|
||||
character_name: v.voiceDisplayName,
|
||||
preview_url: v.voiceExampleUrl,
|
||||
})),
|
||||
})));
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
});
|
||||
|
||||
h.registerAction('get_ai_record', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const character = asString(params.character);
|
||||
const text = asString(params.text);
|
||||
const chatType = asNumber(params.chat_type) || 1;
|
||||
if (!groupId || !character || !text) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, character and text are required');
|
||||
}
|
||||
try {
|
||||
const node = await ctx.bridge.fetchAiVoice(groupId, character, text, chatType);
|
||||
const url = await ctx.bridge.fetchGroupPttUrlByNode(groupId, node);
|
||||
return okResponse(url);
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
});
|
||||
|
||||
// napcat's send_group_ai_record is a side-effect-only call: invoking
|
||||
// fetchAiVoice publishes the voice into the group; the returned
|
||||
// message_id is always 0 because the oidb call doesn't echo one back.
|
||||
h.registerAction('send_group_ai_record', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const character = asString(params.character);
|
||||
const text = asString(params.text);
|
||||
const chatType = asNumber(params.chat_type) || 1;
|
||||
if (!groupId || !character || !text) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, character and text are required');
|
||||
}
|
||||
try {
|
||||
await ctx.bridge.fetchAiVoice(groupId, character, text, chatType);
|
||||
return okResponse({ message_id: 0 });
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function hexToBytes(hex: string): Uint8Array {
|
||||
const out = new Uint8Array(hex.length / 2);
|
||||
for (let i = 0; i < out.length; i++) {
|
||||
out[i] = parseInt(hex.substr(i * 2, 2), 16);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function bytesToHex(buf: Buffer | Uint8Array): string {
|
||||
const arr = buf instanceof Buffer ? buf : Buffer.from(buf);
|
||||
return arr.toString('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -42,14 +42,14 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const addType = asNumber(params.add_type);
|
||||
if (!groupId || addType === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and add_type are required');
|
||||
await ctx.setGroupAddOption(groupId, addType);
|
||||
await ctx.bridge.setGroupAddOption(groupId, addType);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
h.registerAction('set_group_search', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.setGroupSearch(groupId);
|
||||
await ctx.bridge.setGroupSearch(groupId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -58,7 +58,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const enable = asBoolean(params.enable, true);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.setGroupAdmin(groupId, userId, enable);
|
||||
await ctx.bridge.setGroupAdmin(groupId, userId, enable);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -67,7 +67,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const card = asString(params.card);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.setGroupCard(groupId, userId, card);
|
||||
await ctx.bridge.setGroupCard(groupId, userId, card);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -75,7 +75,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const name = asString(params.group_name);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
await ctx.setGroupName(groupId, name);
|
||||
await ctx.bridge.setGroupName(groupId, name);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const title = asString(params.special_title);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
await ctx.setGroupSpecialTitle(groupId, userId, title);
|
||||
await ctx.bridge.setGroupSpecialTitle(groupId, userId, title);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -103,11 +103,20 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
// Highway upload with cmdId 3000 + GroupAvatarExtra (Lagrange protocol).
|
||||
// `file` accepts everything bridge.setGroupAvatar's underlying
|
||||
// loadBinarySource handles: local paths, file:// URLs, http(s) URLs,
|
||||
// and base64:// data URIs — same surface as set_qq_avatar.
|
||||
h.registerAction('set_group_portrait', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const file = asString(params.file);
|
||||
if (!groupId || !file) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file are required');
|
||||
await ctx.setGroupAvatar(groupId, file);
|
||||
return okResponse();
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!file) return failedResponse(RETCODE.BAD_REQUEST, 'file is required');
|
||||
try {
|
||||
await ctx.bridge.setGroupAvatar(groupId, file);
|
||||
return okResponse();
|
||||
} catch (err) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, err instanceof Error ? err.message : String(err));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file_id are required');
|
||||
}
|
||||
await ctx.deleteGroupFile(groupId, fileId);
|
||||
await ctx.bridge.deleteGroupFile(groupId, fileId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -70,7 +70,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId || !parentDirectory || !targetDirectory) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, file_id, parent_directory and target_directory are required');
|
||||
}
|
||||
await ctx.moveGroupFile(groupId, fileId, parentDirectory, targetDirectory);
|
||||
await ctx.bridge.moveGroupFile(groupId, fileId, parentDirectory, targetDirectory);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -91,7 +91,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !folderId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and folder_id are required');
|
||||
}
|
||||
await ctx.deleteGroupFileFolder(groupId, folderId);
|
||||
await ctx.bridge.deleteGroupFileFolder(groupId, folderId);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -102,7 +102,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !folderId || !newName) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id, folder_id and new_folder_name are required');
|
||||
}
|
||||
await ctx.renameGroupFileFolder(groupId, folderId, newName);
|
||||
await ctx.bridge.renameGroupFileFolder(groupId, folderId, newName);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
|
||||
try {
|
||||
const honorInfo = await ctx.getGroupHonorInfo(groupId, typeStr as WebHonorType);
|
||||
const honorInfo = await ctx.bridge.getGroupHonorInfo(groupId, typeStr as WebHonorType);
|
||||
return okResponse(honorInfo);
|
||||
} catch (e) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, `failed to get group honor info: ${(e as Error).message}`);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { JsonObject, JsonValue, MessageMeta } from './types';
|
||||
import type { ForwardPreviewMeta } from './modules/message-actions';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import { RETCODE, failedResponse } from './types';
|
||||
|
||||
import { register as registerInfo } from './actions/info';
|
||||
@@ -13,7 +14,7 @@ import { register as registerExtended } from './actions/extended';
|
||||
import { register as registerGroupAlbum } from './actions/group-album';
|
||||
|
||||
import { WebHonorType } from '@/bridge/web/group-honor';
|
||||
// import {ClientKeyInfo} from "@/bridge/bridge";
|
||||
import { ClientKeyInfo } from '@/bridge/bridge';
|
||||
|
||||
export interface MessageSendResult {
|
||||
messageId: number;
|
||||
@@ -32,6 +33,14 @@ export interface GroupEssenceMsgRet {
|
||||
}
|
||||
|
||||
export interface ApiActionContext {
|
||||
/**
|
||||
* Direct access to the BridgeInterface. Use for actions that are pure
|
||||
* 1:1 calls to a Bridge method — no rename, no default args, no
|
||||
* composition with messageStore / mediaStore. When translation IS
|
||||
* needed, route through the named adapters declared below instead.
|
||||
*/
|
||||
bridge: BridgeInterface;
|
||||
|
||||
getLoginInfo: () => { userId: number; nickname: string };
|
||||
isOnline: () => boolean;
|
||||
getMessage: (messageId: number) => JsonObject | null;
|
||||
@@ -48,57 +57,39 @@ export interface ApiActionContext {
|
||||
getGroupMemberList: (groupId: number, noCache?: boolean) => Promise<JsonObject[]>;
|
||||
getGroupMemberInfo: (groupId: number, userId: number, noCache?: boolean) => Promise<JsonObject | null>;
|
||||
getStrangerInfo: (userId: number) => Promise<JsonObject | null>;
|
||||
// Group admin
|
||||
// Group admin (adapters: rename Bridge methods to OneBot vocabulary)
|
||||
setGroupKick: (groupId: number, userId: number, rejectAdd: boolean) => Promise<void>;
|
||||
setGroupKickMembers: (groupId: number, userIds: number[], rejectAdd: boolean) => Promise<void>;
|
||||
setGroupBan: (groupId: number, userId: number, duration: number) => Promise<void>;
|
||||
setGroupWholeBan: (groupId: number, enable: boolean) => Promise<void>;
|
||||
setGroupAddOption: (groupId: number, addType: number) => Promise<void>;
|
||||
setGroupSearch: (groupId: number) => Promise<void>;
|
||||
setGroupAdmin: (groupId: number, userId: number, enable: boolean) => Promise<void>;
|
||||
setGroupCard: (groupId: number, userId: number, card: string) => Promise<void>;
|
||||
setGroupName: (groupId: number, name: string) => Promise<void>;
|
||||
setGroupLeave: (groupId: number) => Promise<void>;
|
||||
setGroupSpecialTitle: (groupId: number, userId: number, title: string) => Promise<void>;
|
||||
getGroupAtAllRemain: (groupId: number) => Promise<any>;
|
||||
// Group file
|
||||
// Group file (adapters: field extraction + Bridge name translation)
|
||||
uploadGroupFile: (groupId: number, file: string, name?: string, folderId?: string, uploadFile?: boolean) => Promise<string | null>;
|
||||
uploadPrivateFile: (userId: number, file: string, name?: string, uploadFile?: boolean) => Promise<string | null>;
|
||||
getGroupFileUrl: (groupId: number, fileId: string, busId?: number) => Promise<string>;
|
||||
getGroupFiles: (groupId: number, folderId?: string) => Promise<JsonObject>;
|
||||
deleteGroupFile: (groupId: number, fileId: string) => Promise<void>;
|
||||
moveGroupFile: (groupId: number, fileId: string, parentDirectory: string, targetDirectory: string) => Promise<void>;
|
||||
createGroupFileFolder: (groupId: number, name: string, parentId?: string) => Promise<void>;
|
||||
deleteGroupFileFolder: (groupId: number, folderId: string) => Promise<void>;
|
||||
renameGroupFileFolder: (groupId: number, folderId: string, newName: string) => Promise<void>;
|
||||
getPrivateFileUrl: (userId: number, fileId: string, fileHash: string) => Promise<string>;
|
||||
// Requests
|
||||
getGroupFileCount: (groupId: number) => Promise<{ fileCount: number; maxCount: number }>;
|
||||
// Requests (adapters: rename to OneBot vocabulary)
|
||||
handleFriendRequest: (flag: string, approve: boolean) => Promise<void>;
|
||||
handleGroupRequest: (flag: string, subType: string, approve: boolean, reason: string) => Promise<void>;
|
||||
// Extended
|
||||
sendLike: (userId: number, times: number) => Promise<void>;
|
||||
// Pokes (adapters: flatten isGroup into bridge.sendPoke signature)
|
||||
sendFriendPoke: (userId: number, targetId?: number) => Promise<void>;
|
||||
sendGroupPoke: (groupId: number, userId: number) => Promise<void>;
|
||||
// Essence (adapter: bakes the set/unset boolean)
|
||||
setEssenceMsg: (messageId: number) => Promise<void>;
|
||||
deleteEssenceMsg: (messageId: number) => Promise<void>;
|
||||
forceFetchClientKey: () => Promise<{clientKey: string, keyIndex: string, expireTime: string}>;
|
||||
setOnlineStatus: (status: number, extStatus?: number, batteryStatus?: number) => Promise<void>;
|
||||
setProfile: (nickname?: string, personalNote?: string) => Promise<void>;
|
||||
getUnidirectionalFriendList: () => Promise<any>;
|
||||
setSelfLongNick: (longNick: string) => Promise<void>;
|
||||
setInputStatus: (userId: number, eventType: number) => Promise<void>;
|
||||
translateEn2Zh: (words: string[]) => Promise<string[]>;
|
||||
getMiniAppArk: (type: string, title: string, desc: string, picUrl: string, jumpUrl: string) => Promise<any>;
|
||||
clickInlineKeyboardButton: (groupId: number, botAppid: number, buttonId: string, callbackData: string, msgSeq: number) => Promise<any>;
|
||||
sendGroupSign: (groupId: number) => Promise<void>;
|
||||
// New context methods
|
||||
setGroupReaction: (groupId: number, sequence: number, code: string, isSet: boolean) => Promise<void>;
|
||||
// Profile reads with OneBot-specific default args
|
||||
getProfileLike: (userId?: number, start?: number, limit?: number) => Promise<any>;
|
||||
getGroupEssence: (groupId: number, pageStart?: number, pageLimit?: number) => Promise<GroupEssenceMsgRet>;
|
||||
// Friend deletion (adapter: rename + force-boolean)
|
||||
handleDeleteFriend: (userId: number, block?: boolean) => Promise<void>;
|
||||
// Module wrappers / multi-dep compositions
|
||||
getGroupMsgHistory: (groupId: number, messageId?: number, count?: number) => Promise<JsonObject[]>;
|
||||
getFriendMsgHistory: (userId: number, messageId?: number, count?: number) => Promise<JsonObject[]>;
|
||||
handleGetGroupSystemMsg: () => Promise<JsonObject[]>;
|
||||
getDownloadRKeys: () => Promise<JsonObject[]>;
|
||||
// Forward message
|
||||
sendGroupForwardMsg: (groupId: number, messages: JsonValue, meta?: ForwardPreviewMeta) => Promise<{ messageId: number; forwardId: string }>;
|
||||
sendPrivateForwardMsg: (userId: number, messages: JsonValue, meta?: ForwardPreviewMeta) => Promise<{ messageId: number; forwardId: string }>;
|
||||
sendForwardMsg: (messages: JsonValue) => Promise<{ forwardId: string }>;
|
||||
@@ -108,16 +99,15 @@ export interface ApiActionContext {
|
||||
setFriendRemark: (userId: number, remark: string) => Promise<void>;
|
||||
setGroupRemark: (groupId: number, remark: string) => Promise<void>;
|
||||
setGroupAvatar: (groupId: number, source: string) => Promise<void>;
|
||||
getGroupFileCount: (groupId: number) => Promise<{ fileCount: number; maxCount: number }>;
|
||||
setMsgEmojiLike: (messageId: number, emojiId: string, set: boolean) => Promise<void>;
|
||||
markGroupMsgAsRead: (groupId: number, sequence: number) => Promise<void>;
|
||||
markPrivateMsgAsRead: (userId: number, sequence: number) => Promise<void>;
|
||||
getProfileLike: (userId?: number, start?: number, limit?: number) => Promise<any>;
|
||||
setOnlineStatus: (status: number, extStatus?: number, batteryStatus?: number) => Promise<void>;
|
||||
setProfile: (nickname?: string, personalNote?: string) => Promise<void>;
|
||||
fetchCustomFace: (count?: number) => Promise<string[]>;
|
||||
getEmojiLikes: (groupId: number, sequence: number, emojiId: string, emojiType?: number, count?: number, cookie?: string) => Promise<{ users: Array<{ uin: number }>, cookie: string, isLast: boolean }>;
|
||||
// Web
|
||||
getGroupHonorInfo: (groupId: number, type: WebHonorType | string) => Promise<any>;
|
||||
getGroupEssence: (groupId: number, pageStart?: number, pageLimit?: number) => Promise<GroupEssenceMsgRet>;
|
||||
getGroupEssenceAll: (groupId: number) => Promise<GroupEssenceMsgRet[]>;
|
||||
getGroupAlbumList: (groupId: number) => Promise<any>;
|
||||
uploadImageToGroupAlbum: (groupId: number, albumId: string, albumName: string, filePath: string) => Promise<void>;
|
||||
@@ -128,11 +118,10 @@ export interface ApiActionContext {
|
||||
getCookiesStr: (domain: string) => Promise<string>;
|
||||
getCsrfToken: () => Promise<number>;
|
||||
getCredentials: (domain: string) => Promise<{ cookies: string; token: number; csrf_token: number }>;
|
||||
forceFetchClientKey: () => Promise<ClientKeyInfo>;
|
||||
// Media lookup (populated from previously dispatched message segments)
|
||||
getImageInfo: (file: string) => Promise<JsonObject | null>;
|
||||
getRecordInfo: (file: string) => Promise<JsonObject | null>;
|
||||
// Avatar
|
||||
setAvatar: (source: string) => Promise<void>;
|
||||
}
|
||||
|
||||
type ActionHandler = (params: JsonObject) => Promise<import('./types').ApiResponse>;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import type { WebHonorType } from '@/bridge/web/group-honor';
|
||||
import type { Bridge } from '../bridge/bridge';
|
||||
import type { QQInfo } from '../bridge/qq-info';
|
||||
import type { ApiActionContext } from './api-handler';
|
||||
import type { ConverterContext } from './event-converter';
|
||||
import type { MediaStore } from './media-store';
|
||||
@@ -36,6 +35,7 @@ import {
|
||||
getRecordInfo as getCachedRecordInfo,
|
||||
} from './modules/media-actions';
|
||||
import { handleGroupAddRequest } from './modules/request-actions';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
|
||||
/**
|
||||
* Single shared context bag that flows through every OneBot instance-internal
|
||||
@@ -56,8 +56,7 @@ export interface OneBotInstanceContext {
|
||||
/** Self UIN parsed once, used in event payloads. */
|
||||
selfId: number;
|
||||
|
||||
qqInfo: QQInfo;
|
||||
bridge: Bridge;
|
||||
bridge: BridgeInterface;
|
||||
|
||||
messageStore: MessageStore;
|
||||
mediaStore: MediaStore;
|
||||
@@ -73,10 +72,25 @@ export interface OneBotInstanceContext {
|
||||
dispatchEvent(event: JsonObject): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the ApiActionContext that ApiHandler hands to each action file.
|
||||
*
|
||||
* Two flavours of entries live in here:
|
||||
* - Adapters — rename a Bridge method (setGroupKick → kickGroupMember),
|
||||
* compose with messageStore / mediaStore / ref, bake in a constant
|
||||
* (setEssenceMsg passes true; deleteEssenceMsg passes false), bridge a
|
||||
* bridge call into OneBot vocabulary (sendFriendPoke flattens the
|
||||
* isGroup boolean), or extract a field from the bridge return shape.
|
||||
* - Pass-throughs used to live here too but added zero value; OneBot
|
||||
* actions now call `ctx.bridge.<name>` directly when no translation is
|
||||
* happening (set_group_admin, set_online_status, set_avatar, …).
|
||||
*/
|
||||
export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
const { bridge, qqInfo, messageStore, mediaStore } = ref;
|
||||
const { bridge, messageStore, mediaStore } = ref;
|
||||
|
||||
return {
|
||||
bridge,
|
||||
|
||||
getLoginInfo: () => getLoginInfo(ref),
|
||||
isOnline: () => true,
|
||||
getMessage: (messageId) => messageStore.findEvent(messageId),
|
||||
@@ -89,29 +103,22 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
sendGroupMessage: (groupId, message, autoEscape) => sendGroupMessage(ref, groupId, message, autoEscape),
|
||||
deleteMessage: (_messageId, meta) => deleteMessage(bridge, meta),
|
||||
|
||||
// OneBot11 info actions.
|
||||
getFriendList: () => getFriendList(bridge, qqInfo),
|
||||
getGroupList: (noCache) => getGroupList(bridge, qqInfo, noCache),
|
||||
getGroupInfo: (groupId, noCache) => getGroupInfo(bridge, qqInfo, groupId, noCache),
|
||||
getGroupMemberList: (groupId, noCache) => getGroupMemberList(bridge, qqInfo, groupId, noCache),
|
||||
getGroupMemberInfo: (groupId, userId, noCache) => getGroupMemberInfo(bridge, qqInfo, groupId, userId, noCache),
|
||||
getStrangerInfo: (userId) => getStrangerInfo(bridge, qqInfo, userId),
|
||||
// OneBot11 info actions (wrap modules that also touch identity).
|
||||
getFriendList: () => getFriendList(bridge),
|
||||
getGroupList: (noCache) => getGroupList(bridge, noCache),
|
||||
getGroupInfo: (groupId, noCache) => getGroupInfo(bridge, groupId, noCache),
|
||||
getGroupMemberList: (groupId, noCache) => getGroupMemberList(bridge, groupId, noCache),
|
||||
getGroupMemberInfo: (groupId, userId, noCache) => getGroupMemberInfo(bridge, groupId, userId, noCache),
|
||||
getStrangerInfo: (userId) => getStrangerInfo(bridge, userId),
|
||||
|
||||
// Group admin.
|
||||
// Group admin — names translate to OneBot vocabulary.
|
||||
setGroupKick: (groupId, userId, reject) => bridge.kickGroupMember(groupId, userId, reject),
|
||||
setGroupKickMembers: (groupId, userIds, reject) => bridge.kickGroupMembers(groupId, userIds, reject),
|
||||
setGroupBan: (groupId, userId, duration) => bridge.muteGroupMember(groupId, userId, duration),
|
||||
setGroupWholeBan: (groupId, enable) => bridge.muteGroupAll(groupId, enable),
|
||||
setGroupAddOption: (groupId, addType) => bridge.setGroupAddOption(groupId, addType),
|
||||
setGroupSearch: (groupId) => bridge.setGroupSearch(groupId),
|
||||
setGroupAdmin: (groupId, userId, enable) => bridge.setGroupAdmin(groupId, userId, enable),
|
||||
setGroupCard: (groupId, userId, card) => bridge.setGroupCard(groupId, userId, card),
|
||||
setGroupName: (groupId, name) => bridge.setGroupName(groupId, name),
|
||||
setGroupLeave: (groupId) => bridge.leaveGroup(groupId),
|
||||
setGroupSpecialTitle: (groupId, userId, title) => bridge.setGroupSpecialTitle(groupId, userId, title),
|
||||
getGroupAtAllRemain: (groupId) => bridge.getGroupAtAllRemain(groupId),
|
||||
|
||||
// Group file.
|
||||
// Group file — fileId field extraction + defaults.
|
||||
uploadGroupFile: async (groupId, file, name, folderId, uploadFile) => {
|
||||
const result = await bridge.uploadGroupFile(groupId, file, name ?? '', folderId ?? '/', uploadFile ?? true);
|
||||
return result.fileId;
|
||||
@@ -122,45 +129,31 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
},
|
||||
getGroupFileUrl: (groupId, fileId, busId) => bridge.fetchGroupFileUrl(groupId, fileId, busId ?? 102),
|
||||
getGroupFiles: (groupId, folderId) => getGroupFiles(bridge, groupId, folderId),
|
||||
deleteGroupFile: (groupId, fileId) => bridge.deleteGroupFile(groupId, fileId),
|
||||
moveGroupFile: (groupId, fileId, parentDirectory, targetDirectory) => {
|
||||
return bridge.moveGroupFile(groupId, fileId, parentDirectory, targetDirectory);
|
||||
},
|
||||
createGroupFileFolder: (groupId, name, parentId) => bridge.createGroupFileFolder(groupId, name, parentId ?? '/'),
|
||||
deleteGroupFileFolder: (groupId, folderId) => bridge.deleteGroupFileFolder(groupId, folderId),
|
||||
renameGroupFileFolder: (groupId, folderId, newName) => bridge.renameGroupFileFolder(groupId, folderId, newName),
|
||||
getPrivateFileUrl: (userId, fileId, fileHash) => bridge.fetchPrivateFileUrl(userId, fileId, fileHash),
|
||||
|
||||
// Requests.
|
||||
// Requests — name translation.
|
||||
handleFriendRequest: (flag, approve) => bridge.setFriendAddRequest(flag, approve),
|
||||
handleGroupRequest: (flag, _subType, approve, reason) => handleGroupAddRequest(bridge, flag, approve, reason),
|
||||
|
||||
// Extended.
|
||||
sendLike: (userId, times) => bridge.sendLike(userId, times),
|
||||
// Pokes — flatten isGroup into the bridge signature.
|
||||
sendFriendPoke: (userId, targetId) => bridge.sendPoke(false, userId, targetId),
|
||||
sendGroupPoke: (groupId, userId) => bridge.sendPoke(true, groupId, userId),
|
||||
|
||||
// Essence — bake the set/unset boolean.
|
||||
setEssenceMsg: (messageId) => setEssenceMessage(bridge, messageStore, messageId, true),
|
||||
deleteEssenceMsg: (messageId) => setEssenceMessage(bridge, messageStore, messageId, false),
|
||||
getProfileLike: (userId = undefined, start = 0, limit = 10) => bridge.getProfileLike(userId, start, limit),
|
||||
fetchCustomFace: (count) => bridge.fetchCustomFace(count),
|
||||
getEmojiLikes: (groupId, sequence, emojiId, emojiType, count, cookie) => {
|
||||
return bridge.getEmojiLikes(groupId, sequence, emojiId, emojiType, count, cookie);
|
||||
},
|
||||
getUnidirectionalFriendList: () => bridge.getUnidirectionalFriendList(),
|
||||
setSelfLongNick: (longNick) => bridge.setSelfLongNick(longNick),
|
||||
setInputStatus: (userId, eventType) => bridge.setInputStatus(userId, eventType),
|
||||
translateEn2Zh: (words) => bridge.translateEn2Zh(words),
|
||||
getMiniAppArk: (type, title, desc, picUrl, jumpUrl) => bridge.getMiniAppArk(type, title, desc, picUrl, jumpUrl),
|
||||
clickInlineKeyboardButton: (groupId, botAppid, buttonId, callbackData, msgSeq) => {
|
||||
return bridge.clickInlineKeyboardButton(groupId, botAppid, buttonId, callbackData, msgSeq);
|
||||
},
|
||||
sendGroupSign: (groupId) => bridge.sendGroupSign(groupId),
|
||||
|
||||
// NapCat-compatible extended actions.
|
||||
setGroupReaction: (groupId, sequence, code, isSet) => bridge.setGroupReaction(groupId, sequence, code, isSet),
|
||||
handleDeleteFriend: (userId, block) => bridge.deleteFriend(userId, !!block),
|
||||
// Profile-like / get_group_essence — OneBot-specific defaults that the
|
||||
// action handlers don't supply.
|
||||
getProfileLike: (userId = undefined, start = 0, limit = 10) => bridge.getProfileLike(userId, start, limit),
|
||||
getGroupEssence: (groupId, pageStart = 0, pageLimit = 50) => bridge.getGroupEssence(groupId, pageStart, pageLimit),
|
||||
|
||||
// Message-store-backed history reads.
|
||||
getGroupMsgHistory: (groupId, messageId, count) => getGroupMsgHistory(messageStore, groupId, messageId, count),
|
||||
getFriendMsgHistory: (userId, messageId, count) => getFriendMsgHistory(messageStore, userId, messageId, count),
|
||||
|
||||
// Module wrappers / multi-dep compositions.
|
||||
handleGetGroupSystemMsg: () => getGroupSystemMessages(bridge),
|
||||
getDownloadRKeys: () => getDownloadRKeys(bridge),
|
||||
sendGroupForwardMsg: (groupId, messages, meta) => sendGroupForwardMessage(ref, groupId, messages, meta),
|
||||
@@ -168,24 +161,30 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
sendForwardMsg: (messages) => uploadForwardMessage(ref, messages),
|
||||
getForwardMsg: (resId) => getForwardMessage(ref, resId),
|
||||
forwardSingleMsg: (messageId, target) => forwardSingleMessage(ref, messageId, target),
|
||||
handleDeleteFriend: (userId, block) => bridge.deleteFriend(userId, !!block),
|
||||
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
||||
setGroupRemark: (groupId, remark) => bridge.setGroupRemark(groupId, remark),
|
||||
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
||||
|
||||
// Cross-store: looks up the meta then routes through Bridge.
|
||||
setMsgEmojiLike: async (messageId, emojiId, set) => {
|
||||
const meta = messageStore.findMeta(messageId);
|
||||
if (!meta || !meta.isGroup) throw new Error('message not found or not a group message');
|
||||
if (!meta) throw new Error('message not found');
|
||||
// QQ itself doesn't expose emoji reactions on private chats, so
|
||||
// there is no wire path to forward this to; fail loudly instead
|
||||
// of silently no-op'ing.
|
||||
if (!meta.isGroup) throw new Error('emoji reactions are not supported on private messages');
|
||||
await bridge.setGroupReaction(meta.targetId, meta.sequence, emojiId, set);
|
||||
},
|
||||
markGroupMsgAsRead: (groupId, sequence) => bridge.markGroupMsgAsRead(groupId, sequence),
|
||||
markPrivateMsgAsRead: (userId, sequence) => bridge.markPrivateMsgAsRead(userId, sequence),
|
||||
setOnlineStatus: (status, extStatus, batteryStatus) => bridge.setOnlineStatus(status, extStatus, batteryStatus),
|
||||
setProfile: (nickname, personalNote) => bridge.setProfile(nickname, personalNote),
|
||||
setOnlineStatus: (status: number, extStatus?: number, batteryStatus?: number) => bridge.setOnlineStatus(status, extStatus, batteryStatus),
|
||||
setProfile: (nickname?: string, personalNote?: string) => bridge.setProfile(nickname, personalNote),
|
||||
|
||||
// Web-backed actions.
|
||||
getGroupHonorInfo: (groupId: number, type: WebHonorType | string) => bridge.getGroupHonorInfo(groupId, type),
|
||||
getGroupEssence: (groupId, pageStart = 0, pageLimit = 50) => bridge.getGroupEssence(groupId, pageStart, pageLimit),
|
||||
getGroupEssenceAll: (groupId) => bridge.getGroupEssenceAll(groupId),
|
||||
getGroupAlbumList: (groupId) => bridge.getGroupAlbumList(groupId),
|
||||
uploadImageToGroupAlbum: (groupId, albumId, albumName, filePath) => bridge.uploadImageToGroupAlbum(groupId, albumId, albumName, filePath),
|
||||
@@ -197,11 +196,20 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
||||
getCsrfToken: () => bridge.getCsrfToken(),
|
||||
getCredentials: (domain) => bridge.getCredentials(domain),
|
||||
|
||||
// Extended
|
||||
fetchCustomFace: (count) => bridge.fetchCustomFace(count),
|
||||
getEmojiLikes: (groupId, sequence, emojiId, emojiType, count, cookie) => bridge.getEmojiLikes(groupId, sequence, emojiId, emojiType, count, cookie),
|
||||
|
||||
// Media lookup.
|
||||
getImageInfo: (file) => getCachedImageInfo(mediaStore, file),
|
||||
getRecordInfo: (file) => getCachedRecordInfo(bridge, mediaStore, file),
|
||||
|
||||
// Avatar.
|
||||
setAvatar: (source) => bridge.setAvatar(source),
|
||||
};
|
||||
}
|
||||
|
||||
// Re-export Bridge type so consumers of OneBotInstanceContext that need it
|
||||
// (legacy) keep the import surface stable.
|
||||
export type { Bridge };
|
||||
|
||||
// Re-export WebHonorType so legacy spots that imported it via this module
|
||||
// keep working.
|
||||
export type { WebHonorType };
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { Bridge, DownloadRKeyInfo } from '../bridge/bridge';
|
||||
import type { DownloadRKeyInfo } from '../bridge/bridge';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import { createLogger } from '../utils/logger';
|
||||
|
||||
const log = createLogger('OneBot');
|
||||
@@ -26,7 +27,7 @@ export class RKeyCache {
|
||||
private cache = new Map<number, CachedRKey>();
|
||||
private lastRefreshAttempt = 0;
|
||||
|
||||
warmUp(bridge: Bridge, uin: string): void {
|
||||
warmUp(bridge: BridgeInterface, uin: string): void {
|
||||
bridge.fetchDownloadRKeys().then(
|
||||
(rkeys) => {
|
||||
this.updateCache(rkeys);
|
||||
@@ -38,7 +39,7 @@ export class RKeyCache {
|
||||
);
|
||||
}
|
||||
|
||||
resolveImageUrl(bridge: Bridge, element: MessageElement, isGroup: boolean): string {
|
||||
resolveImageUrl(bridge: BridgeInterface, element: MessageElement, isGroup: boolean): string {
|
||||
const url = element.imageUrl ?? '';
|
||||
if (!urlNeedsRKey(url)) return url;
|
||||
|
||||
@@ -54,7 +55,7 @@ export class RKeyCache {
|
||||
* Resolve a URL for video/record/file media elements.
|
||||
* Appends the correct RKey type based on media kind and group/private context.
|
||||
*/
|
||||
resolveMediaUrl(bridge: Bridge, element: MessageElement, isGroup: boolean): string {
|
||||
resolveMediaUrl(bridge: BridgeInterface, element: MessageElement, isGroup: boolean): string {
|
||||
const url = element.url ?? '';
|
||||
if (!url || !urlNeedsRKey(url)) return url;
|
||||
|
||||
@@ -93,12 +94,12 @@ export class RKeyCache {
|
||||
}
|
||||
}
|
||||
|
||||
private findRKey(bridge: Bridge, isGroup: boolean): string | null {
|
||||
private findRKey(bridge: BridgeInterface, isGroup: boolean): string | null {
|
||||
const primaryType = isGroup ? GROUP_IMAGE_RKEY_TYPE : PRIVATE_IMAGE_RKEY_TYPE;
|
||||
return this.findRKeyForType(bridge, primaryType);
|
||||
}
|
||||
|
||||
private findRKeyForType(bridge: Bridge, primaryType: number): string | null {
|
||||
private findRKeyForType(bridge: BridgeInterface, primaryType: number): string | null {
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
const tryFind = (type: number): string | null => {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import path from 'path';
|
||||
import type { Bridge } from '../bridge/bridge';
|
||||
import type { QQInfo } from '../bridge/qq-info';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import { ApiHandler } from './api-handler';
|
||||
import type { ConverterContext } from './event-converter';
|
||||
import { MediaIndexer } from './media-indexer';
|
||||
@@ -27,8 +26,7 @@ const log = createLogger('Event');
|
||||
export class OneBotInstance {
|
||||
readonly uin: string;
|
||||
|
||||
readonly qqInfo: QQInfo;
|
||||
private readonly bridge: Bridge;
|
||||
private readonly bridge: BridgeInterface;
|
||||
private readonly apiHandler: ApiHandler;
|
||||
private readonly converterCtx: ConverterContext;
|
||||
private readonly messageStore: MessageStore;
|
||||
@@ -43,9 +41,10 @@ export class OneBotInstance {
|
||||
private heartbeatTimer: NodeJS.Timeout | null = null;
|
||||
private static readonly HEARTBEAT_INTERVAL = 30000;
|
||||
|
||||
constructor(uin: string, qqInfo: QQInfo, bridge: Bridge, config: OneBotConfig) {
|
||||
get nickname(): string { return this.bridge.identity.nickname; }
|
||||
|
||||
constructor(uin: string, bridge: BridgeInterface, config: OneBotConfig) {
|
||||
this.uin = uin;
|
||||
this.qqInfo = qqInfo;
|
||||
this.bridge = bridge;
|
||||
|
||||
this.rkeyCache = new RKeyCache();
|
||||
@@ -75,7 +74,6 @@ export class OneBotInstance {
|
||||
const ctx: OneBotInstanceContext = {
|
||||
uin: this.uin,
|
||||
selfId: parseInt(this.uin, 10) || 0,
|
||||
qqInfo: this.qqInfo,
|
||||
bridge: this.bridge,
|
||||
messageStore: this.messageStore,
|
||||
mediaStore: this.mediaStore,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { Bridge } from '../bridge/bridge';
|
||||
import type { QQInfo } from '../bridge/qq-info';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import type { BridgeManager } from '../bridge/manager';
|
||||
import { loadOneBotConfig } from './config';
|
||||
import { OneBotInstance } from './instance';
|
||||
@@ -12,8 +11,8 @@ export class OneBotManager {
|
||||
private readonly instances = new Map<string, OneBotInstance>();
|
||||
|
||||
bind(bridgeManager: BridgeManager): void {
|
||||
bridgeManager.setSessionStartedCallback((uin, qqInfo, bridge) => {
|
||||
this.onSessionStarted(uin, qqInfo, bridge);
|
||||
bridgeManager.setSessionStartedCallback((uin, bridge) => {
|
||||
this.onSessionStarted(uin, bridge);
|
||||
});
|
||||
|
||||
bridgeManager.setSessionClosedCallback((uin) => {
|
||||
@@ -49,11 +48,11 @@ export class OneBotManager {
|
||||
this.instances.clear();
|
||||
}
|
||||
|
||||
private onSessionStarted(uin: string, qqInfo: QQInfo, bridge: Bridge): void {
|
||||
private onSessionStarted(uin: string, bridge: BridgeInterface): void {
|
||||
if (this.instances.has(uin)) return;
|
||||
|
||||
const config = loadOneBotConfig(uin);
|
||||
const instance = new OneBotInstance(uin, qqInfo, bridge, config);
|
||||
const instance = new OneBotInstance(uin, bridge, config);
|
||||
|
||||
const activePid = bridge.activePid;
|
||||
if (activePid !== null) {
|
||||
@@ -62,13 +61,13 @@ export class OneBotManager {
|
||||
|
||||
// Seed nickname with the UIN so the WebUI never renders blank while
|
||||
// warmup is in flight or if warmup never resolves a real nickname.
|
||||
if (!qqInfo.nickname) qqInfo.nickname = uin;
|
||||
if (!bridge.identity.nickname) bridge.identity.nickname = uin;
|
||||
|
||||
this.instances.set(uin, instance);
|
||||
log.info('session started: UIN=%s', uin);
|
||||
|
||||
// Warm up bridge state asynchronously (mirrors C++ warm_up_bridge_state)
|
||||
warmUpBridgeState(uin, qqInfo, bridge).catch((err) => {
|
||||
warmUpBridgeState(uin, bridge).catch((err) => {
|
||||
log.warn('warmup error for UIN %s: %s', uin, err instanceof Error ? (err.stack ?? err.message) : String(err));
|
||||
});
|
||||
}
|
||||
@@ -84,13 +83,13 @@ export class OneBotManager {
|
||||
|
||||
}
|
||||
|
||||
async function warmUpBridgeState(uin: string, qqInfo: QQInfo, bridge: Bridge): Promise<void> {
|
||||
async function warmUpBridgeState(uin: string, bridge: BridgeInterface): Promise<void> {
|
||||
const selfUin = parseInt(uin, 10) || 0;
|
||||
let selfResolved = false;
|
||||
|
||||
// Step 1: Fetch friend list + derive self profile when QQ happens to
|
||||
// include self in the response. Some accounts / versions omit self,
|
||||
// which used to leave qqInfo.nickname empty — see step 1b for the
|
||||
// which used to leave identity.nickname empty — see step 1b for the
|
||||
// explicit fallback.
|
||||
try {
|
||||
const friends = await bridge.fetchFriendList();
|
||||
@@ -98,12 +97,12 @@ async function warmUpBridgeState(uin: string, qqInfo: QQInfo, bridge: Bridge): P
|
||||
|
||||
for (const f of friends) {
|
||||
if (f.uin === selfUin) {
|
||||
qqInfo.setSelfProfile({
|
||||
bridge.identity.setSelfProfile({
|
||||
uin: f.uin, uid: f.uid,
|
||||
nickname: f.nickname || uin,
|
||||
remark: '', qid: '', sex: 'unknown', age: 0, sign: '', avatar: '',
|
||||
});
|
||||
qqInfo.nickname = f.nickname || uin;
|
||||
bridge.identity.nickname = f.nickname || uin;
|
||||
log.debug('self info: UIN=%s uid=%s nickname=%s', uin, f.uid, f.nickname ?? '');
|
||||
selfResolved = true;
|
||||
break;
|
||||
@@ -120,8 +119,8 @@ async function warmUpBridgeState(uin: string, qqInfo: QQInfo, bridge: Bridge): P
|
||||
if (!selfResolved && selfUin > 0) {
|
||||
try {
|
||||
const profile = await bridge.fetchUserProfile(selfUin);
|
||||
qqInfo.setSelfProfile(profile);
|
||||
qqInfo.nickname = profile.nickname || uin;
|
||||
bridge.identity.setSelfProfile(profile);
|
||||
bridge.identity.nickname = profile.nickname || uin;
|
||||
log.debug('self info via profile: UIN=%s uid=%s nickname=%s',
|
||||
uin, profile.uid, profile.nickname);
|
||||
} catch (e) {
|
||||
|
||||
@@ -12,13 +12,13 @@
|
||||
//
|
||||
// Used as the `mediaUrlResolver` callback in `ConverterContext`.
|
||||
|
||||
import type { Bridge } from '../bridge/bridge';
|
||||
import type { BridgeInterface } from '../bridge/bridge-interface';
|
||||
import type { MessageElement } from '../bridge/events';
|
||||
import type { RKeyCache } from './instance-rkey';
|
||||
|
||||
export class MediaUrlResolver {
|
||||
constructor(
|
||||
private readonly bridge: Bridge,
|
||||
private readonly bridge: BridgeInterface,
|
||||
private readonly rkeyCache: RKeyCache,
|
||||
) {}
|
||||
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import type { Bridge } from '../../bridge/bridge';
|
||||
import type { QQInfo } from '../../bridge/qq-info';
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
import type { IdentityService } from '../../bridge/identity-service';
|
||||
import type { OneBotInstanceContext } from '../instance-context';
|
||||
import type { JsonObject } from '../types';
|
||||
|
||||
export function getLoginInfo(ref: OneBotInstanceContext): { userId: number; nickname: string } {
|
||||
const userId = parseInt(ref.uin, 10) || 0;
|
||||
const nickname = ref.qqInfo.nickname || ref.uin;
|
||||
const nickname = ref.bridge.identity.nickname || ref.uin;
|
||||
return { userId, nickname };
|
||||
}
|
||||
|
||||
// Keep refreshes scoped. A broad "refresh all members in all groups" call can
|
||||
// turn one OneBot request into N OIDB calls, which is risky for busy clients.
|
||||
async function refreshSingleGroupMembers(bridge: Bridge, groupId: number): Promise<void> {
|
||||
async function refreshSingleGroupMembers(bridge: BridgeInterface, groupId: number): Promise<void> {
|
||||
try {
|
||||
await bridge.fetchGroupMemberList(groupId);
|
||||
} catch {
|
||||
@@ -19,7 +19,7 @@ async function refreshSingleGroupMembers(bridge: Bridge, groupId: number): Promi
|
||||
}
|
||||
}
|
||||
|
||||
export async function getFriendList(bridge: Bridge, qqInfo: QQInfo): Promise<JsonObject[]> {
|
||||
export async function getFriendList(bridge: BridgeInterface): Promise<JsonObject[]> {
|
||||
try {
|
||||
const friends = await bridge.fetchFriendList();
|
||||
return friends.map(f => ({
|
||||
@@ -28,7 +28,7 @@ export async function getFriendList(bridge: Bridge, qqInfo: QQInfo): Promise<Jso
|
||||
remark: f.remark as any,
|
||||
}));
|
||||
} catch {
|
||||
return qqInfo.friends.map(f => ({
|
||||
return bridge.identity.friends.map(f => ({
|
||||
user_id: f.uin as any,
|
||||
nickname: f.nickname as any,
|
||||
remark: f.remark as any,
|
||||
@@ -37,18 +37,17 @@ export async function getFriendList(bridge: Bridge, qqInfo: QQInfo): Promise<Jso
|
||||
}
|
||||
|
||||
export async function getGroupList(
|
||||
bridge: Bridge,
|
||||
qqInfo: QQInfo,
|
||||
bridge: BridgeInterface,
|
||||
noCache?: boolean,
|
||||
): Promise<JsonObject[]> {
|
||||
try {
|
||||
if (noCache || qqInfo.groups.length === 0) {
|
||||
if (noCache || bridge.identity.groups.length === 0) {
|
||||
await bridge.fetchGroupList();
|
||||
}
|
||||
} catch {
|
||||
// Use cached data.
|
||||
}
|
||||
return qqInfo.groups.map(g => ({
|
||||
return bridge.identity.groups.map(g => ({
|
||||
group_id: g.groupId as any,
|
||||
group_name: g.groupName as any,
|
||||
member_count: g.memberCount as any,
|
||||
@@ -57,19 +56,18 @@ export async function getGroupList(
|
||||
}
|
||||
|
||||
export async function getGroupInfo(
|
||||
bridge: Bridge,
|
||||
qqInfo: QQInfo,
|
||||
bridge: BridgeInterface,
|
||||
groupId: number,
|
||||
noCache?: boolean,
|
||||
): Promise<JsonObject | null> {
|
||||
if (noCache || !qqInfo.findGroup(groupId)) {
|
||||
if (noCache || !bridge.identity.findGroup(groupId)) {
|
||||
try {
|
||||
await bridge.fetchGroupList();
|
||||
} catch {
|
||||
// Use cached data.
|
||||
}
|
||||
}
|
||||
const g = qqInfo.findGroup(groupId);
|
||||
const g = bridge.identity.findGroup(groupId);
|
||||
if (!g) return null;
|
||||
return {
|
||||
group_id: g.groupId as any,
|
||||
@@ -80,41 +78,39 @@ export async function getGroupInfo(
|
||||
}
|
||||
|
||||
export async function getGroupMemberList(
|
||||
bridge: Bridge,
|
||||
qqInfo: QQInfo,
|
||||
bridge: BridgeInterface,
|
||||
groupId: number,
|
||||
noCache?: boolean,
|
||||
): Promise<JsonObject[]> {
|
||||
if (noCache) {
|
||||
await refreshSingleGroupMembers(bridge, groupId);
|
||||
return getCachedGroupMembers(qqInfo, groupId);
|
||||
return getCachedGroupMembers(bridge.identity, groupId);
|
||||
}
|
||||
|
||||
try {
|
||||
const members = await bridge.fetchGroupMemberList(groupId);
|
||||
return members.map(m => formatGroupMember(groupId, m));
|
||||
} catch {
|
||||
return getCachedGroupMembers(qqInfo, groupId);
|
||||
return getCachedGroupMembers(bridge.identity, groupId);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getGroupMemberInfo(
|
||||
bridge: Bridge,
|
||||
qqInfo: QQInfo,
|
||||
bridge: BridgeInterface,
|
||||
groupId: number,
|
||||
userId: number,
|
||||
noCache?: boolean,
|
||||
): Promise<JsonObject | null> {
|
||||
if (noCache || !qqInfo.findGroupMember(groupId, userId)) {
|
||||
if (noCache || !bridge.identity.findGroupMember(groupId, userId)) {
|
||||
await refreshSingleGroupMembers(bridge, groupId);
|
||||
}
|
||||
const m = qqInfo.findGroupMember(groupId, userId);
|
||||
const m = bridge.identity.findGroupMember(groupId, userId);
|
||||
if (!m) return null;
|
||||
return formatGroupMember(groupId, m);
|
||||
}
|
||||
|
||||
export async function getGroupFiles(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeInterface,
|
||||
groupId: number,
|
||||
folderId?: string,
|
||||
): Promise<JsonObject> {
|
||||
@@ -146,8 +142,7 @@ export async function getGroupFiles(
|
||||
}
|
||||
|
||||
export async function getStrangerInfo(
|
||||
bridge: Bridge,
|
||||
qqInfo: QQInfo,
|
||||
bridge: BridgeInterface,
|
||||
userId: number,
|
||||
): Promise<JsonObject | null> {
|
||||
try {
|
||||
@@ -159,7 +154,7 @@ export async function getStrangerInfo(
|
||||
age: p.age as any,
|
||||
};
|
||||
} catch {
|
||||
const p = qqInfo.findUserProfile(userId);
|
||||
const p = bridge.identity.findUserProfile(userId);
|
||||
if (!p) return null;
|
||||
return {
|
||||
user_id: p.uin as any,
|
||||
@@ -170,7 +165,7 @@ export async function getStrangerInfo(
|
||||
}
|
||||
}
|
||||
|
||||
export async function getGroupSystemMessages(bridge: Bridge): Promise<JsonObject[]> {
|
||||
export async function getGroupSystemMessages(bridge: BridgeInterface): Promise<JsonObject[]> {
|
||||
try {
|
||||
const reqs = await bridge.fetchGroupRequests();
|
||||
return reqs.map(r => ({
|
||||
@@ -187,7 +182,7 @@ export async function getGroupSystemMessages(bridge: Bridge): Promise<JsonObject
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDownloadRKeys(bridge: Bridge): Promise<JsonObject[]> {
|
||||
export async function getDownloadRKeys(bridge: BridgeInterface): Promise<JsonObject[]> {
|
||||
try {
|
||||
const rkeys = await bridge.fetchDownloadRKeys();
|
||||
return rkeys.map(r => ({
|
||||
@@ -201,8 +196,8 @@ export async function getDownloadRKeys(bridge: Bridge): Promise<JsonObject[]> {
|
||||
}
|
||||
}
|
||||
|
||||
function getCachedGroupMembers(qqInfo: QQInfo, groupId: number): JsonObject[] {
|
||||
const g = qqInfo.findGroup(groupId);
|
||||
function getCachedGroupMembers(identity: IdentityService, groupId: number): JsonObject[] {
|
||||
const g = identity.findGroup(groupId);
|
||||
if (!g) return [];
|
||||
const result: JsonObject[] = [];
|
||||
for (const [, member] of g.members) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Bridge } from '../../bridge/bridge';
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
import { createLogger } from '../../utils/logger';
|
||||
import type { MediaStore } from '../media-store';
|
||||
import type { JsonObject } from '../types';
|
||||
@@ -21,7 +21,7 @@ export async function getImageInfo(
|
||||
}
|
||||
|
||||
export async function getRecordInfo(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeInterface,
|
||||
mediaStore: MediaStore,
|
||||
file: string,
|
||||
): Promise<JsonObject | null> {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Bridge } from '../../bridge/bridge';
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
import type { ForwardNodePayload, MessageElement } from '../../bridge/events';
|
||||
import { createLogger } from '../../utils/logger';
|
||||
import type { MessageSendResult } from '../api-handler';
|
||||
@@ -63,7 +63,7 @@ export async function getFriendMsgHistory(
|
||||
.map(sanitizeMessageEventForApi);
|
||||
}
|
||||
|
||||
export async function deleteMessage(bridge: Bridge, meta: MessageMeta): Promise<void> {
|
||||
export async function deleteMessage(bridge: BridgeInterface, meta: MessageMeta): Promise<void> {
|
||||
if (meta.isGroup) {
|
||||
await bridge.recallGroupMessage(meta.targetId, meta.sequence);
|
||||
} else {
|
||||
@@ -78,7 +78,7 @@ export async function deleteMessage(bridge: Bridge, meta: MessageMeta): Promise<
|
||||
}
|
||||
|
||||
export async function setEssenceMessage(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeInterface,
|
||||
messageStore: MessageStore,
|
||||
messageId: number,
|
||||
enable: boolean,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Bridge } from '../../bridge/bridge';
|
||||
import type { BridgeInterface } from '../../bridge/bridge-interface';
|
||||
|
||||
export async function handleGroupAddRequest(
|
||||
bridge: Bridge,
|
||||
bridge: BridgeInterface,
|
||||
flag: string,
|
||||
approve: boolean,
|
||||
reason: string,
|
||||
|
||||
Reference in new issue
Block a user