diff --git a/packages/bot/src/desiredProperties.ts b/packages/bot/src/desiredProperties.ts index 4a61b0b51..37207ecbf 100644 --- a/packages/bot/src/desiredProperties.ts +++ b/packages/bot/src/desiredProperties.ts @@ -15,6 +15,7 @@ import type { GuildOnboarding, GuildOnboardingPrompt, GuildOnboardingPromptOption, + IncidentsData, Interaction, InteractionCallback, InteractionCallbackResponse, @@ -65,6 +66,7 @@ export interface TransformersObjects { guildOnboarding: GuildOnboarding guildOnboardingPrompt: GuildOnboardingPrompt guildOnboardingPromptOption: GuildOnboardingPromptOption + incidentsData: IncidentsData interaction: Interaction interactionCallback: InteractionCallback interactionCallbackResponse: InteractionCallbackResponse @@ -347,8 +349,16 @@ export function createDesiredPropertiesObject any + incidentsData: (bot: Bot, payload: DiscordIncidentsData, incidentsData: IncidentsData) => any integration: (bot: Bot, payload: DiscordIntegrationCreateUpdate, integration: Integration) => any interaction: ( bot: Bot, @@ -438,6 +442,7 @@ export type Transformers SetupDesiredProps guildOnboardingPromptOption: (bot: Bot, payload: DiscordGuildOnboardingPromptOption) => GuildOnboardingPromptOption + incidentsData: (bot: Bot, payload: DiscordIncidentsData) => IncidentsData integration: (bot: Bot, payload: DiscordIntegrationCreateUpdate) => Integration interaction: ( bot: Bot, @@ -540,6 +545,7 @@ export function createTransformers bot.transformers.presence(bot, presence as DiscordPresenceUpdate)) if (props.safetyAlertsChannelId && payload.guild.safety_alerts_channel_id) guild.safetyAlertsChannelId = bot.transformers.snowflake(payload.guild.safety_alerts_channel_id) + if (props.incidentsData && payload.guild.incidents_data) guild.incidentsData = bot.transformers.incidentsData(bot, payload.guild.incidents_data) return bot.transformers.customizers.guild(bot, payload.guild, guild) } diff --git a/packages/bot/src/transformers/incidentsData.ts b/packages/bot/src/transformers/incidentsData.ts new file mode 100644 index 000000000..4a5d634d1 --- /dev/null +++ b/packages/bot/src/transformers/incidentsData.ts @@ -0,0 +1,14 @@ +import type { DiscordIncidentsData } from '@discordeno/types' +import type { IncidentsData, InternalBot } from '../index.js' + +export function transformIncidentsData(bot: InternalBot, payload: DiscordIncidentsData): typeof bot.transformers.$inferredTypes.incidentsData { + const props = bot.transformers.desiredProperties.incidentsData + const incidentsData = {} as IncidentsData + + if (props.invitesDisabledUntil && payload.invites_disabled_until) incidentsData.invitesDisabledUntil = Date.parse(payload.invites_disabled_until) + if (props.dmsDisabledUntil && payload.dms_disabled_until) incidentsData.dmsDisabledUntil = Date.parse(payload.dms_disabled_until) + if (props.dmSpamDetectedAt && payload.dm_spam_detected_at) incidentsData.dmSpamDetectedAt = Date.parse(payload.dm_spam_detected_at) + if (props.raidDetectedAt && payload.raid_detected_at) incidentsData.raidDetectedAt = Date.parse(payload.raid_detected_at) + + return bot.transformers.customizers.incidentsData(bot, payload, incidentsData) +} diff --git a/packages/bot/src/transformers/index.ts b/packages/bot/src/transformers/index.ts index d464dc023..3d751530f 100644 --- a/packages/bot/src/transformers/index.ts +++ b/packages/bot/src/transformers/index.ts @@ -16,6 +16,7 @@ export * from './emoji.js' export * from './entitlement.js' export * from './gatewayBot.js' export * from './guild.js' +export * from './incidentsData.js' export * from './integration.js' export * from './interaction.js' export * from './invite.js' @@ -28,21 +29,21 @@ export * from './reverse/index.js' export * from './role.js' export * from './scheduledEvent.js' export * from './sku.js' +export * from './soundboardSound.js' export * from './stageInstance.js' export * from './stageInviteInstance.js' export * from './sticker.js' +export * from './subscription.js' +export * from './subscription.js' export * from './team.js' export * from './template.js' export * from './threadMember.js' export * from './toggles/index.js' export * from './types.js' -export * from './subscription.js' -export * from './soundboardSound.js' export * from './user.js' export * from './voiceRegion.js' export * from './voiceState.js' export * from './webhook.js' -export * from './subscription.js' export * from './welcomeScreen.js' export * from './widget.js' export * from './widgetSettings.js' diff --git a/packages/bot/src/transformers/types.ts b/packages/bot/src/transformers/types.ts index 63f64962c..feb1c8751 100644 --- a/packages/bot/src/transformers/types.ts +++ b/packages/bot/src/transformers/types.ts @@ -787,6 +787,19 @@ export interface Guild { stickers?: Collection /** The id of the channel where admins and moderators of Community guilds receive safety alerts from Discord */ safetyAlertsChannelId?: bigint + /** The incidents data for this guild */ + incidentsData: IncidentsData +} + +export interface IncidentsData { + /** When invites get enabled again */ + invitesDisabledUntil?: number + /** When direct messages get enabled again */ + dmsDisabledUntil?: number + /** When the dm spam was detected */ + dmSpamDetectedAt?: number + /** When the raid was detected */ + raidDetectedAt?: number } export interface Integration { diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index ae9437ca5..90a7dc8a3 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -25,6 +25,7 @@ import { type DiscordGuildPreview, type DiscordGuildWidget, type DiscordGuildWidgetSettings, + type DiscordIncidentsData, type DiscordIntegration, type DiscordInteractionCallbackResponse, type DiscordInvite, @@ -1568,6 +1569,10 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }) }, + async modifyGuildIncidentActions(guildId, options) { + return await rest.put(rest.routes.guilds.incidentActions(guildId), { body: options }) + }, + async unbanMember(guildId, userId, reason) { await rest.delete(rest.routes.guilds.members.ban(guildId, userId), { reason }) }, diff --git a/packages/rest/src/routes.ts b/packages/rest/src/routes.ts index 6d21798cb..8242fc56e 100644 --- a/packages/rest/src/routes.ts +++ b/packages/rest/src/routes.ts @@ -481,6 +481,9 @@ export function createRoutes(): RestRoutes { onboarding: (guildId) => { return `/guilds/${guildId}/onboarding` }, + incidentActions: (guildId) => { + return `/guilds/${guildId}/incident-actions` + }, }, sticker: (stickerId) => { diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index c21244821..e475fb20d 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -54,6 +54,7 @@ import type { DiscordGuildPreview, DiscordGuildWidget, DiscordGuildWidgetSettings, + DiscordIncidentsData, DiscordIntegration, DiscordInteractionCallbackResponse, DiscordInvite, @@ -120,6 +121,7 @@ import type { ModifyGuild, ModifyGuildChannelPositions, ModifyGuildEmoji, + ModifyGuildIncidentActions, ModifyGuildMember, ModifyGuildSoundboardSound, ModifyGuildTemplate, @@ -2975,7 +2977,7 @@ export interface RestManager { /** * Modifies the onboarding configuration of the guild. * - * @param guildId - The guild to get the onboarding from + * @param guildId - The guild to edit the onboarding from * @param {string} [reason] - An optional reason for the action, to be included in the audit log. * * @remarks @@ -2988,6 +2990,16 @@ export interface RestManager { * The `mode` field modifies what is considered when enforcing these constraints. */ editGuildOnboarding: (guildId: BigString, options: EditGuildOnboarding, reason?: string) => Promise> + /** + * Modifies the incident actions of the guild. + * + * @param guildId - The guild to edit the incident actions from + * @param options - The options for the incident actions + * + * @remarks + * Requires the `MANAGE_GUILD` permission. + */ + modifyGuildIncidentActions: (guildId: BigString, options: ModifyGuildIncidentActions) => Promise> /** * Returns all entitlements for a given app, active and expired. * diff --git a/packages/rest/src/typings/routes.ts b/packages/rest/src/typings/routes.ts index 209a760c0..303359946 100644 --- a/packages/rest/src/typings/routes.ts +++ b/packages/rest/src/typings/routes.ts @@ -219,6 +219,8 @@ export interface RestRoutes { voice: (guildId: BigString, userId?: BigString) => string /** Route for the onboarding */ onboarding: (guildId: BigString) => string + /** Route for guild incident actions */ + incidentActions: (guildId: BigString) => string } /** Routes for interaction related endpoints. */ interactions: { diff --git a/packages/types/src/discord/guild.ts b/packages/types/src/discord/guild.ts index d8a83f953..8dbe9546b 100644 --- a/packages/types/src/discord/guild.ts +++ b/packages/types/src/discord/guild.ts @@ -117,6 +117,8 @@ export interface DiscordGuild { stickers?: DiscordSticker[] /** The id of the channel where admins and moderators of Community guilds receive safety alerts from Discord */ safety_alerts_channel_id: string | null + /** The incidents data for this guild */ + incidents_data: DiscordIncidentsData /** * Soundboard sounds in the guild * @@ -598,6 +600,18 @@ export enum DiscordGuildOnboardingPromptType { DropDown, } +/** https://discord.com/developers/docs/resources/guild#incidents-data-object-incidents-data-structure */ +export interface DiscordIncidentsData { + /** When invites get enabled again */ + invites_disabled_until: string | null + /** When direct messages get enabled again */ + dms_disabled_until: string | null + /** When the dm spam was detected */ + dm_spam_detected_at?: string | null + /** When the raid was detected */ + raid_detected_at?: string | null +} + /** https://discord.com/developers/docs/resources/guild#create-guild-channel-json-params */ export interface DiscordCreateGuildChannel { /** Channel name (1-100 characters) */ diff --git a/packages/types/src/discordeno.ts b/packages/types/src/discordeno.ts index d29fb14e7..118e22c5d 100644 --- a/packages/types/src/discordeno.ts +++ b/packages/types/src/discordeno.ts @@ -1648,3 +1648,27 @@ export interface CreateWebhook { /** Image url for the default webhook avatar */ avatar?: string | null } + +/** https://discord.com/developers/docs/resources/guild#modify-guild-incident-actions-json-params */ +export interface ModifyGuildIncidentActions { + /** + * When invites will be enabled again + * + * @remarks + * The value should either be an ISO8601 string or null + * + * Can be enabled for a maximal timespan of 24 hours in the future. + * Supplying null disables the action + */ + invitesDisabledUntil?: string | null + /** + * When direct messages will be enabled again + * + * @remarks + * The value should either be an ISO8601 string or null + * + * Can be enabled for a maximal timespan of 24 hours in the future. + * Supplying null disables the action + */ + dms_disabled_until?: string | null +}