feat: friend invite

This commit is contained in:
Elysia 2023-05-10 19:04:05 +07:00
parent 3ffe3cb8d1
commit 29bbd1df20
2 changed files with 33 additions and 11 deletions

View File

@ -463,28 +463,48 @@ class ClientUser extends User {
/**
* Create an invite [Friend Invites]
* maxAge: 86400 | maxUses: 0
* maxAge: 604800 | maxUses: 1
* @returns {Promise<Invite>}
* @see {@link https://github.com/13-05/hidden-disc-docs#js-snippet-for-creating-friend-invites}
* @example
* // Options not working
* client.user.getInvite();
* client.user.createFriendInvite();
* .then(console.log)
* .catch(console.error);
*/
async getInvite() {
async createFriendInvite() {
const data = await this.client.api.users['@me'].invites.post({
data: {
validate: null,
max_age: 86400,
max_uses: 0,
target_type: 2,
temporary: false,
},
data: {},
});
return new Invite(this.client, data);
}
/**
* Get all friend invites
* @returns {Promise<Collection<string, Invite>>}
*/
async getAllFriendInvites() {
const data = await this.client.api.users['@me'].invites.get();
const collection = new Collection();
for (const invite of data) {
collection.set(invite.code, new Invite(this.client, invite));
}
return collection;
}
/**
* Revoke all friend invites
* @returns {Promise<Collection<string, Invite>>}
*/
async revokeAllFriendInvites() {
const data = await this.client.api.users['@me'].invites.delete();
const collection = new Collection();
for (const invite of data) {
collection.set(invite.code, new Invite(this.client, invite));
}
return collection;
}
/**
* Get a collection of messages mentioning clientUser
* @param {number} [limit=25] Maximum number of messages to get

4
typings/index.d.ts vendored
View File

@ -1064,7 +1064,9 @@ export class ClientUser extends User {
public deleteAccount(password: string): Promise<this>;
public setDeaf(status: boolean): Promise<boolean>;
public setMute(status: boolean): Promise<boolean>;
public getInvite(options?: CreateInviteOptions): Promise<Invite>;
public createFriendInvite(): Promise<Invite>;
public getAllFriendInvites(): Promise<Collection<string, Invite>>;
public revokeAllFriendInvites(): Promise<Collection<string, Invite>>;
public setSamsungActivity(packageName: string, type?: 'START' | 'UPDATE' | 'STOP'): Promise<this>;
public getMentions(
limit?: number,