@zygout/eris 0.19.0 → 0.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +71 -80
  3. package/esm.mjs +72 -72
  4. package/index.d.ts +4407 -4397
  5. package/index.js +75 -75
  6. package/lib/Client.js +4708 -4683
  7. package/lib/Constants.d.ts +990 -988
  8. package/lib/Constants.js +1163 -1161
  9. package/lib/command/Command.js +552 -552
  10. package/lib/command/CommandClient.js +460 -460
  11. package/lib/errors/DiscordHTTPError.js +63 -63
  12. package/lib/errors/DiscordRESTError.js +77 -77
  13. package/lib/gateway/Shard.js +3029 -3029
  14. package/lib/gateway/ShardManager.js +164 -164
  15. package/lib/rest/Endpoints.js +172 -172
  16. package/lib/rest/RequestHandler.js +459 -459
  17. package/lib/structures/ApplicationCommand.js +125 -125
  18. package/lib/structures/AutoModerationRule.js +143 -143
  19. package/lib/structures/AutocompleteInteraction.js +80 -80
  20. package/lib/structures/Base.js +81 -81
  21. package/lib/structures/CategoryChannel.js +77 -77
  22. package/lib/structures/Channel.js +98 -98
  23. package/lib/structures/CommandInteraction.js +473 -473
  24. package/lib/structures/ComponentInteraction.js +538 -538
  25. package/lib/structures/DMChannel.js +278 -278
  26. package/lib/structures/Entitlement.js +77 -77
  27. package/lib/structures/ExtendedUser.js +46 -46
  28. package/lib/structures/ForumChannel.js +24 -24
  29. package/lib/structures/GroupChannel.js +106 -106
  30. package/lib/structures/Guild.js +1677 -1677
  31. package/lib/structures/GuildAuditLogEntry.js +190 -190
  32. package/lib/structures/GuildChannel.js +128 -128
  33. package/lib/structures/GuildIntegration.js +99 -99
  34. package/lib/structures/GuildPreview.js +97 -97
  35. package/lib/structures/GuildScheduledEvent.js +176 -176
  36. package/lib/structures/GuildTemplate.js +76 -76
  37. package/lib/structures/GuildTextableChannel.js +260 -260
  38. package/lib/structures/Interaction.js +133 -133
  39. package/lib/structures/Invite.js +143 -143
  40. package/lib/structures/Lobby.js +108 -108
  41. package/lib/structures/LobbyMember.js +59 -59
  42. package/lib/structures/MediaChannel.js +216 -216
  43. package/lib/structures/Member.js +371 -371
  44. package/lib/structures/Message.js +708 -708
  45. package/lib/structures/ModalSubmitInteraction.js +478 -478
  46. package/lib/structures/NewsChannel.js +34 -34
  47. package/lib/structures/NewsThreadChannel.js +12 -12
  48. package/lib/structures/Permission.js +80 -80
  49. package/lib/structures/PermissionOverwrite.js +32 -32
  50. package/lib/structures/PingInteraction.js +39 -39
  51. package/lib/structures/PrivateThreadChannel.js +25 -25
  52. package/lib/structures/PublicThreadChannel.js +26 -26
  53. package/lib/structures/Role.js +163 -163
  54. package/lib/structures/SKU.js +80 -80
  55. package/lib/structures/SoundboardSound.js +79 -79
  56. package/lib/structures/StageChannel.js +59 -59
  57. package/lib/structures/StageInstance.js +55 -55
  58. package/lib/structures/Subscription.js +69 -69
  59. package/lib/structures/TextChannel.js +202 -202
  60. package/lib/structures/ThreadChannel.js +143 -143
  61. package/lib/structures/ThreadMember.js +59 -59
  62. package/lib/structures/UnavailableGuild.js +26 -26
  63. package/lib/structures/UnknownInteraction.js +502 -502
  64. package/lib/structures/User.js +296 -296
  65. package/lib/structures/VoiceChannel.js +166 -166
  66. package/lib/structures/VoiceState.js +84 -84
  67. package/lib/util/BrowserWebSocket.js +76 -76
  68. package/lib/util/Bucket.js +89 -89
  69. package/lib/util/Collection.js +202 -202
  70. package/lib/util/MultipartData.js +70 -70
  71. package/lib/util/Opus.js +33 -33
  72. package/lib/util/SequentialBucket.js +83 -83
  73. package/lib/util/emitDeprecation.js +26 -26
  74. package/lib/voice/Piper.js +300 -300
  75. package/lib/voice/SharedStream.js +238 -238
  76. package/lib/voice/VoiceConnection.js +1440 -1440
  77. package/lib/voice/VoiceConnectionManager.js +151 -151
  78. package/lib/voice/VoiceDataStream.js +22 -22
  79. package/lib/voice/streams/BaseTransformer.js +40 -40
  80. package/lib/voice/streams/DCAOpusTransformer.js +78 -78
  81. package/lib/voice/streams/FFmpegDuplex.js +192 -192
  82. package/lib/voice/streams/FFmpegOggTransformer.js +35 -35
  83. package/lib/voice/streams/FFmpegPCMTransformer.js +26 -26
  84. package/lib/voice/streams/OggOpusTransformer.js +108 -108
  85. package/lib/voice/streams/PCMOpusTransformer.js +61 -61
  86. package/lib/voice/streams/VolumeTransformer.js +50 -50
  87. package/lib/voice/streams/WebmOpusTransformer.js +258 -258
  88. package/package.json +83 -82
