feat: implement upload group avatar
This commit is contained in:
1 parent
00a70b1ccc
commit
b176e929b9
6 files changed
+49
-2
No files matched your search
@@ -151,3 +151,32 @@ export async function getGroupAtAllRemain(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ─────────────── group avatar ───────────────
|
||||||
|
|
||||||
|
export async function setGroupAvatar(
|
||||||
|
bridge: Bridge,
|
||||||
|
groupId: number,
|
||||||
|
source: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const { loadBinarySource, computeHashes } = await import('../highway/utils');
|
||||||
|
const { fetchHighwaySession, uploadHighwayHttp } = await import('../highway/highway-client');
|
||||||
|
const { protoEncode } = await import('../../protobuf/decode');
|
||||||
|
const { GroupAvatarUploadExtSchema } = await import('../proto/highway');
|
||||||
|
|
||||||
|
const loaded = await loadBinarySource(source, 'group avatar');
|
||||||
|
if (!loaded.bytes.length) throw new Error('group avatar file is empty');
|
||||||
|
|
||||||
|
const extend = protoEncode({
|
||||||
|
field1: 101,
|
||||||
|
groupId: BigInt(groupId),
|
||||||
|
field3: new Uint8Array([0x08, 0x01, 0x12, 0x00]),
|
||||||
|
field5: 3,
|
||||||
|
field6: 0,
|
||||||
|
}, GroupAvatarUploadExtSchema);
|
||||||
|
|
||||||
|
const hashes = computeHashes(loaded.bytes);
|
||||||
|
const session = await fetchHighwaySession(bridge);
|
||||||
|
|
||||||
|
await uploadHighwayHttp(bridge, session, 3000, loaded.bytes, hashes.md5, extend);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ import {
|
|||||||
setGroupSpecialTitle as setGroupSpecialTitle_,
|
setGroupSpecialTitle as setGroupSpecialTitle_,
|
||||||
setGroupRemark as setGroupRemark_,
|
setGroupRemark as setGroupRemark_,
|
||||||
getGroupAtAllRemain as getGroupAtAllRemain_,
|
getGroupAtAllRemain as getGroupAtAllRemain_,
|
||||||
|
setGroupAvatar as setGroupAvatar_,
|
||||||
} from './actions/group-admin';
|
} from './actions/group-admin';
|
||||||
import {
|
import {
|
||||||
uploadGroupFile as uploadGroupFile_,
|
uploadGroupFile as uploadGroupFile_,
|
||||||
@@ -631,6 +632,7 @@ export class Bridge {
|
|||||||
async markPrivateMsgAsRead(userId: number, sequence: number): Promise<void> { return markPrivateMsgAsRead_(this, userId, sequence); }
|
async markPrivateMsgAsRead(userId: number, sequence: number): Promise<void> { return markPrivateMsgAsRead_(this, userId, sequence); }
|
||||||
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
|
async setFriendRemark(userId: number, remark: string): Promise<void> { return setFriendRemark_(this, userId, remark); }
|
||||||
async setGroupRemark(groupId: number, remark: string): Promise<void> { return setGroupRemark_(this, groupId, remark); }
|
async setGroupRemark(groupId: number, remark: string): Promise<void> { return setGroupRemark_(this, groupId, remark); }
|
||||||
|
async setGroupAvatar(groupId: number, source: string): Promise<void> { return setGroupAvatar_(this, groupId, source); }
|
||||||
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
async getGroupHonorInfo(groupId: number, type: WebHonorType | string): Promise<any> {
|
||||||
return getGroupHonorInfo_(this, groupId, type);
|
return getGroupHonorInfo_(this, groupId, type);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,3 +334,13 @@ export const NTV2UploadRichMediaRespSchema = {
|
|||||||
respHead: { field: 1, type: 'message' as const, schema: NTV2UploadRespHeadSchema },
|
respHead: { field: 1, type: 'message' as const, schema: NTV2UploadRespHeadSchema },
|
||||||
upload: { field: 2, type: 'message' as const, schema: NTV2UploadRespBodySchema },
|
upload: { field: 2, type: 'message' as const, schema: NTV2UploadRespBodySchema },
|
||||||
} satisfies ProtoSchema;
|
} satisfies ProtoSchema;
|
||||||
|
|
||||||
|
// --- Group Avatar Upload Extend ---
|
||||||
|
|
||||||
|
export const GroupAvatarUploadExtSchema = {
|
||||||
|
field1: { field: 1, type: 'uint32' as const },
|
||||||
|
groupId: { field: 2, type: 'uint64' as const },
|
||||||
|
field3: { field: 3, type: 'bytes' as const },
|
||||||
|
field5: { field: 5, type: 'uint32' as const },
|
||||||
|
field6: { field: 6, type: 'uint32' as const },
|
||||||
|
} satisfies ProtoSchema;
|
||||||
@@ -103,7 +103,11 @@ export function register(h: ApiHandler, ctx: ApiActionContext): void {
|
|||||||
return okResponse();
|
return okResponse();
|
||||||
});
|
});
|
||||||
|
|
||||||
h.registerAction('set_group_portrait', async () => {
|
h.registerAction('set_group_portrait', async (params) => {
|
||||||
return failedResponse(RETCODE.ACTION_FAILED, 'not yet implemented');
|
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();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -106,6 +106,7 @@ export interface ApiActionContext {
|
|||||||
// Extended NapCat-compatible
|
// Extended NapCat-compatible
|
||||||
setFriendRemark: (userId: number, remark: string) => Promise<void>;
|
setFriendRemark: (userId: number, remark: string) => Promise<void>;
|
||||||
setGroupRemark: (groupId: 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 }>;
|
getGroupFileCount: (groupId: number) => Promise<{ fileCount: number; maxCount: number }>;
|
||||||
setMsgEmojiLike: (messageId: number, emojiId: string, set: boolean) => Promise<void>;
|
setMsgEmojiLike: (messageId: number, emojiId: string, set: boolean) => Promise<void>;
|
||||||
markGroupMsgAsRead: (groupId: number, sequence: number) => Promise<void>;
|
markGroupMsgAsRead: (groupId: number, sequence: number) => Promise<void>;
|
||||||
|
|||||||
@@ -171,6 +171,7 @@ export function buildApiContext(ref: OneBotInstanceContext): ApiActionContext {
|
|||||||
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
forceFetchClientKey: () => bridge.forceFetchClientKey(),
|
||||||
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
setFriendRemark: (userId, remark) => bridge.setFriendRemark(userId, remark),
|
||||||
setGroupRemark: (groupId, remark) => bridge.setGroupRemark(groupId, remark),
|
setGroupRemark: (groupId, remark) => bridge.setGroupRemark(groupId, remark),
|
||||||
|
setGroupAvatar: (groupId, source) => bridge.setGroupAvatar(groupId, source),
|
||||||
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
getGroupFileCount: (groupId) => bridge.fetchGroupFileCount(groupId),
|
||||||
setMsgEmojiLike: async (messageId, emojiId, set) => {
|
setMsgEmojiLike: async (messageId, emojiId, set) => {
|
||||||
const meta = messageStore.findMeta(messageId);
|
const meta = messageStore.findMeta(messageId);
|
||||||
|
|||||||
Reference in new issue
Block a user