Skip to content

Commit

Permalink
incident actions
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Sep 3, 2023
1 parent 8a87287 commit dc8defc
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,12 @@ export enum MessageTypes {
PRIVATE_CHANNEL_INTEGRATION_ADDED = 33,
PRIVATE_CHANNEL_INTEGRATION_REMOVED = 34,
PREMIUM_REFERRAL = 35,
GUILD_INCIDENT_ALERT_MODE_ENABLED = 36,
GUILD_INCIDENT_ALERT_MODE_DISABLED = 37,
GUILD_INCIDENT_REPORT_RAID = 38,
GUILD_INCIDENT_REPORT_FALSE_ALARM = 39,
GUILD_DEADCHAT_REVIVE_PROMPT = 40,
CUSTOM_GIFT = 41,
}

export enum MessageActivityTypes {
Expand Down
29 changes: 28 additions & 1 deletion lib/routes/Guilds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ import type {
EditStickerOptions,
RawOnboarding,
Onboarding,
EditOnboardingOptions
EditOnboardingOptions,
EditIncidentActionsOptions,
IncidentActions,
RawIncidentActions
} from "../types/guilds";
import * as Routes from "../util/Routes";
import type { CreateAutoModerationRuleOptions, EditAutoModerationRuleOptions, RawAutoModerationRule } from "../types/auto-moderation";
Expand Down Expand Up @@ -751,6 +754,30 @@ export default class Guilds {
}).then(data => this.#manager.client.guilds.get(guildID)?.emojis.update(data) ?? this.#manager.client.util.convertEmoji(data));
}

/**
* Edit the incident actions for a guild.
* @param guildID The ID of the guild.
* @param options The options for editing the incident actions.
*/
async editIncidentActions(guildID: string, options: EditIncidentActionsOptions): Promise<IncidentActions> {
const reason = options.reason;
if (options.reason) {
delete options.reason;
}
return this.#manager.authRequest<RawIncidentActions>({
method: "PUT",
path: Routes.GUILD_INCIDENT_ACTIONS(guildID),
json: {
dmsDisabledUntil: options.dmsDisabledUntil,
invitesDisabledUntil: options.invitesDisabledUntil
},
reason
}).then(data => ({
dmsDisabledUntil: data.dms_disabled_until,
invitesDisabledUntil: data.invites_disabled_until
}));
}