@@ -1,125 +1,125 @@
1
- "use strict";
2
-
3
- const Base = require("./Base");
4
- const Permission = require("./Permission");
5
-
6
- /**
7
- * Represents an application command
8
- * @prop {String} applicationID The ID of the application that this command belongs to
9
- * @prop {Array<Number>?} contexts The interaction contexts where the command can be used. See `Constants.InteractionContextTypes`
10
- * @prop {Permission?} defaultMemberPermissions The permissions required by default for this command to be usable
11
- * @prop {Boolean?} defaultPermission [DEPRECATED] Indicates whether the command is enabled by default when the application is added to a guild
12
- * @prop {String} description The description of the command (empty for user & message commands)
13
- * @prop {Object?} descriptionLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to descriptions for that locale
14
- * @prop {Boolean?} dmPermission [DEPRECATED] If this command can be used in direct messages (global commands only). Use `contexts` instead
15
- * @prop {Guild?} guild The guild associated with this command (guild commands only)
16
- * @prop {Number?} handler How the interaction is handled (`PRIMARY_ENTRY_POINT` commands only). See `Constants.EntryPointCommandHandlerTypes`
17
- * @prop {String} id The ID of the application command
18
- * @prop {Array<Number>?} integrationTypes The installation contexts where the command is available. See `Constants.ApplicationIntegrationTypes`
19
- * @prop {String} name The name of the command
20
- * @prop {Object?} nameLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to names for that locale
21
- * @prop {Boolean?} nsfw Indicates whether the command is age-restricted
22
- * @prop {Array<Object>?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command
23
- * @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
24
- * @prop {String} version The ID of the version of this command
25
- */
26
- class ApplicationCommand extends Base {
27
- constructor(data, client) {
28
- super(data.id);
29
- this._client = client;
30
- this.applicationID = data.application_id;
31
- this.name = data.name;
32
- this.description = data.description;
33
- this.defaultMemberPermissions = data.default_member_permissions == null ? null : new Permission(data.default_member_permissions);
34
- this.version = data.version;
35
-
36
- if (data.type !== undefined) {
37
- this.type = data.type;
38
- }
39
- if (data.guild_id !== undefined) {
40
- this.guild = client.guilds.get(data.guild_id) || {
41
- id: data.guild_id,
42
- };
43
- }
44
- if (data.name_localizations !== undefined) {
45
- this.nameLocalizations = data.name_localizations;
46
- }
47
- if (data.description_localizations !== undefined) {
48
- this.descriptionLocalizations = data.description_localizations;
49
- }
50
- if (data.options !== undefined) {
51
- this.options = data.options;
52
- }
53
- if (data.dm_permission !== undefined) {
54
- this.dmPermission = data.dm_permission;
55
- }
56
- if (data.default_permission !== undefined) {
57
- this.defaultPermission = data.default_permission;
58
- }
59
- if (data.nsfw !== undefined) {
60
- this.nsfw = data.nsfw;
61
- }
62
- if (data.contexts !== undefined) {
63
- this.contexts = data.contexts;
64
- }
65
- if (data.handler !== undefined) {
66
- this.handler = data.handler;
67
- }
68
- if (data.integration_types !== undefined) {
69
- this.integrationTypes = data.integration_types;
70
- }
71
- }
72
-
73
- /**
74
- * Delete the command
75
- * @returns {Promise}
76
- */
77
- delete() {
78
- return this.guild === undefined ? this._client.deleteCommand.call(this._client, this.id) : this._client.deleteGuildCommand.call(this._client, this.guild.id, this.id);
79
- }
80
-
81
- /**
82
- * Edit this application command
83
- * @arg {Object} command A command object
84
- * @arg {Array<Number>} [command.contexts] The interaction contexts where the command can be used, `0` for guilds, `1` for the app's bot DM and `2` for group DMs and other DMs. See `Constants.InteractionContextTypes`
85
- * @arg {BigInt | Number | String | Permission?} [command.defaultMemberPermissions] The default permissions the user must have to use the command
86
- * @arg {Boolean} [command.defaultPermission] [DEPRECATED] Whether the command is enabled by default when the application is added to a guild. Replaced by `defaultMemberPermissions`
87
- * @arg {String} [command.description] The command description, required for `CHAT_INPUT` commands
88
- * @arg {Object?} [command.descriptionLocalizations] Localization directory with keys in [available locales](https://discord.dev/reference#locales) for the command description
89
- * @arg {Boolean?} [command.dmPermission=true] [DEPRECATED] Whether the command is available in DMs with the app. Use `contexts` instead
90
- * @arg {Number} [command.handler] How the interaction is handled, `1` for the app (`APP_HANDLER`) or `2` for Discord launching the Activity (`DISCORD_LAUNCH_ACTIVITY`). `PRIMARY_ENTRY_POINT` commands only. See `Constants.EntryPointCommandHandlerTypes`
91
- * @arg {Array<Number>} [command.integrationTypes] The installation contexts where the command is available, `0` for guild installs and `1` for user installs. See `Constants.ApplicationIntegrationTypes`
92
- * @arg {String} [command.name] The command name
93
- * @arg {Object?} [command.nameLocalizations] Localization directory with keys in [available locales](https://discord.dev/reference#locales) for the command name
94
- * @arg {Boolean} [command.nsfw] Whether the command is age-restricted
95
- * @arg {Array<Object>} [command.options] The application command [options](https://discord.dev/interactions/application-commands#application-command-object-application-command-option-structure)
96
- * @returns {Promise<ApplicationCommand>} Resolves with the edited application command
97
- */
98
- edit(command) {
99
- return this.guild === undefined ? this._client.editCommand.call(this._client, this.id, command) : this._client.editGuildCommand.call(this._client, this.guild.id, this.id, command);
100
- }
101
-
102
- toJSON(props = []) {
103
- return super.toJSON([
104
- "applicationID",
105
- "contexts",
106
- "defaultMemberPermissions",
107
- "defaultPermission",
108
- "description",
109
- "descriptionLocalizations",
110
- "dmPermission",
111
- "guild",
112
- "handler",
113
- "integrationTypes",
114
- "name",
115
- "nameLocalizations",
116
- "nsfw",
117
- "options",
118
- "type",
119
- "version",
120
- ...props,
121
- ]);
122
- }
123
- }
124
-
125
- module.exports = ApplicationCommand;
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+ const Permission = require("./Permission");
5
+
6
+ /**
7
+ * Represents an application command
8
+ * @prop {String} applicationID The ID of the application that this command belongs to
9
+ * @prop {Array<Number>?} contexts The interaction contexts where the command can be used. See `Constants.InteractionContextTypes`
10
+ * @prop {Permission?} defaultMemberPermissions The permissions required by default for this command to be usable
11
+ * @prop {Boolean?} defaultPermission [DEPRECATED] Indicates whether the command is enabled by default when the application is added to a guild
12
+ * @prop {String} description The description of the command (empty for user & message commands)
13
+ * @prop {Object?} descriptionLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to descriptions for that locale
14
+ * @prop {Boolean?} dmPermission [DEPRECATED] If this command can be used in direct messages (global commands only). Use `contexts` instead
15
+ * @prop {Guild?} guild The guild associated with this command (guild commands only)
16
+ * @prop {Number?} handler How the interaction is handled (`PRIMARY_ENTRY_POINT` commands only). See `Constants.EntryPointCommandHandlerTypes`
17
+ * @prop {String} id The ID of the application command
18
+ * @prop {Array<Number>?} integrationTypes The installation contexts where the command is available. See `Constants.ApplicationIntegrationTypes`
19
+ * @prop {String} name The name of the command
20
+ * @prop {Object?} nameLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to names for that locale
21
+ * @prop {Boolean?} nsfw Indicates whether the command is age-restricted
22
+ * @prop {Array<Object>?} options The [options](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure) associated with this command
23
+ * @prop {Number} type The [command type](https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-types)
24
+ * @prop {String} version The ID of the version of this command
25
+ */
26
+ class ApplicationCommand extends Base {
27
+ constructor(data, client) {
28
+ super(data.id);
29
+ this._client = client;
30
+ this.applicationID = data.application_id;
31
+ this.name = data.name;
32
+ this.description = data.description;
33
+ this.defaultMemberPermissions = data.default_member_permissions == null ? null : new Permission(data.default_member_permissions);
34
+ this.version = data.version;
35
+
36
+ if (data.type !== undefined) {
37
+ this.type = data.type;
38
+ }
39
+ if (data.guild_id !== undefined) {
40
+ this.guild = client.guilds.get(data.guild_id) || {
41
+ id: data.guild_id,
42
+ };
43
+ }
44
+ if (data.name_localizations !== undefined) {
45
+ this.nameLocalizations = data.name_localizations;
46
+ }
47
+ if (data.description_localizations !== undefined) {
48
+ this.descriptionLocalizations = data.description_localizations;
49
+ }
50
+ if (data.options !== undefined) {
51
+ this.options = data.options;
52
+ }
53
+ if (data.dm_permission !== undefined) {
54
+ this.dmPermission = data.dm_permission;
55
+ }
56
+ if (data.default_permission !== undefined) {
57
+ this.defaultPermission = data.default_permission;
58
+ }
59
+ if (data.nsfw !== undefined) {
60
+ this.nsfw = data.nsfw;
61
+ }
62
+ if (data.contexts !== undefined) {
63
+ this.contexts = data.contexts;
64
+ }
65
+ if (data.handler !== undefined) {
66
+ this.handler = data.handler;
67
+ }
68
+ if (data.integration_types !== undefined) {
69
+ this.integrationTypes = data.integration_types;
70
+ }
71
+ }
72
+
73
+ /**
74
+ * Delete the command
75
+ * @returns {Promise}
76
+ */
77
+ delete() {
78
+ return this.guild === undefined ? this._client.deleteCommand.call(this._client, this.id) : this._client.deleteGuildCommand.call(this._client, this.guild.id, this.id);
79
+ }
80
+
81
+ /**
82
+ * Edit this application command
83
+ * @arg {Object} command A command object
84
+ * @arg {Array<Number>} [command.contexts] The interaction contexts where the command can be used, `0` for guilds, `1` for the app's bot DM and `2` for group DMs and other DMs. See `Constants.InteractionContextTypes`
85
+ * @arg {BigInt | Number | String | Permission?} [command.defaultMemberPermissions] The default permissions the user must have to use the command
86
+ * @arg {Boolean} [command.defaultPermission] [DEPRECATED] Whether the command is enabled by default when the application is added to a guild. Replaced by `defaultMemberPermissions`
87
+ * @arg {String} [command.description] The command description, required for `CHAT_INPUT` commands
88
+ * @arg {Object?} [command.descriptionLocalizations] Localization directory with keys in [available locales](https://discord.dev/reference#locales) for the command description
89
+ * @arg {Boolean?} [command.dmPermission=true] [DEPRECATED] Whether the command is available in DMs with the app. Use `contexts` instead
90
+ * @arg {Number} [command.handler] How the interaction is handled, `1` for the app (`APP_HANDLER`) or `2` for Discord launching the Activity (`DISCORD_LAUNCH_ACTIVITY`). `PRIMARY_ENTRY_POINT` commands only. See `Constants.EntryPointCommandHandlerTypes`
91
+ * @arg {Array<Number>} [command.integrationTypes] The installation contexts where the command is available, `0` for guild installs and `1` for user installs. See `Constants.ApplicationIntegrationTypes`
92
+ * @arg {String} [command.name] The command name
93
+ * @arg {Object?} [command.nameLocalizations] Localization directory with keys in [available locales](https://discord.dev/reference#locales) for the command name
94
+ * @arg {Boolean} [command.nsfw] Whether the command is age-restricted
95
+ * @arg {Array<Object>} [command.options] The application command [options](https://discord.dev/interactions/application-commands#application-command-object-application-command-option-structure)
96
+ * @returns {Promise<ApplicationCommand>} Resolves with the edited application command
97
+ */
98
+ edit(command) {
99
+ return this.guild === undefined ? this._client.editCommand.call(this._client, this.id, command) : this._client.editGuildCommand.call(this._client, this.guild.id, this.id, command);
100
+ }
101
+
102
+ toJSON(props = []) {
103
+ return super.toJSON([
104
+ "applicationID",
105
+ "contexts",
106
+ "defaultMemberPermissions",
107
+ "defaultPermission",
108
+ "description",
109
+ "descriptionLocalizations",
110
+ "dmPermission",
111
+ "guild",
112
+ "handler",
113
+ "integrationTypes",
114
+ "name",
115
+ "nameLocalizations",
116
+ "nsfw",
117
+ "options",
118
+ "type",
119
+ "version",
120
+ ...props,
121
+ ]);
122
+ }
123
+ }
124
+
125
+ module.exports = ApplicationCommand;
@@ -1,143 +1,143 @@
1
- "use strict";
2
-
3
- const Base = require("./Base");
4
-
5
- /**
6
- * Represents an Auto Moderation Rule
7
- * @prop {Array<Object>} actions The actions that will be executed if the rule is triggered
8
- * @prop {Object?} actions[].metadata Additional data used when an action is executed
9
- * @prop {String?} actions[].metadata.channelID The channel where user content will be logged (action type 2 only)
10
- * @prop {String?} actions[].metadata.customMessage Optional custom message up to 150 characters that will be shown to users when their message gets blocked (action type 1 only)
11
- * @prop {Number?} actions[].metadata.durationSeconds Timeout duration in seconds, up to 4 weeks (action type 3 only)
12
- * @prop {User} creator The user that created the Auto Moderation rule. If the user is uncached, this will be an object with an id key. No other properties are guaranteed
13
- * @prop {Boolean} enabled Whether the rule is enabled or not
14
- * @prop {Number} eventType Whether this rule applies for message sends (1) or member updates (2)
15
- * @prop {Array<String>} exemptChannels A list of channel IDs that aren't affected by this rule
16
- * @prop {Array<String>} exemptRoles A list of role IDs that aren't affected by this rule
17
- * @prop {Guild} guild The guild which this rule applies to. If the guild is uncached, this will be an object with an id key. No other properties are guaranteed
18
- * @prop {String} id The Auto Moderation Rule ID
19
- * @prop {String} name The name of this rule
20
- * @prop {Object} triggerMetadata Additional data used to determine whether a rule is triggered or not
21
- * @prop {Array<String>?} triggerMetadata.allowList Substrings which shouldn't trigger this rule (trigger types 1, 4 and 6 only). Max of 100 for types 1 and 6, max of 1000 for type 4
22
- * @prop {Array<String>?} triggerMetadata.keywordFilter Substrings which should trigger this rule (trigger types 1 and 6 only). Max of 1000
23
- * @prop {Boolean?} triggerMetadata.mentionRaidProtectionEnabled Whether to automatically detect mention raids
24
- * @prop {Number?} triggerMetadata.mentionTotalLimit The number of unique roles/user mentions allowed per message. Max of 50
25
- * @prop {Array<Number>?} triggerMetadata.presets The predefined wordsets which should trigger this rule. 1 for profanity, 2 for sexual content, 3 for slurs
26
- * @prop {Array<String>?} triggerMetadata.regexPatterns Rust flavored Regex patterns which should trigger this rule. Max of 10
27
- * @prop {Number} triggerType The type of content which triggers this rule
28
- */
29
- class AutoModerationRule extends Base {
30
- constructor(data, client) {
31
- super(data.id);
32
- this._client = client;
33
- this.guild = client.guilds.get(data.guild_id) || { id: data.guild_id };
34
- this.creator = client.users.get(data.creator_id) || { id: data.creator_id };
35
- this.triggerType = data.trigger_type;
36
-
37
- this.update(data);
38
- }
39
-
40
- update(data) {
41
- if (data.name !== undefined) {
42
- this.name = data.name;
43
- }
44
- if (data.event_type !== undefined) {
45
- this.eventType = data.event_type;
46
- }
47
- if (data.trigger_metadata !== undefined) {
48
- if (data.trigger_metadata.keyword_filter !== undefined) {
49
- data.trigger_metadata.keywordFilter = data.trigger_metadata.keyword_filter;
50
- delete data.trigger_metadata.keyword_filter;
51
- }
52
- if (data.trigger_metadata.regex_patterns !== undefined) {
53
- data.trigger_metadata.regexPatterns = data.trigger_metadata.regex_patterns;
54
- delete data.trigger_metadata.regex_patterns;
55
- }
56
- if (data.trigger_metadata.allow_list !== undefined) {
57
- data.trigger_metadata.allowList = data.trigger_metadata.allow_list;
58
- delete data.trigger_metadata.allow_list;
59
- }
60
- if (data.trigger_metadata.mention_total_limit !== undefined) {
61
- data.trigger_metadata.mentionTotalLimit = data.trigger_metadata.mention_total_limit;
62
- delete data.trigger_metadata.mention_total_limit;
63
- }
64
- if (data.trigger_metadata.mention_raid_protection_enabled !== undefined) {
65
- data.trigger_metadata.mentionRaidProtectionEnabled = data.trigger_metadata.mention_raid_protection_enabled;
66
- delete data.trigger_metadata.mention_raid_protection_enabled;
67
- }
68
- this.triggerMetadata = data.trigger_metadata;
69
- }
70
- if (data.actions !== undefined) {
71
- this.actions = data.actions.map((action) => {
72
- if (action.metadata) {
73
- if (action.metadata.channel_id !== undefined) {
74
- action.metadata.channelID = action.metadata.channel_id;
75
- delete action.metadata.channel_id;
76
- }
77
- if (action.metadata.duration_seconds !== undefined) {
78
- action.metadata.durationSeconds = action.metadata.duration_seconds;
79
- delete action.metadata.duration_seconds;
80
- }
81
- if (action.metadata.custom_message !== undefined) {
82
- action.metadata.customMessage = action.metadata.custom_message;
83
- delete action.metadata.custom_message;
84
- }
85
- }
86
- return action;
87
- });
88
- }
89
- if (data.enabled !== undefined) {
90
- this.enabled = data.enabled;
91
- }
92
- if (data.exempt_roles !== undefined) {
93
- this.exemptRoles = data.exempt_roles;
94
- }
95
- if (data.exempt_channels !== undefined) {
96
- this.exemptChannels = data.exempt_channels;
97
- }
98
- }
99
-
100
- /**
101
- * Delete the auto moderation rule
102
- * @arg {String} [reason] The reason to be displayed in audit logs
103
- * @returns {Promise}
104
- */
105
- delete(reason) {
106
- return this._client.deleteAutoModerationRule.call(this._client, this.guild.id, this.id, reason);
107
- }
108
-
109
- /**
110
- * Edit an existing auto moderation rule
111
- * @arg {Object} options The properties to edit
112
- * @arg {Array<Object>} [options.actions] The [actions](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object) done when the rule is violated
113
- * @arg {Boolean} [options.enabled=false] If the rule is enabled, false by default
114
- * @arg {Number} [options.eventType] The [event type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types) for the rule
115
- * @arg {Array<String>} [options.exemptChannels] Any channels where this rule does not apply
116
- * @arg {Array<String>} [options.exemptRoles] Any roles to which this rule does not apply
117
- * @arg {String} [options.name] The name of the rule
118
- * @arg {Object} [options.triggerMetadata] The [trigger metadata](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) for the rule
119
- * @arg {Number} [options.triggerType] The [trigger type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types) of the rule
120
- * @arg {String} [options.reason] The reason to be displayed in audit logs
121
- * @returns {Promise<AutoModerationRule>}
122
- */
123
- edit(options) {
124
- return this._client.editAutoModerationRule.call(this._client, this.guild.id, this.id, options);
125
- }
126
-
127
- toJSON(props = []) {
128
- return super.toJSON([
129
- "actions",
130
- "creator",
131
- "enabled",
132
- "eventType",
133
- "exemptChannels",
134
- "exemptRoles",
135
- "name",
136
- "triggerMetadata",
137
- "triggerType",
138
- ...props,
139
- ]);
140
- }
141
- }
142
-
143
- module.exports = AutoModerationRule;
1
+ "use strict";
2
+
3
+ const Base = require("./Base");
4
+
5
+ /**
6
+ * Represents an Auto Moderation Rule
7
+ * @prop {Array<Object>} actions The actions that will be executed if the rule is triggered
8
+ * @prop {Object?} actions[].metadata Additional data used when an action is executed
9
+ * @prop {String?} actions[].metadata.channelID The channel where user content will be logged (action type 2 only)
10
+ * @prop {String?} actions[].metadata.customMessage Optional custom message up to 150 characters that will be shown to users when their message gets blocked (action type 1 only)
11
+ * @prop {Number?} actions[].metadata.durationSeconds Timeout duration in seconds, up to 4 weeks (action type 3 only)
12
+ * @prop {User} creator The user that created the Auto Moderation rule. If the user is uncached, this will be an object with an id key. No other properties are guaranteed
13
+ * @prop {Boolean} enabled Whether the rule is enabled or not
14
+ * @prop {Number} eventType Whether this rule applies for message sends (1) or member updates (2)
15
+ * @prop {Array<String>} exemptChannels A list of channel IDs that aren't affected by this rule
16
+ * @prop {Array<String>} exemptRoles A list of role IDs that aren't affected by this rule
17
+ * @prop {Guild} guild The guild which this rule applies to. If the guild is uncached, this will be an object with an id key. No other properties are guaranteed
18
+ * @prop {String} id The Auto Moderation Rule ID
19
+ * @prop {String} name The name of this rule
20
+ * @prop {Object} triggerMetadata Additional data used to determine whether a rule is triggered or not
21
+ * @prop {Array<String>?} triggerMetadata.allowList Substrings which shouldn't trigger this rule (trigger types 1, 4 and 6 only). Max of 100 for types 1 and 6, max of 1000 for type 4
22
+ * @prop {Array<String>?} triggerMetadata.keywordFilter Substrings which should trigger this rule (trigger types 1 and 6 only). Max of 1000
23
+ * @prop {Boolean?} triggerMetadata.mentionRaidProtectionEnabled Whether to automatically detect mention raids
24
+ * @prop {Number?} triggerMetadata.mentionTotalLimit The number of unique roles/user mentions allowed per message. Max of 50
25
+ * @prop {Array<Number>?} triggerMetadata.presets The predefined wordsets which should trigger this rule. 1 for profanity, 2 for sexual content, 3 for slurs
26
+ * @prop {Array<String>?} triggerMetadata.regexPatterns Rust flavored Regex patterns which should trigger this rule. Max of 10
27
+ * @prop {Number} triggerType The type of content which triggers this rule
28
+ */
29
+ class AutoModerationRule extends Base {
30
+ constructor(data, client) {
31
+ super(data.id);
32
+ this._client = client;
33
+ this.guild = client.guilds.get(data.guild_id) || { id: data.guild_id };
34
+ this.creator = client.users.get(data.creator_id) || { id: data.creator_id };
35
+ this.triggerType = data.trigger_type;
36
+
37
+ this.update(data);
38
+ }
39
+
40
+ update(data) {
41
+ if (data.name !== undefined) {
42
+ this.name = data.name;
43
+ }
44
+ if (data.event_type !== undefined) {
45
+ this.eventType = data.event_type;
46
+ }
47
+ if (data.trigger_metadata !== undefined) {
48
+ if (data.trigger_metadata.keyword_filter !== undefined) {
49
+ data.trigger_metadata.keywordFilter = data.trigger_metadata.keyword_filter;
50
+ delete data.trigger_metadata.keyword_filter;
51
+ }
52
+ if (data.trigger_metadata.regex_patterns !== undefined) {
53
+ data.trigger_metadata.regexPatterns = data.trigger_metadata.regex_patterns;
54
+ delete data.trigger_metadata.regex_patterns;
55
+ }
56
+ if (data.trigger_metadata.allow_list !== undefined) {
57
+ data.trigger_metadata.allowList = data.trigger_metadata.allow_list;
58
+ delete data.trigger_metadata.allow_list;
59
+ }
60
+ if (data.trigger_metadata.mention_total_limit !== undefined) {
61
+ data.trigger_metadata.mentionTotalLimit = data.trigger_metadata.mention_total_limit;
62
+ delete data.trigger_metadata.mention_total_limit;
63
+ }
64
+ if (data.trigger_metadata.mention_raid_protection_enabled !== undefined) {
65
+ data.trigger_metadata.mentionRaidProtectionEnabled = data.trigger_metadata.mention_raid_protection_enabled;
66
+ delete data.trigger_metadata.mention_raid_protection_enabled;
67
+ }
68
+ this.triggerMetadata = data.trigger_metadata;
69
+ }
70
+ if (data.actions !== undefined) {
71
+ this.actions = data.actions.map((action) => {
72
+ if (action.metadata) {
73
+ if (action.metadata.channel_id !== undefined) {
74
+ action.metadata.channelID = action.metadata.channel_id;
75
+ delete action.metadata.channel_id;
76
+ }
77
+ if (action.metadata.duration_seconds !== undefined) {
78
+ action.metadata.durationSeconds = action.metadata.duration_seconds;
79
+ delete action.metadata.duration_seconds;
80
+ }
81
+ if (action.metadata.custom_message !== undefined) {
82
+ action.metadata.customMessage = action.metadata.custom_message;
83
+ delete action.metadata.custom_message;
84
+ }
85
+ }
86
+ return action;
87
+ });
88
+ }
89
+ if (data.enabled !== undefined) {
90
+ this.enabled = data.enabled;
91
+ }
92
+ if (data.exempt_roles !== undefined) {
93
+ this.exemptRoles = data.exempt_roles;
94
+ }
95
+ if (data.exempt_channels !== undefined) {
96
+ this.exemptChannels = data.exempt_channels;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Delete the auto moderation rule
102
+ * @arg {String} [reason] The reason to be displayed in audit logs
103
+ * @returns {Promise}
104
+ */
105
+ delete(reason) {
106
+ return this._client.deleteAutoModerationRule.call(this._client, this.guild.id, this.id, reason);
107
+ }
108
+
109
+ /**
110
+ * Edit an existing auto moderation rule
111
+ * @arg {Object} options The properties to edit
112
+ * @arg {Array<Object>} [options.actions] The [actions](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object) done when the rule is violated
113
+ * @arg {Boolean} [options.enabled=false] If the rule is enabled, false by default
114
+ * @arg {Number} [options.eventType] The [event type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types) for the rule
115
+ * @arg {Array<String>} [options.exemptChannels] Any channels where this rule does not apply
116
+ * @arg {Array<String>} [options.exemptRoles] Any roles to which this rule does not apply
117
+ * @arg {String} [options.name] The name of the rule
118
+ * @arg {Object} [options.triggerMetadata] The [trigger metadata](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) for the rule
119
+ * @arg {Number} [options.triggerType] The [trigger type](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types) of the rule
120
+ * @arg {String} [options.reason] The reason to be displayed in audit logs
121
+ * @returns {Promise<AutoModerationRule>}
122
+ */
123
+ edit(options) {
124
+ return this._client.editAutoModerationRule.call(this._client, this.guild.id, this.id, options);
125
+ }
126
+
127
+ toJSON(props = []) {
128
+ return super.toJSON([
129
+ "actions",
130
+ "creator",
131
+ "enabled",
132
+ "eventType",
133
+ "exemptChannels",
134
+ "exemptRoles",
135
+ "name",
136
+ "triggerMetadata",
137
+ "triggerType",
138
+ ...props,
139
+ ]);
140
+ }
141
+ }
142
+
143
+ module.exports = AutoModerationRule;