Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AutoModeration): Support Auto Moderation #1390

Closed
wants to merge 11 commits into from
130 changes: 110 additions & 20 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ declare namespace Eris {
type ApplicationCommandPermissionTypes = Constants["ApplicationCommandPermissionTypes"][keyof Constants["ApplicationCommandPermissionTypes"]];
type ApplicationCommandTypes = Constants["ApplicationCommandTypes"][keyof Constants["ApplicationCommandTypes"]];

// Auto Moderation
type AutoModerationActionType = Constants["AutoModerationActionTypes"][keyof Constants["AutoModerationActionTypes"]];
type AutoModerationEventType = Constants["AutoModerationEventTypes"][keyof Constants["AutoModerationEventTypes"]];
type AutoModerationKeywordPresetType = Constants["AutoModerationKeywordPresetTypes"][keyof Constants["AutoModerationKeywordPresetTypes"]];
type AutoModerationTriggerType = Constants["AutoModerationTriggerTypes"][keyof Constants["AutoModerationTriggerTypes"]];
type EditAutoModerationRuleOptions = Partial<CreateAutoModerationRuleOptions>;

// Cache
interface Uncached { id: string }

Expand Down Expand Up @@ -255,6 +262,48 @@ declare namespace Eris {
permissions?: ApplicationCommandPermissions[];
}

// Auto Moderation
interface AutoModerationAction {
metadata?: AutoModerationActionMetadata;
type: AutoModerationActionType;
}
interface AutoModerationActionMetadata {
/** valid for SEND_ALERT_MESSAGE */
channel_id?: string;
/** valid for TIMEOUT */
duration_seconds?: number;
}
interface AutoModerationRule {
actions: AutoModerationAction[];
creator_id: string;
enabled: boolean;
event_type: AutoModerationEventType;
exempt_roles: string[];
exempt_users: string[];
guild_id: string;
id: string;
name: string;
trigger_metadata: AutoModerationTriggerMetadata;
trigger_type: AutoModerationTriggerType;
}
interface CreateAutoModerationRuleOptions {
actions: AutoModerationAction[];
enabled?: boolean;
eventType: AutoModerationActionType;
exemptChannels?: string[];
exemptRoles?: string[];
name: string;
reason?: string;
triggerMetadata?: AutoModerationTriggerMetadata;
triggerType: AutoModerationTriggerType;
}

interface AutoModerationTriggerMetadata {
/** valid for KEYWORD */
keyword_filter: string[];
/** valid for KEYWORD_PRESET */
presets: AutoModerationKeywordPresetType[];
}
// Channel
interface ChannelFollow {
channel_id: string;
Expand Down Expand Up @@ -694,6 +743,9 @@ declare namespace Eris {
selfVideo: boolean;
}
interface EventListeners {
DonovanDMC marked this conversation as resolved.
Show resolved Hide resolved
autoModerationRuleCreate: [guild: Guild, rule: AutoModerationRule];
autoModerationRuleDelete: [guild: Guild, rule: AutoModerationRule];
autoModerationRuleUpdate: [guild: Guild, rule: AutoModerationRule | null, newRule: AutoModerationRule];
callCreate: [call: Call];
callDelete: [call: Call];
callRing: [call: Call];
Expand Down Expand Up @@ -1565,6 +1617,30 @@ declare namespace Eris {
THREAD_DELETE: 112;

APPLICATION_COMMAND_PERMISSION_UPDATE: 121;

AUTO_MODERATION_RULE_CREATE: 140;
AUTO_MODERATION_RULE_UPDATE: 141;
AUTO_MODERATION_RULE_DELETE: 142;
AUTO_MODERATION_BLOCK_MESSAGE: 143;
};
AutoModerationActionTypes: {
BLOCK_MESSAGE: 1;
SEND_ALERT_MESSAGE: 2;
TIMEOUT: 3;
};
AutoModerationEventTypes: {
MESSAGE_SEND: 1;
};
AutoModerationKeywordPresetTypes: {
PROFANITY: 1;
SEXUAL_CONTENT: 2;
SLURS: 3;
};
AutoModerationTriggerTypes: {
KEYWORD: 1;
HARMFUL_LINK: 2;
SPAM: 3;
KEYWORD_PRESET: 4;
};
ButtonStyles: {
PRIMARY: 1;
Expand Down Expand Up @@ -1630,6 +1706,7 @@ declare namespace Eris {
SYNC_CALL: 13;
};
GuildFeatures: [
"AUTO_MODERATION",
"ANIMATED_ICON",
"BANNER",
"COMMERCE",
Expand Down Expand Up @@ -1681,26 +1758,28 @@ declare namespace Eris {
MINIMUM: 16;
};
Intents: {
guilds: 1;
guildMembers: 2;
guildBans: 4;
guildEmojisAndStickers: 8;
guilds: 1;
guildMembers: 2;
guildBans: 4;
guildEmojisAndStickers: 8;
/** @deprecated */
guildEmojis: 8;
guildIntegrations: 16;
guildWebhooks: 32;
guildInvites: 64;
guildVoiceStates: 128;
guildPresences: 256;
guildMessages: 512;
guildMessageReactions: 1024;
guildMessageTyping: 2048;
directMessages: 4096;
directMessageReactions: 8192;
directMessageTyping: 16384;
allNonPrivileged: 32509;
allPrivileged: 258;
all: 32767;
guildEmojis: 8;
guildIntegrations: 16;
guildWebhooks: 32;
guildInvites: 64;
guildVoiceStates: 128;
guildPresences: 256;
guildMessages: 512;
guildMessageReactions: 1024;
guildMessageTyping: 2048;
directMessages: 4096;
directMessageReactions: 8192;
directMessageTyping: 16384;
autoModerationConfiguration: 1048576;
autoModerationExecution: 2097152;
allNonPrivileged: 3178237;
allPrivileged: 258;
all: 317849;
};
InteractionResponseTypes: {
PONG: 1;
Expand Down Expand Up @@ -1776,6 +1855,7 @@ declare namespace Eris {
THREAD_STARTER_MESSAGE: 21;
GUILD_INVITE_REMINDER: 22;
CONTEXT_MENU_COMMAND: 23;
AUTO_MODERATION_ACTION: 24;
};
PermissionOverwriteTypes: {
ROLE: 0;
Expand Down Expand Up @@ -2146,6 +2226,7 @@ declare namespace Eris {
bulkEditGuildCommands(guildID: string, commands: ApplicationCommandStructure[]): Promise<ApplicationCommand[]>;
closeVoiceConnection(guildID: string): void;
connect(): Promise<void>;
createAutoModerationRule(guildID: string, rule: CreateAutoModerationRuleOptions): Promise<AutoModerationRule>;
createChannel(guildID: string, name: string): Promise<TextChannel>;
createChannel(
guildID: string,
Expand Down Expand Up @@ -2271,6 +2352,7 @@ declare namespace Eris {
createThreadWithMessage(channelID: string, messageID: string, options: CreateThreadOptions): Promise<NewsThreadChannel | PublicThreadChannel>;
createThreadWithoutMessage(channelID: string, options: CreateThreadWithoutMessageOptions): Promise<PrivateThreadChannel>;
crosspostMessage(channelID: string, messageID: string): Promise<Message>;
deleteAutoModerationRule(guildID: string, ruleID: string, reason?: string): Promise<void>;
deleteChannel(channelID: string, reason?: string): Promise<void>;
deleteChannelPermission(channelID: string, overwriteID: string, reason?: string): Promise<void>;
deleteCommand(commandID: string): Promise<void>;
Expand All @@ -2294,6 +2376,7 @@ declare namespace Eris {
disableSelfMFATOTP(code: string): Promise<{ token: string }>;
disconnect(options: { reconnect?: boolean | "auto" }): void;
editAFK(afk: boolean): void;
editAutoModerationRule(guildID: string, ruleID: string, options: EditAutoModerationRuleOptions): Promise<AutoModerationRule>;
editChannel(
channelID: string,
options: EditChannelOptions,
Expand Down Expand Up @@ -2372,6 +2455,8 @@ declare namespace Eris {
getActiveThreads(channelID: string): Promise<ListedChannelThreads>;
getArchivedThreads(channelID: string, type: "private", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getArchivedThreads(channelID: string, type: "public", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel>>;
getAutoModerationRule(guildID: string, ruleID: string): Promise<AutoModerationRule>;
getAutoModerationRules(guildID: string): Promise<AutoModerationRule[]>;
getBotGateway(): Promise<{ session_start_limit: { max_concurrency: number; remaining: number; reset_after: number; total: number }; shards: number; url: string }>;
getChannel(channelID: string): AnyChannel;
getChannelInvites(channelID: string): Promise<Invite[]>;
Expand Down Expand Up @@ -2702,13 +2787,14 @@ declare namespace Eris {
addMemberRole(memberID: string, roleID: string, reason?: string): Promise<void>;
banMember(userID: string, deleteMessageDays?: number, reason?: string): Promise<void>;
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<ApplicationCommand[]>;
createAutoModerationRule(rule: CreateAutoModerationRuleOptions): Promise<AutoModerationRule>;
createChannel(name: string): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], options?: CreateChannelOptions): Promise<TextChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_VOICE"], options?: CreateChannelOptions): Promise<TextVoiceChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_CATEGORY"], options?: CreateChannelOptions): Promise<CategoryChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_NEWS"], options?: CreateChannelOptions | string): Promise<NewsChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STORE"], options?: CreateChannelOptions | string): Promise<StoreChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STAGE"], options?: CreateChannelOptions | string): Promise<StageChannel>;
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_STAGE_VOICE"], options?: CreateChannelOptions | string): Promise<StageChannel>;
createChannel(name: string, type?: number, options?: CreateChannelOptions): Promise<unknown>;
/** @deprecated */
createChannel(name: string, type: Constants["ChannelTypes"]["GUILD_TEXT"], reason?: string, options?: CreateChannelOptions | string): Promise<TextChannel>;
Expand All @@ -2731,6 +2817,7 @@ declare namespace Eris {
createSticker(options: CreateStickerOptions, reason?: string): Promise<Sticker>;
createTemplate(name: string, description?: string | null): Promise<GuildTemplate>;
delete(): Promise<void>;
deleteAutoModerationRule(ruleID: string, reason?: string): Promise<void>;
deleteCommand(commandID: string): Promise<void>;
deleteDiscoverySubcategory(categoryID: string, reason?: string): Promise<void>;
deleteEmoji(emojiID: string, reason?: string): Promise<void>;
Expand All @@ -2743,6 +2830,7 @@ declare namespace Eris {
dynamicIconURL(format?: ImageFormat, size?: number): string | null;
dynamicSplashURL(format?: ImageFormat, size?: number): string | null;
edit(options: GuildOptions, reason?: string): Promise<Guild>;
editAutoModerationRule(ruleID: string, options: EditAutoModerationRuleOptions): Promise<AutoModerationRule>;
editChannelPositions(channelPositions: ChannelPosition[]): Promise<void>;
editCommand(commandID: string, command: ApplicationCommandStructure): Promise<ApplicationCommand>;
editCommandPermissions(permissions: ApplicationCommandPermissions[]): Promise<GuildApplicationCommandPermissions[]>;
Expand All @@ -2765,6 +2853,8 @@ declare namespace Eris {
getAuditLog(options?: GetGuildAuditLogOptions): Promise<GuildAuditLog>;
/** @deprecated */
getAuditLogs(limit?: number, before?: string, actionType?: number, userID?: string): Promise<GuildAuditLog>;
getAutoModerationRule(guildID: string, ruleID: string): Promise<AutoModerationRule>;
getAutoModerationRules(guildID: string): Promise<AutoModerationRule[]>;
getBan(userID: string): Promise<GuildBan>;
getBans(options?: GetGuildBansOptions): Promise<GuildBan[]>;
getCommand(commandID: string): Promise<ApplicationCommand>;
Expand Down
89 changes: 89 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,34 @@ class Client extends EventEmitter {
}
}

/**
* Create an auto moderation rule
* @arg {String} guildID the ID of the guild to create the rule in
* @arg {Object} options The rule to create
* @arg {Object[]} options.actions The [actions](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object) done when the rule is violated
* @arg {Boolean} [options.enabled=false] If the rule is enabled, false by default
* @arg {Number} options.eventType The [event type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types) for the rule
* @arg {String[]} [options.exemptChannels] Any channels where this rule does not apply
* @arg {String[]} [options.exemptRoles] Any roles to which this rule does not apply
* @arg {String} options.name The name of the rule
* @arg {Object} [options.triggerMetadata] The [trigger metadata](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) for the rule
* @arg {Number} options.triggerType The [trigger type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types) of the rule
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @returns {Promise<Object>}
*/
createAutoModerationRule(guildID, options) {
return this.requestHandler.request("POST", Endpoints.AUTO_MODERATION_RULES(guildID), true, {
actions: options.actions,
enabled: options.enabled,
event_type: options.eventType,
exempt_channels: options.exemptChannels,
exempt_roles: options.exemptRoles,
name: options.name,
trigger_metadata: options.triggerMetadata,
trigger_type: options.triggerType
});
}

/**
* Create a channel in a guild
* @arg {String} guildID The ID of the guild to create the channel in
Expand Down Expand Up @@ -953,6 +981,19 @@ class Client extends EventEmitter {
return this.requestHandler.request("POST", Endpoints.CHANNEL_CROSSPOST(channelID, messageID), true).then((message) => new Message(message, this));
}

/**
* Delete an auto moderation rule
* @arg {String} guildID The guildID to delete the rule from
* @arg {String} ruleID The ID of the rule to delete
* @arg {String} [reason] The reason to be displayed in audit logs
* @returns {Promise}
*/
deleteAutoModerationRule(guildID, ruleID, reason) {
return this.requestHandler.request("DELETE", Endpoints.AUTO_MODERATION_RULE(guildID, ruleID), true, {
reason
});
}

/**
* Delete a guild channel, or leave a private or group channel
* @arg {String} channelID The ID of the channel
Expand Down Expand Up @@ -1242,6 +1283,35 @@ class Client extends EventEmitter {
});
}

/**
* edit an existing auto moderation rule
* @arg {String} guildID the ID of the guild to edit the rule in
* @arg {String} ruleID The ID of the rule to edit
* @arg {Object} options The rule to create
* @arg {Object[]} [options.actions] The [actions](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object) done when the rule is violated
* @arg {Boolean} [options.enabled=false] If the rule is enabled, false by default
* @arg {Number} [options.eventType] The [event type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types) for the rule
* @arg {String[]} [options.exemptChannels] Any channels where this rule does not apply
* @arg {String[]} [options.exemptRoles] Any roles to which this rule does not apply
* @arg {String} [options.name] The name of the rule
* @arg {Object} [options.triggerMetadata] The [trigger metadata](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) for the rule
* @arg {Number} [options.triggerType] The [trigger type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types) of the rule
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @returns {Promise<Object>}
*/
editAutoModerationRule(guildID, ruleID, options) {
return this.requestHandler.request("PATCH", Endpoints.AUTO_MODERATION_RULE(guildID, ruleID), true, {
actions: options.actions,
enabled: options.enabled,
event_type: options.eventType,
exempt_channels: options.exemptChannels,
exempt_roles: options.exemptRoles,
name: options.name,
trigger_metadata: options.triggerMetadata,
trigger_type: options.triggerType
});
}

/**
* Edit a channel's properties
* @arg {String} channelID The ID of the channel
Expand Down Expand Up @@ -2172,6 +2242,25 @@ class Client extends EventEmitter {
});
}

/**
* Get an existing auto moderation rule
* @arg {String} guildID The ID of the guild to get the rule from
* @arg {String} ruleID The ID of the rule to get
* @returns {Promise<Object>}
*/
getAutoModerationRule(guildID, ruleID) {
return this.requestHandler.request("GET", Endpoints.AUTO_MODERATION_RULE(guildID, ruleID), true);
}

/**
* Get a guild's auto moderation rules
* @arg {String} guildID The ID of the guild to get the rules of
* @returns {Promise<Object[]>}
*/
getAutoModerationRules(guildID) {
return this.requestHandler.request("GET", Endpoints.AUTO_MODERATION_RULES(guildID), true);
}

/**
* Get general and bot-specific info on connecting to the Discord gateway (e.g. connection ratelimit)
* @returns {Promise<Object>} Resolves with an object containing gateway connection info
Expand Down
Loading