feat(onebot): add Qzone profile read and update actions (#586)
Add actions to read a space name and description and update the current account profile. Preserve omitted fields and support explicit empty values, with matching SDK types, MCP discovery, documentation, and tests.
This commit is contained in:
16 files changed
+862
-3
No files matched your search
@@ -4,16 +4,20 @@ import {
|
||||
getQzoneFeeds,
|
||||
getQzoneMsgDetail,
|
||||
getQzoneMsgList,
|
||||
getQzoneProfile,
|
||||
publishQzoneMsg,
|
||||
replyQzoneComment,
|
||||
setQzoneBlack,
|
||||
setQzoneLike,
|
||||
setQzoneProfile,
|
||||
updateQzoneMsgRight,
|
||||
uploadQzoneImageFromSource,
|
||||
type QzoneCommentResult,
|
||||
type QzoneFeedsPage,
|
||||
type QzoneMsgDetailResult,
|
||||
type QzoneMsgListResult,
|
||||
type QzoneProfile,
|
||||
type QzoneProfileUpdate,
|
||||
type QzonePublishResult,
|
||||
type QzoneReplyTarget,
|
||||
type QzoneUpdateRightResult,
|
||||
@@ -30,6 +34,16 @@ import type { BridgeContext } from '../bridge-context';
|
||||
export class QzoneApi {
|
||||
constructor(private readonly ctx: BridgeContext) {}
|
||||
|
||||
async getProfile(targetUin?: number): Promise<QzoneProfile> {
|
||||
const cookieObject = await this.ctx.apis.web.getCookies('qzone.qq.com');
|
||||
return getQzoneProfile(cookieObject, this.ctx.identity.uin, targetUin?.toString());
|
||||
}
|
||||
|
||||
async setProfile(profile: QzoneProfileUpdate): Promise<void> {
|
||||
const cookieObject = await this.ctx.apis.web.getCookies('qzone.qq.com');
|
||||
await setQzoneProfile(cookieObject, this.ctx.identity.uin, profile);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取说说列表。`targetUin` 省略时取机器人自己的空间。
|
||||
* `pos` 为起始偏移,`num` 为本页数量(服务端上限约 20/页)。
|
||||
|
||||
@@ -20,6 +20,61 @@ describe('apis/qzone', () => {
|
||||
return { bridge, getCookies, fetchSpy };
|
||||
}
|
||||
|
||||
it.each([undefined, 20002])(
|
||||
'getProfile reads owner %s with the current account credentials',
|
||||
async (targetUin) => {
|
||||
const { bridge, getCookies } = bridgeWithWeb();
|
||||
const profile = { name: 'My space', description: 'Notes' };
|
||||
const getProfile = vi.spyOn(qzoneWeb, 'getQzoneProfile').mockResolvedValue(profile);
|
||||
|
||||
expect(await new QzoneApi(bridge as never).getProfile(targetUin)).toEqual(profile);
|
||||
expect(getCookies).toHaveBeenCalledWith('qzone.qq.com');
|
||||
expect(getProfile).toHaveBeenCalledWith(
|
||||
{ p_skey: 'PSK' },
|
||||
'10001',
|
||||
targetUin?.toString(),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it('getProfile propagates cookie and protocol failures', async () => {
|
||||
const { bridge, getCookies } = bridgeWithWeb();
|
||||
const api = new QzoneApi(bridge as never);
|
||||
const getProfile = vi
|
||||
.spyOn(qzoneWeb, 'getQzoneProfile')
|
||||
.mockRejectedValue(new Error('denied'));
|
||||
|
||||
await expect(api.getProfile(20002)).rejects.toThrow('denied');
|
||||
getCookies.mockRejectedValueOnce(new Error('cookie failure'));
|
||||
await expect(api.getProfile()).rejects.toThrow('cookie failure');
|
||||
expect(getProfile).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([{ name: 'New name' }, { description: '' }, { name: '', description: 'New notes' }])(
|
||||
'setProfile writes only the supplied fields to the current account (%j)',
|
||||
async (profile) => {
|
||||
const { bridge, getCookies } = bridgeWithWeb();
|
||||
const setProfile = vi.spyOn(qzoneWeb, 'setQzoneProfile').mockResolvedValue();
|
||||
|
||||
await new QzoneApi(bridge as never).setProfile(profile);
|
||||
expect(getCookies).toHaveBeenCalledWith('qzone.qq.com');
|
||||
expect(setProfile).toHaveBeenCalledWith({ p_skey: 'PSK' }, '10001', profile);
|
||||
},
|
||||
);
|
||||
|
||||
it('setProfile propagates cookie and protocol failures', async () => {
|
||||
const { bridge, getCookies } = bridgeWithWeb();
|
||||
const api = new QzoneApi(bridge as never);
|
||||
const setProfile = vi
|
||||
.spyOn(qzoneWeb, 'setQzoneProfile')
|
||||
.mockRejectedValue(new Error('captcha required'));
|
||||
|
||||
await expect(api.setProfile({ name: 'New name' })).rejects.toThrow('captcha required');
|
||||
getCookies.mockRejectedValueOnce(new Error('cookie failure'));
|
||||
await expect(api.setProfile({ description: 'Notes' })).rejects.toThrow('cookie failure');
|
||||
expect(setProfile).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it.each([undefined, 20002])(
|
||||
'getMsgDetail uses current-account credentials for owner %s',
|
||||
async (targetUin) => {
|
||||
|
||||
Reference in new issue
Block a user