diff --git a/src/ntqqapi/api/group.ts b/src/ntqqapi/api/group.ts index d6507d9..9c4fd31 100644 --- a/src/ntqqapi/api/group.ts +++ b/src/ntqqapi/api/group.ts @@ -8,7 +8,8 @@ import { GetFileListParam, PublishGroupBulletinReq, GroupAllInfo, - GroupFileInfo + GroupFileInfo, + GroupBulletinListResult } from '../types' import { invoke, NTClass, NTMethod } from '../ntcall' import { GeneralCallResult } from '../services' @@ -347,4 +348,33 @@ export class NTQQGroupApi extends Service { } ) } + + async getGroupBulletinList(groupCode: string) { + invoke('nodeIKernelGroupListener/onGetGroupBulletinListResult', [], { registerEvent: true }) + const ntUserApi = this.ctx.get('ntUserApi')! + const psKey = (await ntUserApi.getPSkey(['qun.qq.com'])).domainPskeyMap.get('qun.qq.com')! + return await invoke<{ + groupCode: string + context: string + result: GroupBulletinListResult + }>( + 'nodeIKernelGroupService/getGroupBulletinList', + [{ + groupCode, + psKey, + context: '', + req: { + startIndex: -1, + num: 20, + needInstructionsForJoinGroup: 1, + needPublisherInfo: 1 + } + }], + { + cbCmd: 'nodeIKernelGroupListener/onGetGroupBulletinListResult', + cmdCB: payload => payload.groupCode === groupCode, + afterFirstCmd: false + } + ) + } } diff --git a/src/ntqqapi/types/group.ts b/src/ntqqapi/types/group.ts index 72a3885..2dcee1f 100644 --- a/src/ntqqapi/types/group.ts +++ b/src/ntqqapi/types/group.ts @@ -22,9 +22,9 @@ export interface Group { hasModifyConfGroupName: boolean remarkName: string hasMemo: boolean - groupShutupExpireTime: string //"0", - personShutupExpireTime: string //"0", - discussToGroupUin: string //"0", + groupShutupExpireTime: string + personShutupExpireTime: string + discussToGroupUin: string discussToGroupMaxMsgSeq: number discussToGroupTime: number groupFlagExt: number //1073938496, @@ -32,8 +32,8 @@ export interface Group { groupCreditLevel: number //0, groupFlagExt3: number //0, groupOwnerId: { - memberUin: string //"0", - memberUid: string //"u_fbf8N7aeuZEnUiJAbQ9R8Q" + memberUin: string + memberUid: string } members: GroupMember[] // 原始数据是没有这个的,为了方便自己加了这个字段 createTime: string @@ -120,3 +120,55 @@ export interface GroupAllInfo { joinGroupAuth: string isAllowModifyConfGroupName: number } + +export interface GroupBulletinListResult { + groupCode: string + srvCode: number + readOnly: number + role: number + inst: unknown[] + feeds: { + uin: string + feedId: string + publishTime: string + msg: { + text: string + textFace: string + pics: { + id: string + width: number + height: number + }[] + title: string + } + type: number + fn: number + cn: number + vn: number + settings: { + isShowEditCard: number + remindTs: number + tipWindowType: number + confirmRequired: number + } + pinned: number + readNum: number + is_read: number + is_all_confirm: number + }[] + groupInfo: { + groupCode: string + classId: number + } + gln: number + tst: number + publisherInfos: { + uin: string + nick: string + avatar: string + }[] + server_time: string + svrt: string + nextIndex: number + jointime: string +} diff --git a/src/onebot11/action/go-cqhttp/GetGroupNotice.ts b/src/onebot11/action/go-cqhttp/GetGroupNotice.ts new file mode 100644 index 0000000..6bfbd51 --- /dev/null +++ b/src/onebot11/action/go-cqhttp/GetGroupNotice.ts @@ -0,0 +1,48 @@ +import { BaseAction, Schema } from '../BaseAction' +import { ActionName } from '../types' + +interface Payload { + group_id: number | string +} + +interface Notice { + sender_id: number + publish_time: number + message: { + text: string + images: { + height: string + width: string + id: string + }[] + } +} + +export class GetGroupNotice extends BaseAction { + actionName = ActionName.GoCQHTTP_GetGroupNotice + payloadSchema = Schema.object({ + group_id: Schema.union([Number, String]).required() + }) + + protected async _handle(payload: Payload) { + const data = await this.ctx.ntGroupApi.getGroupBulletinList(payload.group_id.toString()) + const result: Notice[] = [] + for (const feed of data.result.feeds) { + result.push({ + sender_id: +feed.uin, + publish_time: +feed.publishTime, + message: { + text: feed.msg.text, + images: feed.msg.pics.map(image => { + return { + height: String(image.height), + width: String(image.width), + id: image.id + } + }) + } + }) + } + return result + } +} diff --git a/src/onebot11/action/index.ts b/src/onebot11/action/index.ts index d037dfe..1558639 100644 --- a/src/onebot11/action/index.ts +++ b/src/onebot11/action/index.ts @@ -70,6 +70,7 @@ import { GetFriendWithCategory } from './llonebot/GetFriendWithCategory' import { UploadGroupFile } from './go-cqhttp/UploadGroupFile' import { UploadPrivateFile } from './go-cqhttp/UploadPrivateFile' import { GetGroupFileUrl } from './go-cqhttp/GetGroupFileUrl' +import { GetGroupNotice } from './go-cqhttp/GetGroupNotice' export function initActionMap(adapter: Adapter) { const actionHandlers = [ @@ -144,7 +145,8 @@ export function initActionMap(adapter: Adapter) { new GetGroupRootFiles(adapter), new SendGroupNotice(adapter), new GetGroupFilesByFolder(adapter), - new GetGroupFileUrl(adapter) + new GetGroupFileUrl(adapter), + new GetGroupNotice(adapter), ] const actionMap = new Map>() for (const action of actionHandlers) { diff --git a/src/onebot11/action/types.ts b/src/onebot11/action/types.ts index 8dda7bf..2cb911f 100644 --- a/src/onebot11/action/types.ts +++ b/src/onebot11/action/types.ts @@ -82,5 +82,6 @@ export enum ActionName { GoCQHTTP_GetGroupRootFiles = 'get_group_root_files', GoCQHTTP_SendGroupNotice = '_send_group_notice', GoCQHTTP_GetGroupFilesByFolder = 'get_group_files_by_folder', - GoCQHTTP_GetGroupFileUrl = 'get_group_file_url' + GoCQHTTP_GetGroupFileUrl = 'get_group_file_url', + GoCQHTTP_GetGroupNotice = '_get_group_notice', }