refactor(*): use async functions (#6210)

This commit is contained in:
Sugden
2021-08-02 00:47:43 +01:00
committed by GitHub
parent 626ff85ae7
commit e2e4f6518b
29 changed files with 298 additions and 399 deletions

View File

@@ -236,7 +236,7 @@ class Client extends BaseClient {
);
if (this.options.presence) {
this.options.ws.presence = await this.presence._parse(this.options.presence);
this.options.ws.presence = this.presence._parse(this.options.presence);
}
this.emit(Events.DEBUG, 'Preparing to connect to the gateway...');
@@ -284,12 +284,10 @@ class Client extends BaseClient {
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
* .catch(console.error);
*/
fetchInvite(invite) {
async fetchInvite(invite) {
const code = DataResolver.resolveInviteCode(invite);
return this.api
.invites(code)
.get({ query: { with_counts: true, with_expiration: true } })
.then(data => new Invite(this, data));
const data = await this.api.invites(code).get({ query: { with_counts: true, with_expiration: true } });
return new Invite(this, data);
}
/**
@@ -301,12 +299,10 @@ class Client extends BaseClient {
* .then(template => console.log(`Obtained template with code: ${template.code}`))
* .catch(console.error);
*/
fetchGuildTemplate(template) {
async fetchGuildTemplate(template) {
const code = DataResolver.resolveGuildTemplateCode(template);
return this.api.guilds
.templates(code)
.get()
.then(data => new GuildTemplate(this, data));
const data = await this.api.guilds.templates(code).get();
return new GuildTemplate(this, data);
}
/**
@@ -319,11 +315,9 @@ class Client extends BaseClient {
* .then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
* .catch(console.error);
*/
fetchWebhook(id, token) {
return this.api
.webhooks(id, token)
.get()
.then(data => new Webhook(this, { token, ...data }));
async fetchWebhook(id, token) {
const data = await this.api.webhooks(id, token).get();
return new Webhook(this, { token, ...data });
}
/**
@@ -334,12 +328,11 @@ class Client extends BaseClient {
* .then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
* .catch(console.error);
*/
fetchVoiceRegions() {
return this.api.voice.regions.get().then(res => {
const regions = new Collection();
for (const region of res) regions.set(region.id, new VoiceRegion(region));
return regions;
});
async fetchVoiceRegions() {
const apiRegions = await this.api.voice.regions.get();
const regions = new Collection();
for (const region of apiRegions) regions.set(region.id, new VoiceRegion(region));
return regions;
}
/**
@@ -433,13 +426,11 @@ class Client extends BaseClient {
* @param {GuildResolvable} guild The guild to fetch the preview for
* @returns {Promise<GuildPreview>}
*/
fetchGuildPreview(guild) {
async fetchGuildPreview(guild) {
const id = this.guilds.resolveId(guild);
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
return this.api
.guilds(id)
.preview.get()
.then(data => new GuildPreview(this, data));
const data = await this.api.guilds(id).preview.get();
return new GuildPreview(this, data);
}
/**