Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 支持撤回消息 #28

Merged
merged 1 commit into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ export class QQBotApi extends EventEmitter {
}
}

/**
* delete请求
* @param url 请求地址
* @param options 请求参数
*/
async delete (url: string) {
try {
return await got.delete(url, { headers: this.headers })
} catch (error: any) {
logger.error(`[got] 请求错误: ${JSON.stringify(error.response.body)}`)
}
}

/**
* 获取调用凭证
* @param clientSecret 开发者的Secret
Expand Down Expand Up @@ -340,6 +353,18 @@ export class QQBotApi extends EventEmitter {
return JSON.parse(result.body) as SendMessageResponse
}

/**
* 撤回消息
* @param openid 用户、群openid
* @param type 请求路径类型
* @param message_id 消息id
*/
async recallMessage (openid: string, type: PathType, message_id: string) {
const url = this.buildUrl(openid, type, V2ApiType.Message)
const result = await this.delete(`${url}/${message_id}`) as any
return result.status === 200
}

/**
* 构建发送文本消息请求参数
*/
Expand Down
5 changes: 4 additions & 1 deletion src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
raw_message: '',
}

const e = new KarinMessage(message)

Check failure on line 127 in src/core/index.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ event: EventType.Message; sub_event: MessageSubType.GroupMessage; raw_event: GroupAtMessageCreateEvent; event_id: string; self_id: string; user_id: string; ... 7 more ...; raw_message: string; }' is not assignable to parameter of type 'BaseEventDataType & { event: EventType.Message; sub_event: MessageSubType; message_id: string; message_seq?: number | undefined; elements: KarinElement[]; }'.
e.bot = this
e.replyCallback = async elements => await this._sendNsg(e, elements, PathType.Groups, e.contact.peer, e.message_id)

Expand Down Expand Up @@ -161,7 +161,7 @@
raw_message: '',
}

const e = new KarinMessage(message)

Check failure on line 164 in src/core/index.ts

View workflow job for this annotation

GitHub Actions / build

Argument of type '{ event: EventType.Message; sub_event: MessageSubType.PrivateMessage; raw_event: C2CMessageCreateEvent; event_id: string; self_id: string; user_id: string; ... 7 more ...; raw_message: string; }' is not assignable to parameter of type 'BaseEventDataType & { event: EventType.Message; sub_event: MessageSubType; message_id: string; message_seq?: number | undefined; elements: KarinElement[]; }'.
e.bot = this
e.replyCallback = async elements => await this._sendNsg(e, elements, PathType.Friends, e.contact.peer, e.message_id)

Expand Down Expand Up @@ -350,6 +350,10 @@
return { account_uid: 'input', account_uin: 'input', account_name: 'input' }
}

async RecallMessage (contact: Contact, message_id: string) {
return await this.super.recallMessage(contact.peer, contact.scene === 'group' ? PathType.Groups : PathType.Friends, message_id)
}

async GetEssenceMessageList (): Promise<any> { throw new Error('Method not implemented.') }
async DownloadForwardMessage (): Promise<any> { throw new Error('Method not implemented.') }
async SetEssenceMessage (): Promise<any> { throw new Error('Method not implemented.') }
Expand All @@ -363,7 +367,6 @@
async UploadForwardMessage (): Promise<any> { throw new Error('Method not implemented.') }
async sendForwardMessage (): Promise<any> { throw new Error('Method not implemented.') }
async SendMessageByResId (): Promise<any> { throw new Error('Method not implemented.') }
async RecallMessage (): Promise<any> { throw new Error('Method not implemented.') }
async GetMessage (): Promise<any> { throw new Error('Method not implemented.') }
async GetHistoryMessage (): Promise<any> { throw new Error('Method not implemented.') }
async VoteUser (): Promise<any> { throw new Error('Method not implemented.') }
Expand Down
Loading