feat(DMChannel): Message request

This commit is contained in:
March 7th 2022-10-27 19:29:45 +07:00
parent 31e0de6a05
commit 91ae4195a6
2 changed files with 49 additions and 0 deletions

View File

@ -61,6 +61,51 @@ class DMChannel extends Channel {
} else {
this.lastPinTimestamp ??= null;
}
if ('is_message_request' in data) {
/**
* Whether the channel is a message request
* @type {boolean}
*/
this.messageRequest = data.is_message_request;
}
if ('is_message_request_timestamp' in data) {
/**
* The timestamp when the message request was created
* @type {?number}
*/
this.messageRequestTimestamp = new Date(data.is_message_request_timestamp).getTime();
}
}
/**
* Accept this DMChannel.
* @returns {Promise<DMChannel>}
*/
async acceptMessageRequest() {
if (!this.messageRequest) {
throw new Error('NOT_MESSAGE_REQUEST', 'This channel is not a message request');
}
const c = await this.client.api.channels[this.id].recipients['@me'].put({
data: {
consent_status: 2,
},
});
this.messageRequest = false;
return this.client.channels._add(c);
}
/**
* Cancel this DMChannel.
* @returns {Promise<DMChannel>}
*/
async cancelMessageRequest() {
if (!this.messageRequest) {
throw new Error('NOT_MESSAGE_REQUEST', 'This channel is not a message request');
}
await this.client.api.channels[this.id].recipients['@me'].delete();
return this;
}
/**

4
typings/index.d.ts vendored
View File

@ -2384,6 +2384,10 @@ export class PartialGroupDMChannel extends TextBasedChannelMixin(Channel, [
public owner: User | null;
public ownerId: Snowflake | null;
public flags: null;
public messageRequest: boolean | undefined;
public messageRequestTimestamp: Date | undefined;
public acceptMessageRequest(): Promise<this>;
public cancelMessageRequest(): Promise<this>;
public iconURL(options?: StaticImageURLOptions): string | null;
public addMember(user: User): Promise<PartialGroupDMChannel>;
public removeMember(user: User): Promise<PartialGroupDMChannel>;