fix(Guild): cache fetched widget data (#4760)

This commit is contained in:
Sugden
2020-08-31 08:16:53 +01:00
committed by GitHub
parent f97316319f
commit 7ba9440053

View File

@@ -883,13 +883,7 @@ class Guild extends Base {
* .catch(console.error); * .catch(console.error);
*/ */
fetchEmbed() { fetchEmbed() {
return this.client.api return this.fetchWidget();
.guilds(this.id)
.embed.get()
.then(data => ({
enabled: data.enabled,
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
}));
} }
/** /**
@@ -901,14 +895,14 @@ class Guild extends Base {
* .then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`)) * .then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`))
* .catch(console.error); * .catch(console.error);
*/ */
fetchWidget() { async fetchWidget() {
return this.client.api const data = await this.client.api.guilds(this.id).widget.get();
.guilds(this.id) this.widgetEnabled = this.embedEnabled = data.enabled;
.widget.get() this.widgetChannelID = this.embedChannelID = data.channel_id;
.then(data => ({ return {
enabled: data.enabled, enabled: data.enabled,
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null, channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
})); };
} }
/** /**
@@ -1387,16 +1381,7 @@ class Guild extends Base {
* @deprecated * @deprecated
*/ */
setEmbed(embed, reason) { setEmbed(embed, reason) {
return this.client.api return this.setWidget(embed, reason);
.guilds(this.id)
.embed.patch({
data: {
enabled: embed.enabled,
channel_id: this.channels.resolveID(embed.channel),
},
reason,
})
.then(() => this);
} }
/** /**