diff --git a/src/helpers/guilds/edit_welcome_screen.ts b/src/helpers/guilds/edit_welcome_screen.ts new file mode 100644 index 000000000..5ad2a95b6 --- /dev/null +++ b/src/helpers/guilds/edit_welcome_screen.ts @@ -0,0 +1,21 @@ +import { rest } from "../../rest/rest.ts"; +import { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts"; +import { WelcomeScreen } from "../../types/mod.ts"; +import { endpoints } from "../../util/constants.ts"; +import { + camelKeysToSnakeCase, + snakeKeysToCamelCase, +} from "../../util/utils.ts"; + +export async function editWelcomeScreen( + guildId: string, + options: ModifyGuildWelcomeScreen, +) { + const result = await rest.runMethod( + "patch", + endpoints.GUILD_WELCOME_SCREEN(guildId), + camelKeysToSnakeCase(options), + ); + + return snakeKeysToCamelCase(result); +} diff --git a/src/helpers/guilds/get_welcome_screen.ts b/src/helpers/guilds/get_welcome_screen.ts new file mode 100644 index 000000000..4163c4f71 --- /dev/null +++ b/src/helpers/guilds/get_welcome_screen.ts @@ -0,0 +1,13 @@ +import { rest } from "../../rest/rest.ts"; +import { WelcomeScreen } from "../../types/mod.ts"; +import { endpoints } from "../../util/constants.ts"; +import { snakeKeysToCamelCase } from "../../util/utils.ts"; + +export async function getWelcomeScreen(guildId: string) { + const result = await rest.runMethod( + "get", + endpoints.GUILD_WELCOME_SCREEN(guildId), + ); + + return snakeKeysToCamelCase(result); +} diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index a657d3f14..49486d140 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -31,6 +31,7 @@ import { getEmojis } from "./emojis/get_emojis.ts"; import { createGuild } from "./guilds/create_guild.ts"; import { deleteServer } from "./guilds/delete_server.ts"; import { editGuild } from "./guilds/edit_guild.ts"; +import { editWelcomeScreen } from "./guilds/edit_welcome_screen.ts"; import { editWidget } from "./guilds/edit_widget.ts"; import { getAuditLogs } from "./guilds/get_audit_logs.ts"; import { getAvailableVoiceRegions } from "./guilds/get_available_voice_regions.ts"; @@ -41,6 +42,7 @@ import { getGuildPreview } from "./guilds/get_guild_preview.ts"; import { getPruneCount } from "./guilds/get_prune_count.ts"; import { getVanityURL } from "./guilds/get_vainty_url.ts"; import { getVoiceRegions } from "./guilds/get_voice_regions.ts"; +import { getWelcomeScreen } from "./guilds/get_welcome_screen.ts"; import { getWidget } from "./guilds/get_widget.ts"; import { getWidgetImageURL } from "./guilds/get_widget_image_url.ts"; import { getWidgetSettings } from "./guilds/get_widget_settings.ts"; @@ -163,6 +165,7 @@ export { editWebhook, editWebhookMessage, editWebhookWithToken, + editWelcomeScreen, editWidget, emojiURL, executeWebhook, @@ -203,6 +206,7 @@ export { getWebhook, getWebhooks, getWebhookWithToken, + getWelcomeScreen, getWidget, getWidgetImageURL, getWidgetSettings, @@ -275,6 +279,7 @@ export let helpers = { deleteServer, editGuild, editWidget, + editWelcomeScreen, emojiURL, getAuditLogs, getAvailableVoiceRegions, @@ -282,6 +287,7 @@ export let helpers = { getBans, getGuildPreview, getGuild, + getWelcomeScreen, getPruneCount, getVanityURL, getVoiceRegions, diff --git a/src/types/guilds/modify_guild_welcome_screen.ts b/src/types/guilds/modify_guild_welcome_screen.ts new file mode 100644 index 000000000..d983043af --- /dev/null +++ b/src/types/guilds/modify_guild_welcome_screen.ts @@ -0,0 +1,16 @@ +import { SnakeCasedPropertiesDeep } from "../util.ts"; +import { WelcomeScreenChannel } from "./welcome_screen_channel.ts"; + +export interface ModifyGuildWelcomeScreen { + /** Whether the welcome screen is enabled */ + enabled?: boolean | null; + /** Channels linked in the welcome screen and their display options */ + welcomeScreen?: WelcomeScreenChannel[] | null; + /** The server description to show in the welcome screen */ + description?: string | null; +} + +// TODO: add documentation link +export type DiscordModifyGuildWelcomeScreen = SnakeCasedPropertiesDeep< + ModifyGuildWelcomeScreen +>; diff --git a/src/types/mod.ts b/src/types/mod.ts index 6fcc0228b..e65dab797 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -84,6 +84,7 @@ export * from "./guilds/modify_guild_channel_position.ts"; export * from "./guilds/modify_guild_member.ts"; export * from "./guilds/modify_guild_role.ts"; export * from "./guilds/modify_guild_role_positions.ts"; +export * from "./guilds/modify_guild_welcome_screen.ts"; export * from "./guilds/premium_tiers.ts"; export * from "./guilds/request_guild_members.ts"; export * from "./guilds/system_channel_flags.ts"; diff --git a/src/util/constants.ts b/src/util/constants.ts index bff7d1483..16ef3e07f 100644 --- a/src/util/constants.ts +++ b/src/util/constants.ts @@ -121,6 +121,8 @@ export const endpoints = { GUILD_PREVIEW: (guildId: string) => `${GUILDS_BASE(guildId)}/preview`, UPDATE_VOICE_STATE: (guildId: string, userId?: string) => `${GUILDS_BASE(guildId)}/voice-states/${userId ?? "@me"}`, + GUILD_WELCOME_SCREEN: (guildId: string) => + `${GUILDS_BASE(guildId)}/welcome-screen`, // Voice VOICE_REGIONS: `${baseEndpoints.BASE_URL}/voice/regions`,