/**
* Edit the [mfa level](https://discord.com/developers/docs/resources/guild#guild-object-mfa-level) of a guild. This can only be used by the guild owner.
* @param guildID The ID of the guild.
Expand Down
21 changes: 20 additions & 1 deletion lib/structures/Guild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ import type {
EditOnboardingOptions,
RawGuildEmoji,
RawSticker,
InventorySettings
InventorySettings,
EditIncidentActionsOptions,
IncidentActions
} from "../types/guilds";
import type {
CreateScheduledEventOptions,
Expand Down Expand Up @@ -159,6 +161,7 @@ export default class Guild extends Base {
features: Array<GuildFeature>;
/** The icon hash of this guild. */
icon: string | null;
incidentActions: IncidentActions | null;
/** The integrations in this guild. */
integrations: TypedCollection<RawIntegration, Integration, [guildID?: string]>;
/** The guild's inventory settings. */
Expand Down Expand Up @@ -272,6 +275,7 @@ export default class Guild extends Base {
this.explicitContentFilter = data.explicit_content_filter;
this.features = [];
this.icon = null;
this.incidentActions = null;
this.integrations = new TypedCollection(Integration, client, client.util._getLimit("integrations", this.id));
this.inventorySettings = null;
this.invites = new SimpleCollection(rawInvite => new Invite(rawInvite, client), client.util._getLimit("invites", this.id), "update", "code");
Expand Down Expand Up @@ -497,6 +501,12 @@ export default class Guild extends Base {
if (data.icon !== undefined) {
this.icon = data.icon;
}
if (data.incident_actions !== undefined) {
this.incidentActions = {
dmsDisabledUntil: data.incident_actions!.dms_disabled_until,
invitesDisabledUntil: data.incident_actions!.invites_disabled_until
};
}
if (data.inventory_settings !== undefined) {
this.inventorySettings = data.inventory_settings === null ? null : {
isEmojiPackCollectible: data.inventory_settings.is_emoji_pack_collectible
Expand Down Expand Up @@ -927,6 +937,14 @@ export default class Guild extends Base {
return this.client.rest.guilds.editEmoji(this.id, emojiID, options);
}

/**
* Edit the incident actions for this guild.
* @param options The options for editing the incident actions.
*/
async editIncidentActions(options: EditIncidentActionsOptions): Promise<IncidentActions> {
return this.client.rest.guilds.editIncidentActions(this.id, options);
}

/**
* Edit the [mfa level](https://discord.com/developers/docs/resources/guild#guild-object-mfa-level) of this guild. This can only be used by the guild owner.
* @param options The options for editing the MFA level.
Expand Down Expand Up @@ -1431,6 +1449,7 @@ export default class Guild extends Base {
explicitContentFilter: this.explicitContentFilter,
features: this.features,
icon: this.icon,
incidentActions: this.incidentActions,
joinedAt: this.joinedAt?.getTime() ?? null,
large: this.large,
maxMembers: this.maxMembers,
Expand Down
22 changes: 22 additions & 0 deletions lib/types/guilds.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface RawGuild {
icon: string | null;
icon_hash?: string | null;
id: string;
incident_actions: RawIncidentActions | null;
inventory_settings: RawInventorySettings | null;
joined_at: string | null;
large: boolean;
Expand Down Expand Up @@ -810,3 +811,24 @@ export interface RawInventorySettings {
export interface InventorySettings {
isEmojiPackCollectible: boolean;
}

export interface EditIncidentActionsOptions {
/** When disabled direct messages will expire (up to 24 hours in the future) */
dmsDisabledUntil?: string | null;
/** When disabled invites will expire (up to 24 hours in the future). */
invitesDisabledUntil?: string | null;
/** The reason for editing the incident actions. */
reason?: string;
}

export interface RawIncidentActions {
dms_disabled_until: string | null;
invites_disabled_until: string | null;
}

export interface IncidentActions {
/** When disabled direct messages will expire (up to 24 hours in the future) */
dmsDisabledUntil: string | null;
/** When disabled invites will expire (up to 24 hours in the future). */
invitesDisabledUntil: string | null;
}
4 changes: 3 additions & 1 deletion lib/types/json.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import type {
RawSticker,
WelcomeScreen,
Sticker,
Presence
Presence,
IncidentActions
} from "./guilds";
import type {
ChannelMention,
Expand Down Expand Up @@ -242,6 +243,7 @@ export interface JSONGuild extends JSONBase {
explicitContentFilter: ExplicitContentFilterLevels;
features: Array<GuildFeature>;
icon: string | null;
incidentActions: IncidentActions | null;
joinedAt: number | null;
large: boolean;
maxMembers?: number;
Expand Down
1 change: 1 addition & 0 deletions lib/util/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const GUILD_VOICE_STATE = (guildID: string, userID: string) =>
export const GUILD_STICKER = (guildID: string, stickerID: string) => `/guilds/${guildID}/stickers/${stickerID}` as const;
export const GUILD_STICKERS = (guildID: string) => `/guilds/${guildID}/stickers` as const;
export const GUILD_ONBOARDING = (guildID: string) => `/guilds/${guildID}/onboarding` as const;
export const GUILD_INCIDENT_ACTIONS = (guildID: string) => `/guilds/${guildID}/incident-actions` as const;

// Channels
export const CHANNEL = (channelID: string) => `/channels/${channelID}` as const;
Expand Down

0 comments on commit dc8defc

Please sign in to comment.