mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
feat(bot,rest,types): Guild incidents data (#4123)
* Guild incidents data * Update comments on ModifyGuildIncidentActions
This commit is contained in:
@@ -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<T extends RecursivePartial<Transfo
|
||||
premiumProgressBarEnabled: defaultValue,
|
||||
safetyAlertsChannelId: defaultValue,
|
||||
maxStageVideoChannelUsers: defaultValue,
|
||||
incidentsData: defaultValue,
|
||||
...desiredProperties.guild,
|
||||
},
|
||||
incidentsData: {
|
||||
dmSpamDetectedAt: defaultValue,
|
||||
dmsDisabledUntil: defaultValue,
|
||||
invitesDisabledUntil: defaultValue,
|
||||
raidDetectedAt: defaultValue,
|
||||
...desiredProperties.incidentsData,
|
||||
},
|
||||
interaction: {
|
||||
id: defaultValue,
|
||||
applicationId: defaultValue,
|
||||
|
||||
@@ -30,6 +30,7 @@ import type {
|
||||
DiscordGuildOnboardingPromptOption,
|
||||
DiscordGuildWidget,
|
||||
DiscordGuildWidgetSettings,
|
||||
DiscordIncidentsData,
|
||||
DiscordIntegrationCreateUpdate,
|
||||
DiscordInteraction,
|
||||
DiscordInteractionCallback,
|
||||
@@ -76,6 +77,7 @@ import {
|
||||
type TransformersDesiredProperties,
|
||||
createDesiredPropertiesObject,
|
||||
} from './desiredProperties.js'
|
||||
import { transformIncidentsData } from './transformers/incidentsData.js'
|
||||
import {
|
||||
type Activity,
|
||||
type ActivityInstance,
|
||||
@@ -104,6 +106,7 @@ import {
|
||||
type GuildOnboardingPromptOption,
|
||||
type GuildWidget,
|
||||
type GuildWidgetSettings,
|
||||
type IncidentsData,
|
||||
type Integration,
|
||||
type Interaction,
|
||||
type InteractionCallback,
|
||||
@@ -290,6 +293,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
payload: DiscordGuildOnboardingPromptOption,
|
||||
onboardingPromptOption: GuildOnboardingPromptOption,
|
||||
) => any
|
||||
incidentsData: (bot: Bot<TProps, TBehavior>, payload: DiscordIncidentsData, incidentsData: IncidentsData) => any
|
||||
integration: (bot: Bot<TProps, TBehavior>, payload: DiscordIntegrationCreateUpdate, integration: Integration) => any
|
||||
interaction: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
@@ -438,6 +442,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
payload: DiscordGuildOnboardingPrompt,
|
||||
) => SetupDesiredProps<GuildOnboardingPrompt, TProps, TBehavior>
|
||||
guildOnboardingPromptOption: (bot: Bot<TProps, TBehavior>, payload: DiscordGuildOnboardingPromptOption) => GuildOnboardingPromptOption
|
||||
incidentsData: (bot: Bot<TProps, TBehavior>, payload: DiscordIncidentsData) => IncidentsData
|
||||
integration: (bot: Bot<TProps, TBehavior>, payload: DiscordIntegrationCreateUpdate) => Integration
|
||||
interaction: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
@@ -540,6 +545,7 @@ export function createTransformers<TProps extends TransformersDesiredProperties,
|
||||
guildOnboarding: options.customizers?.guildOnboarding ?? defaultCustomizer,
|
||||
guildOnboardingPrompt: options.customizers?.guildOnboardingPrompt ?? defaultCustomizer,
|
||||
guildOnboardingPromptOption: options.customizers?.guildOnboardingPromptOption ?? defaultCustomizer,
|
||||
incidentsData: options.customizers?.incidentsData ?? defaultCustomizer,
|
||||
integration: options.customizers?.integration ?? defaultCustomizer,
|
||||
interaction: options.customizers?.interaction ?? defaultCustomizer,
|
||||
interactionCallback: options.customizers?.interactionCallback ?? defaultCustomizer,
|
||||
@@ -621,6 +627,7 @@ export function createTransformers<TProps extends TransformersDesiredProperties,
|
||||
guildOnboarding: options.guildOnboarding ?? transformGuildOnboarding,
|
||||
guildOnboardingPrompt: options.guildOnboardingPrompt ?? transformGuildOnboardingPrompt,
|
||||
guildOnboardingPromptOption: options.guildOnboardingPromptOption ?? transformGuildOnboardingPromptOption,
|
||||
incidentsData: options.incidentsData ?? transformIncidentsData,
|
||||
integration: options.integration ?? transformIntegration,
|
||||
interaction: options.interaction ?? transformInteraction,
|
||||
interactionCallback: options.interactionCallback ?? transformInteractionCallback,
|
||||
|
||||
@@ -140,6 +140,7 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.presences = payload.guild.presences?.map((presence) => 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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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'
|
||||
|
||||
@@ -787,6 +787,19 @@ export interface Guild {
|
||||
stickers?: Collection<bigint, Sticker>
|
||||
/** 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 {
|
||||
|
||||
@@ -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<DiscordIncidentsData>(rest.routes.guilds.incidentActions(guildId), { body: options })
|
||||
},
|
||||
|
||||
async unbanMember(guildId, userId, reason) {
|
||||
await rest.delete(rest.routes.guilds.members.ban(guildId, userId), { reason })
|
||||
},
|
||||
|
||||
@@ -481,6 +481,9 @@ export function createRoutes(): RestRoutes {
|
||||
onboarding: (guildId) => {
|
||||
return `/guilds/${guildId}/onboarding`
|
||||
},
|
||||
incidentActions: (guildId) => {
|
||||
return `/guilds/${guildId}/incident-actions`
|
||||
},
|
||||
},
|
||||
|
||||
sticker: (stickerId) => {
|
||||
|
||||
@@ -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<Camelize<DiscordGuildOnboarding>>
|
||||
/**
|
||||
* 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<Camelize<DiscordIncidentsData>>
|
||||
/**
|
||||
* Returns all entitlements for a given app, active and expired.
|
||||
*
|
||||
|
||||
@@ -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: {
|
||||
|
||||
@@ -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) */
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user