refactor(core): make ApiActionContext required, drop 80 dead defensive guards
ApiActionContext had 81 optional method fields (\`name?: ...\`) plus 4
required ones — but every single optional field was wired in
buildApiContext (verified by diffing the two lists). The optionality
was dead: nothing else implemented this interface, no test ever
swapped fields out, and the action handlers all paid for the
fiction with defensive guards like:
if (!ctx.sendGroupMessage) {
return failedResponse(RETCODE.ACTION_FAILED, 'send_group_msg is not implemented');
}
— 80 such guards total across the action files (78 in the 3-line
form, 1 single-line, 1 \`if (!(ctx.a && ctx.b))\` compound). None of
them could ever fire.
This commit deletes the dead optionality. Two mechanical changes:
1. api-handler.ts: 81 \`name?: ...\` -> \`name: ...\` in ApiActionContext.
The MessageSendResult optionals (meta?, echoEvent?) are unrelated
and stay as-is. After: 85 required fields, 0 optionals.
2. actions/*.ts: drop the 80 guard blocks. Net -129 lines across
extended, group-admin, group-file, group-info, friend, message,
request. info.ts had none to begin with.
What this buys:
- The type system now enforces the wiring contract. If
buildApiContext forgets to wire a field, tsc fails at the call
site — the bug we were ostensibly catching at runtime in 80 places
is now caught at compile time in 0 places, for free.
- Action handler bodies shrink visibly (avg ~3 lines per handler).
extended.ts goes 1021 -> 935.
- AI / human readers no longer skim past dead code.
Caught one TS2774 ("This condition will always return true since
this function is always defined") on a compound guard in
extended.ts:186 that the regex missed; removed it manually. That
diagnostic is the type system actually doing its job — exactly the
point of the change.
244 tests pass (was 244). Same pre-existing macOS-arm64 websocket
addon failure, unrelated.
This commit is contained in:
8 files changed
+82
-211
No files matched your search
@@ -9,7 +9,6 @@ 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');
|
||||
if (!ctx.sendLike) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.sendLike(userId, times);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -18,7 +17,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const targetId = asNumber(params.target_id) || undefined;
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
if (!ctx.sendFriendPoke) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.sendFriendPoke(userId, targetId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -27,7 +25,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const userId = asNumber(params.user_id);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
if (!ctx.sendGroupPoke) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.sendGroupPoke(groupId, userId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -37,10 +34,8 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
if (groupId) {
|
||||
if (!ctx.sendGroupPoke) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.sendGroupPoke(groupId, userId);
|
||||
} else {
|
||||
if (!ctx.sendFriendPoke) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.sendFriendPoke(userId);
|
||||
}
|
||||
return okResponse();
|
||||
@@ -53,7 +48,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!Number.isInteger(messageId) || messageId === 0) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
}
|
||||
if (!ctx.setEssenceMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setEssenceMsg(messageId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -63,7 +57,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!Number.isInteger(messageId) || messageId === 0) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
}
|
||||
if (!ctx.deleteEssenceMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.deleteEssenceMsg(messageId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -72,9 +65,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
|
||||
if (!ctx.getGroupEssenceAll) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const essenceDataAll = await ctx.getGroupEssenceAll(groupId);
|
||||
@@ -108,7 +98,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id does not match message session');
|
||||
}
|
||||
|
||||
if (!ctx.setGroupReaction) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupReaction(meta.targetId, meta.sequence, code, isSet);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -120,7 +109,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const messageId = asNumber(params.message_id) || 0;
|
||||
const count = asNumber(params.count) || 20;
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!ctx.getGroupMsgHistory) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const messages = await ctx.getGroupMsgHistory(groupId, messageId, count);
|
||||
return okResponse({ messages });
|
||||
});
|
||||
@@ -130,7 +118,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const messageId = asNumber(params.message_id) || 0;
|
||||
const count = asNumber(params.count) || 20;
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
if (!ctx.getFriendMsgHistory) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const messages = await ctx.getFriendMsgHistory(userId, messageId, count);
|
||||
return okResponse({ messages });
|
||||
});
|
||||
@@ -153,7 +140,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id does not match message session');
|
||||
}
|
||||
|
||||
if (!ctx.markGroupMsgAsRead) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
await ctx.markGroupMsgAsRead(groupId, meta.sequence);
|
||||
return okResponse();
|
||||
@@ -177,7 +163,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id does not match message session');
|
||||
}
|
||||
|
||||
if (!ctx.markPrivateMsgAsRead) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
await ctx.markPrivateMsgAsRead(userId, meta.sequence);
|
||||
return okResponse();
|
||||
@@ -198,8 +183,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'target_id does not match message session');
|
||||
}
|
||||
|
||||
if (!(ctx.markPrivateMsgAsRead && ctx.markGroupMsgAsRead)) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
if (meta.isGroup) {
|
||||
await ctx.markGroupMsgAsRead(targetId, meta.sequence);
|
||||
} else {
|
||||
@@ -239,9 +222,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and content are required');
|
||||
}
|
||||
|
||||
if (!ctx.sendGroupNotice) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const options = {
|
||||
@@ -262,9 +242,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
|
||||
if (!ctx.getGroupNotice) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const notices = await ctx.getGroupNotice(groupId);
|
||||
@@ -282,9 +259,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and fid/notice_id are required');
|
||||
}
|
||||
|
||||
if (!ctx.deleteGroupNotice) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const success = await ctx.deleteGroupNotice(groupId, fid);
|
||||
@@ -304,7 +278,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const messages = asMessage(params.messages ?? params.message);
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (messages === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'message/messages is required');
|
||||
if (!ctx.sendForwardMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
const result = await ctx.sendForwardMsg(messages);
|
||||
const data: Record<string, unknown> = {
|
||||
@@ -319,7 +292,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('upload_foward_msg', async (params) => {
|
||||
const messages = asMessage(params.messages ?? params.message);
|
||||
if (messages === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'message/messages is required');
|
||||
if (!ctx.sendForwardMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const result = await ctx.sendForwardMsg(messages);
|
||||
return okResponse({ res_id: result.forwardId, forward_id: result.forwardId, message_id: 0 });
|
||||
});
|
||||
@@ -344,7 +316,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return okResponse({ message_id: result.messageId, res_id: result.forwardId, forward_id: result.forwardId });
|
||||
}
|
||||
|
||||
if (!ctx.sendForwardMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const result = await ctx.sendForwardMsg(messages);
|
||||
return okResponse({ message_id: 0, res_id: result.forwardId, forward_id: result.forwardId });
|
||||
});
|
||||
@@ -354,7 +325,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const messages = asMessage(params.messages ?? params.message);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (messages === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'message/messages is required');
|
||||
if (!ctx.sendGroupForwardMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
const result = await ctx.sendGroupForwardMsg(groupId, messages);
|
||||
return okResponse({ message_id: result.messageId, res_id: result.forwardId, forward_id: result.forwardId });
|
||||
@@ -365,7 +335,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const messages = asMessage(params.messages ?? params.message);
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
if (messages === undefined) return failedResponse(RETCODE.BAD_REQUEST, 'message/messages is required');
|
||||
if (!ctx.sendPrivateForwardMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
const result = await ctx.sendPrivateForwardMsg(userId, messages);
|
||||
return okResponse({ message_id: result.messageId, res_id: result.forwardId, forward_id: result.forwardId });
|
||||
@@ -400,7 +369,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
}
|
||||
|
||||
if (!id) return failedResponse(RETCODE.BAD_REQUEST, 'id or message_id is required');
|
||||
if (!ctx.getForwardMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
const messages = await ctx.getForwardMsg(id);
|
||||
return okResponse({ messages });
|
||||
@@ -411,7 +379,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_image', async (params) => {
|
||||
const file = asString(params.file) || asString(params.file_id);
|
||||
if (!file) return failedResponse(RETCODE.BAD_REQUEST, 'file is required');
|
||||
if (!ctx.getImageInfo) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const info = await ctx.getImageInfo(file);
|
||||
if (info) return okResponse(info);
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'image not found in cache');
|
||||
@@ -420,7 +387,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_record', async (params) => {
|
||||
const file = asString(params.file) || asString(params.file_id);
|
||||
if (!file) return failedResponse(RETCODE.BAD_REQUEST, 'file is required');
|
||||
if (!ctx.getRecordInfo) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const info = await ctx.getRecordInfo(file);
|
||||
if (info) return okResponse(info);
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'record not found in cache');
|
||||
@@ -431,7 +397,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_cookies', async (params) => {
|
||||
const domain = asString(params.domain) || 'qun.qq.com';
|
||||
|
||||
if (!ctx.getCookiesStr) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
try {
|
||||
const cookies = await ctx.getCookiesStr(domain);
|
||||
@@ -442,7 +407,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
});
|
||||
|
||||
h.registerAction('get_csrf_token', async () => {
|
||||
if (!ctx.getCsrfToken) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
try {
|
||||
const token = await ctx.getCsrfToken();
|
||||
@@ -455,7 +419,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('get_credentials', async (params) => {
|
||||
const domain = asString(params.domain) || 'qun.qq.com';
|
||||
|
||||
if (!ctx.getCredentials) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
|
||||
try {
|
||||
const creds = await ctx.getCredentials(domain);
|
||||
@@ -489,7 +452,6 @@ 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');
|
||||
if (!ctx.setFriendRemark) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setFriendRemark(userId, remark);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -498,7 +460,6 @@ 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');
|
||||
if (!ctx.setGroupRemark) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupRemark(groupId, remark);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -510,7 +471,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!Number.isInteger(messageId) || messageId === 0 || !emojiId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'message_id and emoji_id are required');
|
||||
}
|
||||
if (!ctx.setMsgEmojiLike) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setMsgEmojiLike(messageId, emojiId, set);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -580,9 +540,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const nickname = params.nickname !== undefined ? asString(params.nickname) : undefined;
|
||||
const personalNote = params.personal_note !== undefined ? asString(params.personal_note) : undefined;
|
||||
|
||||
if (!ctx.setProfile) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setProfile(nickname, personalNote);
|
||||
@@ -603,9 +560,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'status is required');
|
||||
}
|
||||
|
||||
if (!ctx.setOnlineStatus) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setOnlineStatus(status, extStatus, batteryStatus);
|
||||
@@ -628,7 +582,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
if (!messageId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
if (!ctx.forwardSingleMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
try {
|
||||
const result = await ctx.forwardSingleMsg(messageId, { userId });
|
||||
return okResponse({ message_id: result.messageId });
|
||||
@@ -642,7 +595,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!messageId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!ctx.forwardSingleMsg) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
try {
|
||||
const result = await ctx.forwardSingleMsg(messageId, { groupId });
|
||||
return okResponse({ message_id: result.messageId });
|
||||
@@ -661,9 +613,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const start = asNumber(params.start) || 0;
|
||||
const count = asNumber(params.count) || 10;
|
||||
|
||||
if (!ctx.getProfileLike) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getProfileLike(userId, start, count);
|
||||
@@ -675,9 +624,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
h.registerAction('fetch_custom_face', async (params) => {
|
||||
const count = asNumber(params.count) || 10;
|
||||
if (!ctx.fetchCustomFace) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
try {
|
||||
const urls = await ctx.fetchCustomFace(count);
|
||||
return okResponse(urls);
|
||||
@@ -690,7 +636,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const messageId = asNumber(params.message_id);
|
||||
const emojiId = asString(params.emoji_id) || '';
|
||||
if (!messageId || !emojiId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id and emoji_id are required');
|
||||
if (!ctx.getEmojiLikes) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
try {
|
||||
const meta = ctx.getMessageMeta(messageId);
|
||||
if (!meta?.isGroup || !meta?.sequence) return failedResponse(RETCODE.BAD_REQUEST, 'message not found or not a group message');
|
||||
@@ -708,7 +653,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const count = asNumber(params.count) || 10;
|
||||
const cookie = asString(params.cookie) || '';
|
||||
if (!messageId || !emojiId) return failedResponse(RETCODE.BAD_REQUEST, 'message_id and emojiId are required');
|
||||
if (!ctx.getEmojiLikes) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
try {
|
||||
const meta = ctx.getMessageMeta(messageId);
|
||||
if (!meta?.isGroup || !meta?.sequence) return failedResponse(RETCODE.BAD_REQUEST, 'message not found or not a group message');
|
||||
@@ -759,9 +703,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid group_id');
|
||||
}
|
||||
|
||||
if (!ctx.getGroupAtAllRemain) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getGroupAtAllRemain(groupId);
|
||||
@@ -772,9 +713,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
});
|
||||
|
||||
h.registerAction('get_unidirectional_friend_list', async () => {
|
||||
if (!ctx.getUnidirectionalFriendList) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getUnidirectionalFriendList();
|
||||
@@ -791,9 +729,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid longNick');
|
||||
}
|
||||
|
||||
if (!ctx.setSelfLongNick) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setSelfLongNick(longNick);
|
||||
@@ -815,9 +750,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const file = asString(params.file);
|
||||
if (!file) return failedResponse(RETCODE.BAD_REQUEST, 'file is required');
|
||||
|
||||
if (!ctx.setAvatar) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setAvatar(file);
|
||||
@@ -840,9 +772,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid event_type');
|
||||
}
|
||||
|
||||
if (!ctx.setInputStatus) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.setInputStatus(userId, eventType);
|
||||
@@ -861,9 +790,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
|
||||
const words = rawWords.map(w => String(w));
|
||||
|
||||
if (!ctx.translateEn2Zh) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const translated = await ctx.translateEn2Zh(words);
|
||||
@@ -874,9 +800,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
});
|
||||
|
||||
h.registerAction('get_clientkey', async () => {
|
||||
if (!ctx.forceFetchClientKey) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
}
|
||||
const clientKeyInfo = await ctx.forceFetchClientKey();
|
||||
if (!clientKeyInfo.clientKey) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'get clientkey error');
|
||||
@@ -891,9 +814,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const picUrl = params.picUrl || params.pic_url || '';
|
||||
const jumpUrl = params.jumpUrl || params.jump_url || '';
|
||||
|
||||
if (!ctx.getMiniAppArk) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.getMiniAppArk(
|
||||
@@ -920,9 +840,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'missing required parameters');
|
||||
}
|
||||
|
||||
if (!ctx.clickInlineKeyboardButton) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await ctx.clickInlineKeyboardButton(
|
||||
@@ -945,9 +862,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'invalid group_id');
|
||||
}
|
||||
|
||||
if (!ctx.sendGroupSign) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
}
|
||||
|
||||
try {
|
||||
await ctx.sendGroupSign(groupId);
|
||||
|
||||
@@ -24,7 +24,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const block = asBoolean(params.block, false);
|
||||
if (!userId) return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
if (!ctx.handleDeleteFriend) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.handleDeleteFriend(userId, block);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -8,7 +8,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const reject = asBoolean(params.reject_add_request, false);
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
if (!ctx.setGroupKick) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupKick(groupId, userId, reject);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -18,7 +17,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userIds = Array.isArray(params.user_id) ? params.user_id.map(asNumber).filter(Boolean) : [];
|
||||
const reject = asBoolean(params.reject_add_request, false);
|
||||
if (!groupId || userIds.length === 0) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id array are required');
|
||||
if (!ctx.setGroupKickMembers) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupKickMembers(groupId, userIds, reject);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -28,7 +26,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const userId = asNumber(params.user_id);
|
||||
const duration = asNumber(params.duration) || 1800;
|
||||
if (!groupId || !userId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and user_id are required');
|
||||
if (!ctx.setGroupBan) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupBan(groupId, userId, duration);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -37,7 +34,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const groupId = asNumber(params.group_id);
|
||||
const enable = asBoolean(params.enable, true);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!ctx.setGroupWholeBan) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupWholeBan(groupId, enable);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -46,7 +42,6 @@ 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');
|
||||
if (!ctx.setGroupAddOption) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupAddOption(groupId, addType);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -54,7 +49,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('set_group_search', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!ctx.setGroupSearch) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupSearch(groupId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -64,7 +58,6 @@ 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');
|
||||
if (!ctx.setGroupAdmin) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupAdmin(groupId, userId, enable);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -74,7 +67,6 @@ 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');
|
||||
if (!ctx.setGroupCard) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupCard(groupId, userId, card);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -83,7 +75,6 @@ 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');
|
||||
if (!ctx.setGroupName) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupName(groupId, name);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -91,7 +82,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
h.registerAction('set_group_leave', async (params) => {
|
||||
const groupId = asNumber(params.group_id);
|
||||
if (!groupId) return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
if (!ctx.setGroupLeave) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupLeave(groupId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -101,7 +91,6 @@ 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');
|
||||
if (!ctx.setGroupSpecialTitle) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.setGroupSpecialTitle(groupId, userId, title);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
@@ -11,7 +11,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const folderId = asString(params.folder) || asString(params.folder_id) || '/';
|
||||
const uploadFile = asBoolean(params.upload_file, true);
|
||||
if (!groupId || !file) return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file are required');
|
||||
if (!ctx.uploadGroupFile) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const fileId = await ctx.uploadGroupFile(groupId, file, name, folderId, uploadFile);
|
||||
return okResponse({ file_id: fileId });
|
||||
});
|
||||
@@ -22,7 +21,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const name = asString(params.name);
|
||||
const uploadFile = asBoolean(params.upload_file, true);
|
||||
if (!userId || !file) return failedResponse(RETCODE.BAD_REQUEST, 'user_id and file are required');
|
||||
if (!ctx.uploadPrivateFile) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
const fileId = await ctx.uploadPrivateFile(userId, file, name, uploadFile);
|
||||
return okResponse({ file_id: fileId });
|
||||
});
|
||||
@@ -34,7 +32,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file_id are required');
|
||||
}
|
||||
if (!ctx.getGroupFileUrl) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
return okResponse({ url: await ctx.getGroupFileUrl(groupId, fileId, busId) });
|
||||
});
|
||||
|
||||
@@ -43,7 +40,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
}
|
||||
if (!ctx.getGroupFiles) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
return okResponse(await ctx.getGroupFiles(groupId, '/'));
|
||||
});
|
||||
|
||||
@@ -53,7 +49,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
}
|
||||
if (!ctx.getGroupFiles) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
return okResponse(await ctx.getGroupFiles(groupId, folderId));
|
||||
});
|
||||
|
||||
@@ -63,7 +58,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !fileId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and file_id are required');
|
||||
}
|
||||
if (!ctx.deleteGroupFile) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.deleteGroupFile(groupId, fileId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -76,7 +70,6 @@ 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');
|
||||
}
|
||||
if (!ctx.moveGroupFile) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.moveGroupFile(groupId, fileId, parentDirectory, targetDirectory);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -88,7 +81,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !name) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and name are required');
|
||||
}
|
||||
if (!ctx.createGroupFileFolder) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.createGroupFileFolder(groupId, name, parentId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -99,7 +91,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!groupId || !folderId) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id and folder_id are required');
|
||||
}
|
||||
if (!ctx.deleteGroupFileFolder) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.deleteGroupFileFolder(groupId, folderId);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -111,7 +102,6 @@ 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');
|
||||
}
|
||||
if (!ctx.renameGroupFileFolder) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.renameGroupFileFolder(groupId, folderId, newName);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -123,7 +113,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!userId || !fileId || !fileHash) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id, file_id and file_hash are required');
|
||||
}
|
||||
if (!ctx.getPrivateFileUrl) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
return okResponse({ url: await ctx.getPrivateFileUrl(userId, fileId, fileHash) });
|
||||
});
|
||||
}
|
||||
@@ -61,9 +61,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
}
|
||||
|
||||
if (!ctx.getGroupHonorInfo) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
||||
}
|
||||
|
||||
const typeValues = Object.values(WebHonorType) as string[];
|
||||
if (!typeValues.includes(typeStr)) {
|
||||
|
||||
@@ -18,9 +18,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!Number.isInteger(groupId) || groupId <= 0) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'group_id is required');
|
||||
}
|
||||
if (!ctx.sendGroupMessage) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'send_group_msg is not implemented');
|
||||
}
|
||||
const result = await ctx.sendGroupMessage(groupId, message, autoEscape);
|
||||
return okResponse({ message_id: result.messageId });
|
||||
}
|
||||
@@ -29,9 +26,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!Number.isInteger(userId) || userId <= 0) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'user_id is required');
|
||||
}
|
||||
if (!ctx.sendPrivateMessage) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'send_private_msg is not implemented');
|
||||
}
|
||||
const result = await ctx.sendPrivateMessage(userId, message, autoEscape);
|
||||
return okResponse({ message_id: result.messageId });
|
||||
});
|
||||
@@ -47,9 +41,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (message === undefined) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'message is required');
|
||||
}
|
||||
if (!ctx.sendPrivateMessage) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'send_private_msg is not implemented');
|
||||
}
|
||||
|
||||
const result = await ctx.sendPrivateMessage(userId, message, autoEscape);
|
||||
return okResponse({ message_id: result.messageId });
|
||||
@@ -66,9 +57,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (message === undefined) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'message is required');
|
||||
}
|
||||
if (!ctx.sendGroupMessage) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'send_group_msg is not implemented');
|
||||
}
|
||||
|
||||
const result = await ctx.sendGroupMessage(groupId, message, autoEscape);
|
||||
return okResponse({ message_id: result.messageId });
|
||||
@@ -97,9 +85,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
if (!Number.isInteger(messageId) || messageId === 0) {
|
||||
return failedResponse(RETCODE.BAD_REQUEST, 'message_id is required');
|
||||
}
|
||||
if (!ctx.deleteMessage) {
|
||||
return failedResponse(RETCODE.ACTION_FAILED, 'delete_msg is not implemented');
|
||||
}
|
||||
|
||||
const meta = ctx.getMessageMeta(messageId);
|
||||
if (!meta) {
|
||||
|
||||
@@ -7,7 +7,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const flag = asString(params.flag);
|
||||
const approve = asBoolean(params.approve, true);
|
||||
if (!flag) return failedResponse(RETCODE.BAD_REQUEST, 'flag is required');
|
||||
if (!ctx.handleFriendRequest) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.handleFriendRequest(flag, approve);
|
||||
return okResponse();
|
||||
});
|
||||
@@ -18,7 +17,6 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
||||
const approve = asBoolean(params.approve, true);
|
||||
const reason = asString(params.reason);
|
||||
if (!flag) return failedResponse(RETCODE.BAD_REQUEST, 'flag is required');
|
||||
if (!ctx.handleGroupRequest) return failedResponse(RETCODE.ACTION_FAILED, 'not implemented');
|
||||
await ctx.handleGroupRequest(flag, subType, approve, reason);
|
||||
return okResponse();
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user