fix(onebot): distinguish group invitation identities
Expose joining members, inviters and request operators separately. Preserve existing notice fields and report unavailable invitation identities explicitly. Refs #643
This commit is contained in:
20 files changed
+853
-63
No files matched your search
@@ -19,6 +19,8 @@ SnowLuma 的 TypeScript SDK,提供 OneBot HTTP / WebSocket 客户端、事件
|
||||
- [项目结构](#项目结构)
|
||||
- [版本策略](#版本策略)
|
||||
|
||||
群申请中的入群者、邀请人和审批人,以及入群通知的身份可用状态,见[群邀请与入群身份](../onebot/GROUP_REQUESTS.md)。
|
||||
|
||||
## 安装
|
||||
|
||||
在本 monorepo 内直接通过 workspace 引用:
|
||||
|
||||
@@ -161,6 +161,7 @@ import type {
|
||||
GroupFileUrl,
|
||||
GroupMessageHistory,
|
||||
GroupNoticeInfo,
|
||||
GroupSystemMessage,
|
||||
GroupTodoListItem,
|
||||
LoginInfo,
|
||||
MediaInfo,
|
||||
@@ -242,7 +243,7 @@ export interface SnowLumaActionMap {
|
||||
get_group_member_list: { params: GetGroupMemberListParams; data: JsonObject[] };
|
||||
get_group_member_info: { params: GetGroupMemberInfoParams; data: JsonObject };
|
||||
get_group_honor_info: { params: GetGroupHonorInfoParams; data: JsonValue };
|
||||
get_group_system_msg: { params: GetGroupSystemMsgParams; data: JsonObject[] };
|
||||
get_group_system_msg: { params: GetGroupSystemMsgParams; data: GroupSystemMessage[] };
|
||||
set_group_kick: { params: SetGroupKickParams; data: EmptyData };
|
||||
set_group_kick_members: { params: SetGroupKickMembersParams; data: EmptyData };
|
||||
set_group_ban: { params: SetGroupBanParams; data: EmptyData };
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { JsonObject, JsonValue } from './json.js';
|
||||
import type { GroupIdentityStatus } from './results.js';
|
||||
|
||||
export interface OneBotBaseEvent extends JsonObject {
|
||||
time: number;
|
||||
@@ -52,6 +53,17 @@ export interface OneBotNoticeEvent extends OneBotBaseEvent {
|
||||
notice_type: string;
|
||||
}
|
||||
|
||||
export interface OneBotGroupIncreaseEvent extends OneBotNoticeEvent {
|
||||
notice_type: 'group_increase';
|
||||
sub_type: 'approve' | 'invite';
|
||||
group_id: number;
|
||||
user_id: number;
|
||||
operator_id: number;
|
||||
/** Independent inviter, when QQ supplies one. Zero does not prove absence. */
|
||||
invitor_id?: number;
|
||||
invitor_status?: GroupIdentityStatus;
|
||||
}
|
||||
|
||||
export type BotStatusSubType = 'online' | 'offline';
|
||||
|
||||
/** Bridge session edge. Not KickNT `bot_offline`. */
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
import type { OneBotPrivateMessageEvent } from './events.js';
|
||||
import type { JsonArray, JsonObject, JsonValue } from './json.js';
|
||||
|
||||
/** Unknown includes missing information; it does not mean that no such person exists. */
|
||||
export type GroupIdentityStatus = 'known' | 'unknown';
|
||||
|
||||
export interface GroupSystemMessage extends JsonObject {
|
||||
group_id: number;
|
||||
group_name: string;
|
||||
request_id: number;
|
||||
requester_uin: number;
|
||||
requester_nick: string;
|
||||
invitor_uin: number;
|
||||
invitor_nick: string;
|
||||
message: string;
|
||||
checked: boolean;
|
||||
flag: string;
|
||||
/** Always the applicant or invitee; unlike requester_uin on self invitations. */
|
||||
target_uin?: number;
|
||||
target_nick?: string;
|
||||
target_status?: GroupIdentityStatus;
|
||||
invitor_status?: GroupIdentityStatus;
|
||||
/** The person who handled the request, not necessarily the inviter. */
|
||||
operator_uin?: number;
|
||||
operator_nick?: string;
|
||||
operator_status?: GroupIdentityStatus;
|
||||
}
|
||||
|
||||
export interface QzoneCommentReply {
|
||||
uin: number;
|
||||
name: string;
|
||||
|
||||
@@ -43,6 +43,12 @@ export type QuickAlias = AssertTrue<
|
||||
declare const http: SnowLumaHttpClient;
|
||||
declare const ws: SnowLumaWebSocketClient;
|
||||
|
||||
const groupSystemMessages = await http.getGroupSystemMessages({ groupId: 10001 });
|
||||
export const invitationTarget: number | undefined = groupSystemMessages[0]?.target_uin;
|
||||
export const invitationOperator: number | undefined = groupSystemMessages[0]?.operator_uin;
|
||||
export const invitationIdentityStatus: 'known' | 'unknown' | undefined =
|
||||
groupSystemMessages[0]?.invitor_status;
|
||||
|
||||
const adminPermissions = await http.raw('get_group_admin_permissions', {
|
||||
group_id: 10001,
|
||||
user_id: 10002,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, expectTypeOf, it, vi } from 'vitest';
|
||||
import type { QzoneMsgDetailResult, QzoneProfileResult } from '../src';
|
||||
import type { GroupSystemMessage, QzoneMsgDetailResult, QzoneProfileResult } from '../src';
|
||||
import {
|
||||
SnowLumaAbortError,
|
||||
SnowLumaApiError,
|
||||
@@ -9,6 +9,37 @@ import {
|
||||
} from '../src';
|
||||
|
||||
describe('SnowLumaHttpClient', () => {
|
||||
it('retains independent group request actors and supports old servers', async () => {
|
||||
const legacy: GroupSystemMessage = {
|
||||
group_id: 90001,
|
||||
group_name: 'group',
|
||||
request_id: 1,
|
||||
requester_uin: 10002,
|
||||
requester_nick: 'member',
|
||||
invitor_uin: 10004,
|
||||
invitor_nick: 'inviter',
|
||||
message: '',
|
||||
checked: true,
|
||||
flag: 'request-1',
|
||||
};
|
||||
const current: GroupSystemMessage = {
|
||||
...legacy,
|
||||
target_uin: 10002,
|
||||
target_status: 'known',
|
||||
operator_uin: 10003,
|
||||
operator_status: 'known',
|
||||
invitor_status: 'known',
|
||||
};
|
||||
const fetchImpl = vi.fn(
|
||||
async () =>
|
||||
new Response(JSON.stringify({ status: 'ok', retcode: 0, data: [current, legacy] })),
|
||||
);
|
||||
const client = new SnowLumaHttpClient({ fetch: fetchImpl });
|
||||
const result = await client.getGroupSystemMessages({ groupId: 90001 });
|
||||
expectTypeOf(result).toEqualTypeOf<GroupSystemMessage[]>();
|
||||
expect(result).toEqual([current, legacy]);
|
||||
expect(result[1]).not.toHaveProperty('invitor_status');
|
||||
});
|
||||
it('reads typed space profiles for the current and an explicit account', async () => {
|
||||
const data: QzoneProfileResult = { name: 'Space', description: 'Description' };
|
||||
const fetchImpl = vi
|
||||
|
||||
Reference in new issue
Block a user