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

@@ -195,45 +195,42 @@ class GuildManager extends CachedManager {
}
if (systemChannelFlags) systemChannelFlags = SystemChannelFlags.resolve(systemChannelFlags);
return new Promise((resolve, reject) =>
this.client.api.guilds
.post({
data: {
name,
icon,
verification_level: verificationLevel,
default_message_notifications: defaultMessageNotifications,
explicit_content_filter: explicitContentFilter,
roles,
channels,
afk_channel_id: afkChannelId,
afk_timeout: afkTimeout,
system_channel_id: systemChannelId,
system_channel_flags: systemChannelFlags,
},
})
.then(data => {
if (this.client.guilds.cache.has(data.id)) return resolve(this.client.guilds.cache.get(data.id));
const data = await this.client.api.guilds.post({
data: {
name,
icon,
verification_level: verificationLevel,
default_message_notifications: defaultMessageNotifications,
explicit_content_filter: explicitContentFilter,
roles,
channels,
afk_channel_id: afkChannelId,
afk_timeout: afkTimeout,
system_channel_id: systemChannelId,
system_channel_flags: systemChannelFlags,
},
});
const handleGuild = guild => {
if (guild.id === data.id) {
clearTimeout(timeout);
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.decrementMaxListeners();
resolve(guild);
}
};
this.client.incrementMaxListeners();
this.client.on(Events.GUILD_CREATE, handleGuild);
if (this.client.guilds.cache.has(data.id)) return this.client.guilds.cache.get(data.id);
const timeout = setTimeout(() => {
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.decrementMaxListeners();
resolve(this.client.guilds._add(data));
}, 10000).unref();
return undefined;
}, reject),
);
return new Promise(resolve => {
const handleGuild = guild => {
if (guild.id === data.id) {
clearTimeout(timeout);
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.decrementMaxListeners();
resolve(guild);
}
};
this.client.incrementMaxListeners();
this.client.on(Events.GUILD_CREATE, handleGuild);
const timeout = setTimeout(() => {
this.client.removeListener(Events.GUILD_CREATE, handleGuild);
this.client.decrementMaxListeners();
resolve(this.client.guilds._add(data));
}, 10000).unref();
});
}
/**