feat(handlers/guild): add getWidget() & getWidgetImageUrl() (#420)

* feat(handlers): more get Widget functoins

* forgot image jsdoc

* only needed inside if

* Update mod.ts

* move inside if

* gonna do that

* Update src/api/handlers/guild.ts

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>

Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
This commit is contained in:
ITOH
2021-03-08 17:41:46 +01:00
committed by GitHub
parent 0ec33b7420
commit 4adf11b7b7
3 changed files with 34 additions and 0 deletions
+29
View File
@@ -729,6 +729,35 @@ export async function editWidget(
return result;
}
/** Returns the widget for the guild. */
export async function getWidget(guildID: string, options?: { force: boolean }) {
if (!options?.force) {
const guild = await cacheHandlers.get("guilds", guildID);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
}
return RequestManager.get(`${endpoints.GUILD_WIDGET(guildID)}.json`);
}
/** Returns the widget image URL for the guild. */
export async function getWidgetImageUrl(
guildID: string,
options?: {
style?: "shield" | "banner1" | "banner2" | "banner3" | "banner4";
force?: boolean;
},
) {
if (!options?.force) {
const guild = await cacheHandlers.get("guilds", guildID);
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
}
return `${endpoints.GUILD_WIDGET(guildID)}.png?style=${options?.style ??
"shield"}`;
}
/** Returns the code and uses of the vanity url for this server if it is enabled. Requires the MANAGE_GUILD permission. */
export async function getVanityURL(guildID: string) {
const result = await RequestManager.get(endpoints.GUILD_VANITY_URL(guildID));
+4
View File
@@ -65,6 +65,8 @@ import {
getVanityURL,
getVoiceRegions,
getWebhooks,
getWidget,
getWidgetImageUrl,
getWidgetSettings,
guildBannerURL,
guildIconURL,
@@ -193,6 +195,8 @@ export let handlers = {
getVanityURL,
getVoiceRegions,
getWebhooks,
getWidget,
getWidgetImageUrl,
guildBannerURL,
guildIconURL,
guildSplashURL,