@velliajs/discord 1.0.2 → 1.0.4

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 (258) hide show
  1. package/README.md +4 -11
  2. package/package.json +3 -3
  3. package/src/client/BaseClient.js +7 -28
  4. package/src/client/Client.js +116 -283
  5. package/src/client/WebhookClient.js +17 -59
  6. package/src/client/actions/Action.js +0 -10
  7. package/src/client/actions/ActionsManager.js +3 -3
  8. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +2 -15
  9. package/src/client/actions/AutoModerationActionExecution.js +1 -6
  10. package/src/client/actions/AutoModerationRuleCreate.js +1 -6
  11. package/src/client/actions/AutoModerationRuleDelete.js +1 -6
  12. package/src/client/actions/AutoModerationRuleUpdate.js +1 -7
  13. package/src/client/actions/ChannelCreate.js +1 -5
  14. package/src/client/actions/ChannelDelete.js +1 -5
  15. package/src/client/actions/GuildAuditLogEntryCreate.js +1 -6
  16. package/src/client/actions/GuildBanAdd.js +1 -5
  17. package/src/client/actions/GuildBanRemove.js +1 -5
  18. package/src/client/actions/GuildDelete.js +6 -14
  19. package/src/client/actions/GuildEmojiCreate.js +1 -5
  20. package/src/client/actions/GuildEmojiDelete.js +1 -5
  21. package/src/client/actions/GuildEmojiUpdate.js +1 -6
  22. package/src/client/actions/GuildEmojisUpdate.js +4 -4
  23. package/src/client/actions/GuildIntegrationsUpdate.js +1 -5
  24. package/src/client/actions/GuildMemberRemove.js +1 -5
  25. package/src/client/actions/GuildMemberUpdate.js +2 -11
  26. package/src/client/actions/GuildRoleCreate.js +1 -5
  27. package/src/client/actions/GuildRoleDelete.js +1 -5
  28. package/src/client/actions/GuildRoleUpdate.js +1 -6
  29. package/src/client/actions/GuildScheduledEventCreate.js +1 -5
  30. package/src/client/actions/GuildScheduledEventDelete.js +1 -5
  31. package/src/client/actions/GuildScheduledEventUpdate.js +1 -6
  32. package/src/client/actions/GuildScheduledEventUserAdd.js +1 -6
  33. package/src/client/actions/GuildScheduledEventUserRemove.js +1 -6
  34. package/src/client/actions/GuildStickerCreate.js +1 -5
  35. package/src/client/actions/GuildStickerDelete.js +1 -5
  36. package/src/client/actions/GuildStickerUpdate.js +1 -6
  37. package/src/client/actions/GuildStickersUpdate.js +4 -4
  38. package/src/client/actions/GuildUpdate.js +1 -6
  39. package/src/client/actions/InteractionCreate.js +3 -7
  40. package/src/client/actions/InviteCreate.js +1 -7
  41. package/src/client/actions/InviteDelete.js +1 -7
  42. package/src/client/actions/MessageCreate.js +1 -5
  43. package/src/client/actions/MessageDelete.js +1 -5
  44. package/src/client/actions/MessageDeleteBulk.js +1 -6
  45. package/src/client/actions/MessageReactionAdd.js +5 -18
  46. package/src/client/actions/MessageReactionRemove.js +5 -16
  47. package/src/client/actions/MessageReactionRemoveAll.js +4 -9
  48. package/src/client/actions/MessageReactionRemoveEmoji.js +1 -5
  49. package/src/client/actions/PresenceUpdate.js +1 -6
  50. package/src/client/actions/StageInstanceCreate.js +1 -5
  51. package/src/client/actions/StageInstanceDelete.js +1 -5
  52. package/src/client/actions/StageInstanceUpdate.js +1 -6
  53. package/src/client/actions/ThreadCreate.js +1 -6
  54. package/src/client/actions/ThreadDelete.js +1 -5
  55. package/src/client/actions/ThreadListSync.js +2 -7
  56. package/src/client/actions/ThreadMemberUpdate.js +2 -7
  57. package/src/client/actions/ThreadMembersUpdate.js +2 -9
  58. package/src/client/actions/TypingStart.js +1 -5
  59. package/src/client/actions/UserUpdate.js +1 -8
  60. package/src/client/actions/VoiceStateUpdate.js +4 -9
  61. package/src/client/actions/WebhooksUpdate.js +1 -6
  62. package/src/client/voice/ClientVoiceManager.js +3 -13
  63. package/src/client/websocket/WebSocketManager.js +25 -117
  64. package/src/client/websocket/WebSocketShard.js +29 -116
  65. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +2 -8
  66. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -6
  67. package/src/client/websocket/handlers/GUILD_CREATE.js +3 -7
  68. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -16
  69. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -5
  70. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -6
  71. package/src/client/websocket/handlers/RESUMED.js +1 -6
  72. package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -6
  73. package/src/errors/DJSError.js +3 -14
  74. package/src/errors/ErrorCodes.js +2 -164
  75. package/src/index.js +6 -6
  76. package/src/managers/ApplicationCommandManager.js +14 -130
  77. package/src/managers/ApplicationCommandPermissionsManager.js +31 -202
  78. package/src/managers/AutoModerationRuleManager.js +17 -145
  79. package/src/managers/BaseGuildEmojiManager.js +7 -38
  80. package/src/managers/BaseManager.js +2 -10
  81. package/src/managers/CachedManager.js +3 -17
  82. package/src/managers/CategoryChannelChildManager.js +6 -48
  83. package/src/managers/ChannelManager.js +11 -52
  84. package/src/managers/DataManager.js +5 -27
  85. package/src/managers/GuildApplicationCommandManager.js +3 -12
  86. package/src/managers/GuildBanManager.js +16 -105
  87. package/src/managers/GuildChannelManager.js +31 -226
  88. package/src/managers/GuildEmojiManager.js +9 -65
  89. package/src/managers/GuildEmojiRoleManager.js +8 -47
  90. package/src/managers/GuildForumThreadManager.js +5 -39
  91. package/src/managers/GuildInviteManager.js +18 -117
  92. package/src/managers/GuildManager.js +14 -115
  93. package/src/managers/GuildMemberManager.js +38 -256
  94. package/src/managers/GuildMemberRoleManager.js +13 -76
  95. package/src/managers/GuildScheduledEventManager.js +25 -128
  96. package/src/managers/GuildStickerManager.js +16 -96
  97. package/src/managers/GuildTextThreadManager.js +4 -47
  98. package/src/managers/MessageManager.js +23 -137
  99. package/src/managers/PermissionOverwriteManager.js +10 -78
  100. package/src/managers/PresenceManager.js +6 -27
  101. package/src/managers/ReactionManager.js +7 -40
  102. package/src/managers/ReactionUserManager.js +6 -29
  103. package/src/managers/RoleManager.js +29 -177
  104. package/src/managers/StageInstanceManager.js +14 -77
  105. package/src/managers/ThreadManager.js +23 -113
  106. package/src/managers/ThreadMemberManager.js +20 -89
  107. package/src/managers/UserManager.js +13 -65
  108. package/src/managers/VoiceStateManager.js +3 -13
  109. package/src/sharding/Shard.js +42 -158
  110. package/src/sharding/ShardClientUtil.js +17 -101
  111. package/src/sharding/ShardingManager.js +34 -151
  112. package/src/structures/ActionRow.js +4 -21
  113. package/src/structures/ActionRowBuilder.js +3 -13
  114. package/src/structures/AnonymousGuild.js +10 -43
  115. package/src/structures/ApplicationCommand.js +54 -308
  116. package/src/structures/ApplicationRoleConnectionMetadata.js +7 -27
  117. package/src/structures/Attachment.js +16 -65
  118. package/src/structures/AttachmentBuilder.js +13 -58
  119. package/src/structures/AutoModerationActionExecution.js +16 -69
  120. package/src/structures/AutoModerationRule.js +32 -164
  121. package/src/structures/AutocompleteInteraction.js +10 -52
  122. package/src/structures/Base.js +2 -10
  123. package/src/structures/BaseChannel.js +16 -80
  124. package/src/structures/BaseGuild.js +13 -59
  125. package/src/structures/BaseGuildEmoji.js +5 -21
  126. package/src/structures/BaseGuildTextChannel.js +19 -100
  127. package/src/structures/BaseGuildVoiceChannel.js +21 -110
  128. package/src/structures/BaseInteraction.js +40 -196
  129. package/src/structures/BaseSelectMenuComponent.js +6 -29
  130. package/src/structures/ButtonBuilder.js +4 -18
  131. package/src/structures/ButtonComponent.js +7 -34
  132. package/src/structures/ButtonInteraction.js +1 -4
  133. package/src/structures/CategoryChannel.js +5 -30
  134. package/src/structures/ChannelSelectMenuBuilder.js +3 -13
  135. package/src/structures/ChannelSelectMenuComponent.js +2 -9
  136. package/src/structures/ChannelSelectMenuInteraction.js +3 -12
  137. package/src/structures/ChatInputCommandInteraction.js +3 -13
  138. package/src/structures/ClientApplication.js +20 -83
  139. package/src/structures/ClientPresence.js +5 -20
  140. package/src/structures/ClientUser.js +21 -118
  141. package/src/structures/CommandInteraction.js +21 -96
  142. package/src/structures/CommandInteractionOptionResolver.js +26 -147
  143. package/src/structures/Component.js +5 -21
  144. package/src/structures/ContextMenuCommandInteraction.js +4 -18
  145. package/src/structures/DMChannel.js +17 -52
  146. package/src/structures/DirectoryChannel.js +4 -16
  147. package/src/structures/Embed.js +21 -107
  148. package/src/structures/EmbedBuilder.js +4 -18
  149. package/src/structures/Emoji.js +12 -60
  150. package/src/structures/ForumChannel.js +30 -140
  151. package/src/structures/Guild.js +117 -697
  152. package/src/structures/GuildAuditLogs.js +7 -32
  153. package/src/structures/GuildAuditLogsEntry.js +27 -135
  154. package/src/structures/GuildBan.js +6 -26
  155. package/src/structures/GuildChannel.js +36 -188
  156. package/src/structures/GuildEmoji.js +13 -67
  157. package/src/structures/GuildMember.js +47 -270
  158. package/src/structures/GuildPreview.js +19 -84
  159. package/src/structures/GuildPreviewEmoji.js +3 -13
  160. package/src/structures/GuildScheduledEvent.js +46 -250
  161. package/src/structures/GuildTemplate.js +24 -108
  162. package/src/structures/Integration.js +25 -103
  163. package/src/structures/IntegrationApplication.js +8 -32
  164. package/src/structures/InteractionCollector.js +22 -113
  165. package/src/structures/InteractionResponse.js +11 -46
  166. package/src/structures/InteractionWebhook.js +8 -33
  167. package/src/structures/Invite.js +27 -131
  168. package/src/structures/InviteGuild.js +2 -8
  169. package/src/structures/InviteStageInstance.js +9 -39
  170. package/src/structures/MentionableSelectMenuBuilder.js +3 -14
  171. package/src/structures/MentionableSelectMenuComponent.js +1 -4
  172. package/src/structures/MentionableSelectMenuInteraction.js +5 -20
  173. package/src/structures/Message.js +85 -460
  174. package/src/structures/MessageCollector.js +14 -70
  175. package/src/structures/MessageComponentInteraction.js +14 -57
  176. package/src/structures/MessageContextMenuCommandInteraction.js +2 -9
  177. package/src/structures/MessageMentions.js +25 -136
  178. package/src/structures/MessagePayload.js +24 -94
  179. package/src/structures/MessageReaction.js +13 -51
  180. package/src/structures/ModalBuilder.js +3 -13
  181. package/src/structures/ModalSubmitFields.js +5 -22
  182. package/src/structures/ModalSubmitInteraction.js +17 -61
  183. package/src/structures/NewsChannel.js +2 -16
  184. package/src/structures/OAuth2Guild.js +3 -12
  185. package/src/structures/PartialGroupDMChannel.js +7 -27
  186. package/src/structures/PermissionOverwrites.js +20 -99
  187. package/src/structures/Presence.js +45 -190
  188. package/src/structures/ReactionCollector.js +20 -108
  189. package/src/structures/ReactionEmoji.js +2 -10
  190. package/src/structures/Role.js +39 -261
  191. package/src/structures/RoleSelectMenuBuilder.js +3 -13
  192. package/src/structures/RoleSelectMenuComponent.js +1 -4
  193. package/src/structures/RoleSelectMenuInteraction.js +3 -12
  194. package/src/structures/SelectMenuBuilder.js +1 -4
  195. package/src/structures/SelectMenuComponent.js +1 -4
  196. package/src/structures/SelectMenuInteraction.js +1 -4
  197. package/src/structures/SelectMenuOptionBuilder.js +1 -4
  198. package/src/structures/StageChannel.js +12 -84
  199. package/src/structures/StageInstance.js +16 -87
  200. package/src/structures/Sticker.js +25 -124
  201. package/src/structures/StickerPack.js +12 -52
  202. package/src/structures/StringSelectMenuBuilder.js +6 -29
  203. package/src/structures/StringSelectMenuComponent.js +2 -9
  204. package/src/structures/StringSelectMenuInteraction.js +2 -8
  205. package/src/structures/StringSelectMenuOptionBuilder.js +4 -18
  206. package/src/structures/Team.js +11 -52
  207. package/src/structures/TeamMember.js +7 -33
  208. package/src/structures/TextChannel.js +3 -14
  209. package/src/structures/TextInputBuilder.js +3 -13
  210. package/src/structures/TextInputComponent.js +3 -14
  211. package/src/structures/ThreadChannel.js +59 -305
  212. package/src/structures/ThreadMember.js +12 -55
  213. package/src/structures/Typing.js +8 -35
  214. package/src/structures/User.js +29 -151
  215. package/src/structures/UserContextMenuCommandInteraction.js +3 -14
  216. package/src/structures/UserSelectMenuBuilder.js +3 -13
  217. package/src/structures/UserSelectMenuComponent.js +1 -4
  218. package/src/structures/UserSelectMenuInteraction.js +4 -16
  219. package/src/structures/VoiceChannel.js +8 -67
  220. package/src/structures/VoiceRegion.js +6 -23
  221. package/src/structures/VoiceState.js +28 -140
  222. package/src/structures/Webhook.js +37 -227
  223. package/src/structures/WelcomeChannel.js +7 -29
  224. package/src/structures/WelcomeScreen.js +5 -20
  225. package/src/structures/Widget.js +9 -40
  226. package/src/structures/WidgetMember.js +15 -61
  227. package/src/structures/interfaces/Application.js +10 -49
  228. package/src/structures/interfaces/Collector.js +34 -155
  229. package/src/structures/interfaces/InteractionResponses.js +25 -164
  230. package/src/structures/interfaces/TextBasedChannel.js +37 -232
  231. package/src/util/APITypes.js +183 -456
  232. package/src/util/ActivityFlagsBitField.js +3 -15
  233. package/src/util/ApplicationFlagsBitField.js +3 -15
  234. package/src/util/BitField.js +17 -82
  235. package/src/util/ChannelFlagsBitField.js +7 -30
  236. package/src/util/Channels.js +5 -35
  237. package/src/util/Colors.js +3 -38
  238. package/src/util/Components.js +21 -75
  239. package/src/util/Constants.js +17 -144
  240. package/src/util/DataResolver.js +20 -77
  241. package/src/util/Events.js +3 -81
  242. package/src/util/Formatters.js +58 -305
  243. package/src/util/GuildMemberFlagsBitField.js +7 -30
  244. package/src/util/IntentsBitField.js +4 -23
  245. package/src/util/LimitedCollection.js +4 -21
  246. package/src/util/MessageFlagsBitField.js +5 -21
  247. package/src/util/Options.js +24 -137
  248. package/src/util/Partials.js +3 -30
  249. package/src/util/PermissionsBitField.js +12 -67
  250. package/src/util/ShardEvents.js +3 -15
  251. package/src/util/Status.js +3 -17
  252. package/src/util/Sweepers.js +35 -184
  253. package/src/util/SystemChannelFlagsBitField.js +7 -32
  254. package/src/util/ThreadMemberFlagsBitField.js +5 -21
  255. package/src/util/Transformers.js +2 -11
  256. package/src/util/UserFlagsBitField.js +5 -21
  257. package/src/util/Util.js +30 -169
  258. package/src/util/WebSocketShardEvents.js +3 -14
@@ -2,132 +2,83 @@
2
2
 
3
3
  const { basename, flatten } = require('../util/Util');
4
4
 
5
- /**
6
- * @typedef {Object} AttachmentPayload
7
- * @property {?string} name The name of the attachment
8
- * @property {Stream|BufferResolvable} attachment The attachment in this payload
9
- * @property {?string} description The description of the attachment
10
- */
11
-
12
- /**
13
- * Represents an attachment
14
- */
5
+
6
+
7
+
15
8
  class Attachment {
16
9
  constructor(data) {
17
10
  this.attachment = data.url;
18
- /**
19
- * The name of this attachment
20
- * @type {string}
21
- */
11
+
22
12
  this.name = data.filename;
23
13
  this._patch(data);
24
14
  }
25
15
 
26
16
  _patch(data) {
27
- /**
28
- * The attachment's id
29
- * @type {Snowflake}
30
- */
17
+
31
18
  this.id = data.id;
32
19
 
33
20
  if ('size' in data) {
34
- /**
35
- * The size of this attachment in bytes
36
- * @type {number}
37
- */
21
+
38
22
  this.size = data.size;
39
23
  }
40
24
 
41
25
  if ('url' in data) {
42
- /**
43
- * The URL to this attachment
44
- * @type {string}
45
- */
26
+
46
27
  this.url = data.url;
47
28
  }
48
29
 
49
30
  if ('proxy_url' in data) {
50
- /**
51
- * The Proxy URL to this attachment
52
- * @type {string}
53
- */
31
+
54
32
  this.proxyURL = data.proxy_url;
55
33
  }
56
34
 
57
35
  if ('height' in data) {
58
- /**
59
- * The height of this attachment (if an image or video)
60
- * @type {?number}
61
- */
36
+
62
37
  this.height = data.height;
63
38
  } else {
64
39
  this.height ??= null;
65
40
  }
66
41
 
67
42
  if ('width' in data) {
68
- /**
69
- * The width of this attachment (if an image or video)
70
- * @type {?number}
71
- */
43
+
72
44
  this.width = data.width;
73
45
  } else {
74
46
  this.width ??= null;
75
47
  }
76
48
 
77
49
  if ('content_type' in data) {
78
- /**
79
- * The media type of this attachment
80
- * @type {?string}
81
- */
50
+
82
51
  this.contentType = data.content_type;
83
52
  } else {
84
53
  this.contentType ??= null;
85
54
  }
86
55
 
87
56
  if ('description' in data) {
88
- /**
89
- * The description (alt text) of this attachment
90
- * @type {?string}
91
- */
57
+
92
58
  this.description = data.description;
93
59
  } else {
94
60
  this.description ??= null;
95
61
  }
96
62
 
97
- /**
98
- * Whether this attachment is ephemeral
99
- * @type {boolean}
100
- */
63
+
101
64
  this.ephemeral = data.ephemeral ?? false;
102
65
 
103
66
  if ('duration_secs' in data) {
104
- /**
105
- * The duration of this attachment in seconds
106
- * <info>This will only be available if the attachment is an audio file.</info>
107
- * @type {?number}
108
- */
67
+
109
68
  this.duration = data.duration_secs;
110
69
  } else {
111
70
  this.duration ??= null;
112
71
  }
113
72
 
114
73
  if ('waveform' in data) {
115
- /**
116
- * The base64 encoded byte array representing a sampled waveform
117
- * <info>This will only be available if the attachment is an audio file.</info>
118
- * @type {?string}
119
- */
74
+
120
75
  this.waveform = data.waveform;
121
76
  } else {
122
77
  this.waveform ??= null;
123
78
  }
124
79
  }
125
80
 
126
- /**
127
- * Whether or not this attachment has been marked as a spoiler
128
- * @type {boolean}
129
- * @readonly
130
- */
81
+
131
82
  get spoiler() {
132
83
  return basename(this.url ?? this.name).startsWith('SPOILER_');
133
84
  }
@@ -2,67 +2,37 @@
2
2
 
3
3
  const { basename, flatten } = require('../util/Util');
4
4
 
5
- /**
6
- * Represents an attachment builder
7
- */
5
+
8
6
  class AttachmentBuilder {
9
- /**
10
- * @param {BufferResolvable|Stream} attachment The file
11
- * @param {AttachmentData} [data] Extra data
12
- */
7
+
13
8
  constructor(attachment, data = {}) {
14
- /**
15
- * The file associated with this attachment.
16
- * @type {BufferResolvable|Stream}
17
- */
9
+
18
10
  this.attachment = attachment;
19
- /**
20
- * The name of this attachment
21
- * @type {?string}
22
- */
11
+
23
12
  this.name = data.name;
24
- /**
25
- * The description of the attachment
26
- * @type {?string}
27
- */
13
+
28
14
  this.description = data.description;
29
15
  }
30
16
 
31
- /**
32
- * Sets the description of this attachment.
33
- * @param {string} description The description of the file
34
- * @returns {AttachmentBuilder} This attachment
35
- */
17
+
36
18
  setDescription(description) {
37
19
  this.description = description;
38
20
  return this;
39
21
  }
40
22
 
41
- /**
42
- * Sets the file of this attachment.
43
- * @param {BufferResolvable|Stream} attachment The file
44
- * @returns {AttachmentBuilder} This attachment
45
- */
23
+
46
24
  setFile(attachment) {
47
25
  this.attachment = attachment;
48
26
  return this;
49
27
  }
50
28
 
51
- /**
52
- * Sets the name of this attachment.
53
- * @param {string} name The name of the file
54
- * @returns {AttachmentBuilder} This attachment
55
- */
29
+
56
30
  setName(name) {
57
31
  this.name = name;
58
32
  return this;
59
33
  }
60
34
 
61
- /**
62
- * Sets whether this attachment is a spoiler
63
- * @param {boolean} [spoiler=true] Whether the attachment should be marked as a spoiler
64
- * @returns {AttachmentBuilder} This attachment
65
- */
35
+
66
36
  setSpoiler(spoiler = true) {
67
37
  if (spoiler === this.spoiler) return this;
68
38
 
@@ -76,11 +46,7 @@ class AttachmentBuilder {
76
46
  return this;
77
47
  }
78
48
 
79
- /**
80
- * Whether or not this attachment has been marked as a spoiler
81
- * @type {boolean}
82
- * @readonly
83
- */
49
+
84
50
  get spoiler() {
85
51
  return basename(this.name).startsWith('SPOILER_');
86
52
  }
@@ -89,11 +55,7 @@ class AttachmentBuilder {
89
55
  return flatten(this);
90
56
  }
91
57
 
92
- /**
93
- * Makes a new builder instance from a preexisting attachment structure.
94
- * @param {AttachmentBuilder|Attachment|AttachmentPayload} other The builder to construct a new instance from
95
- * @returns {AttachmentBuilder}
96
- */
58
+
97
59
  static from(other) {
98
60
  return new AttachmentBuilder(other.attachment, {
99
61
  name: other.name,
@@ -104,13 +66,6 @@ class AttachmentBuilder {
104
66
 
105
67
  module.exports = AttachmentBuilder;
106
68
 
107
- /**
108
- * @external APIAttachment
109
- * @see {@link https://discord.com/developers/docs/resources/channel#attachment-object}
110
- */
111
69
 
112
- /**
113
- * @typedef {Object} AttachmentData
114
- * @property {string} [name] The name of the attachment
115
- * @property {string} [description] The description of the attachment
116
- */
70
+
71
+
@@ -2,112 +2,59 @@
2
2
 
3
3
  const { _transformAPIAutoModerationAction } = require('../util/Transformers');
4
4
 
5
- /**
6
- * Represents the structure of an executed action when an {@link AutoModerationRule} is triggered.
7
- */
5
+
8
6
  class AutoModerationActionExecution {
9
7
  constructor(data, guild) {
10
- /**
11
- * The guild where this action was executed from.
12
- * @type {Guild}
13
- */
8
+
14
9
  this.guild = guild;
15
10
 
16
- /**
17
- * The action that was executed.
18
- * @type {AutoModerationAction}
19
- */
11
+
20
12
  this.action = _transformAPIAutoModerationAction(data.action);
21
13
 
22
- /**
23
- * The id of the auto moderation rule this action belongs to.
24
- * @type {Snowflake}
25
- */
14
+
26
15
  this.ruleId = data.rule_id;
27
16
 
28
- /**
29
- * The trigger type of the auto moderation rule which was triggered.
30
- * @type {AutoModerationRuleTriggerType}
31
- */
17
+
32
18
  this.ruleTriggerType = data.rule_trigger_type;
33
19
 
34
- /**
35
- * The id of the user that triggered this action.
36
- * @type {Snowflake}
37
- */
20
+
38
21
  this.userId = data.user_id;
39
22
 
40
- /**
41
- * The id of the channel where this action was triggered from.
42
- * @type {?Snowflake}
43
- */
23
+
44
24
  this.channelId = data.channel_id ?? null;
45
25
 
46
- /**
47
- * The id of the message that triggered this action.
48
- * <info>This will not be present if the message was blocked or the content was not part of any message.</info>
49
- * @type {?Snowflake}
50
- */
26
+
51
27
  this.messageId = data.message_id ?? null;
52
28
 
53
- /**
54
- * The id of any system auto moderation messages posted as a result of this action.
55
- * @type {?Snowflake}
56
- */
29
+
57
30
  this.alertSystemMessageId = data.alert_system_message_id ?? null;
58
31
 
59
- /**
60
- * The content that triggered this action.
61
- * <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged gateway intent.</info>
62
- * @type {string}
63
- */
32
+
64
33
  this.content = data.content;
65
34
 
66
- /**
67
- * The word or phrase configured in the rule that triggered this action.
68
- * @type {?string}
69
- */
35
+
70
36
  this.matchedKeyword = data.matched_keyword ?? null;
71
37
 
72
- /**
73
- * The substring in content that triggered this action.
74
- * @type {?string}
75
- */
38
+
76
39
  this.matchedContent = data.matched_content ?? null;
77
40
  }
78
41
 
79
- /**
80
- * The auto moderation rule this action belongs to.
81
- * @type {?AutoModerationRule}
82
- * @readonly
83
- */
42
+
84
43
  get autoModerationRule() {
85
44
  return this.guild.autoModerationRules.cache.get(this.ruleId) ?? null;
86
45
  }
87
46
 
88
- /**
89
- * The channel where this action was triggered from.
90
- * @type {?TextBasedChannel}
91
- * @readonly
92
- */
47
+
93
48
  get channel() {
94
49
  return this.guild.channels.cache.get(this.channelId) ?? null;
95
50
  }
96
51
 
97
- /**
98
- * The user that triggered this action.
99
- * @type {?User}
100
- * @readonly
101
- */
52
+
102
53
  get user() {
103
54
  return this.guild.client.users.cache.get(this.userId) ?? null;
104
55
  }
105
56
 
106
- /**
107
- * The guild member that triggered this action.
108
- * @type {?GuildMember}
109
- * @readonly
110
- */
57
+
111
58
  get member() {
112
59
  return this.guild.members.cache.get(this.userId) ?? null;
113
60
  }
@@ -4,36 +4,21 @@ const { Collection } = require('@discordjs/collection');
4
4
  const Base = require('./Base');
5
5
  const { _transformAPIAutoModerationAction } = require('../util/Transformers');
6
6
 
7
- /**
8
- * Represents an auto moderation rule.
9
- * @extends {Base}
10
- */
7
+
11
8
  class AutoModerationRule extends Base {
12
9
  constructor(client, data, guild) {
13
10
  super(client);
14
11
 
15
- /**
16
- * The id of this auto moderation rule.
17
- * @type {Snowflake}
18
- */
12
+
19
13
  this.id = data.id;
20
14
 
21
- /**
22
- * The guild this auto moderation rule is for.
23
- * @type {Guild}
24
- */
15
+
25
16
  this.guild = guild;
26
17
 
27
- /**
28
- * The user that created this auto moderation rule.
29
- * @type {Snowflake}
30
- */
18
+
31
19
  this.creatorId = data.creator_id;
32
20
 
33
- /**
34
- * The trigger type of this auto moderation rule.
35
- * @type {AutoModerationRuleTriggerType}
36
- */
21
+
37
22
  this.triggerType = data.trigger_type;
38
23
 
39
24
  this._patch(data);
@@ -41,40 +26,19 @@ class AutoModerationRule extends Base {
41
26
 
42
27
  _patch(data) {
43
28
  if ('name' in data) {
44
- /**
45
- * The name of this auto moderation rule.
46
- * @type {string}
47
- */
29
+
48
30
  this.name = data.name;
49
31
  }
50
32
 
51
33
  if ('event_type' in data) {
52
- /**
53
- * The event type of this auto moderation rule.
54
- * @type {AutoModerationRuleEventType}
55
- */
34
+
56
35
  this.eventType = data.event_type;
57
36
  }
58
37
 
59
38
  if ('trigger_metadata' in data) {
60
- /**
61
- * Additional data used to determine whether an auto moderation rule should be triggered.
62
- * @typedef {Object} AutoModerationTriggerMetadata
63
- * @property {string[]} keywordFilter The substrings that will be searched for in the content
64
- * @property {string[]} regexPatterns The regular expression patterns which will be matched against the content
65
- * <info>Only Rust-flavored regular expressions are supported.</info>
66
- * @property {AutoModerationRuleKeywordPresetType[]} presets
67
- * The internally pre-defined wordsets which will be searched for in the content
68
- * @property {string[]} allowList The substrings that will be exempt from triggering
69
- * {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.KeywordPreset}
70
- * @property {?number} mentionTotalLimit The total number of role & user mentions allowed per message
71
- * @property {boolean} mentionRaidProtectionEnabled Whether mention raid protection is enabled
72
- */
73
-
74
- /**
75
- * The trigger metadata of the rule.
76
- * @type {AutoModerationTriggerMetadata}
77
- */
39
+
40
+
41
+
78
42
  this.triggerMetadata = {
79
43
  keywordFilter: data.trigger_metadata.keyword_filter ?? [],
80
44
  regexPatterns: data.trigger_metadata.regex_patterns ?? [],
@@ -86,196 +50,100 @@ class AutoModerationRule extends Base {
86
50
  }
87
51
 
88
52
  if ('actions' in data) {
89
- /**
90
- * An object containing information about an auto moderation rule action.
91
- * @typedef {Object} AutoModerationAction
92
- * @property {AutoModerationActionType} type The type of this auto moderation rule action
93
- * @property {AutoModerationActionMetadata} metadata Additional metadata needed during execution
94
- */
95
-
96
- /**
97
- * Additional data used when an auto moderation rule is executed.
98
- * @typedef {Object} AutoModerationActionMetadata
99
- * @property {?Snowflake} channelId The id of the channel to which content will be logged
100
- * @property {?number} durationSeconds The timeout duration in seconds
101
- * @property {?string} customMessage The custom message that is shown whenever a message is blocked
102
- */
103
-
104
- /**
105
- * The actions of this auto moderation rule.
106
- * @type {AutoModerationAction[]}
107
- */
53
+
54
+
55
+
56
+
57
+
108
58
  this.actions = data.actions.map(action => _transformAPIAutoModerationAction(action));
109
59
  }
110
60
 
111
61
  if ('enabled' in data) {
112
- /**
113
- * Whether this auto moderation rule is enabled.
114
- * @type {boolean}
115
- */
62
+
116
63
  this.enabled = data.enabled;
117
64
  }
118
65
 
119
66
  if ('exempt_roles' in data) {
120
- /**
121
- * The roles exempt by this auto moderation rule.
122
- * @type {Collection<Snowflake, Role>}
123
- */
67
+
124
68
  this.exemptRoles = new Collection(
125
69
  data.exempt_roles.map(exemptRole => [exemptRole, this.guild.roles.cache.get(exemptRole)]),
126
70
  );
127
71
  }
128
72
 
129
73
  if ('exempt_channels' in data) {
130
- /**
131
- * The channels exempt by this auto moderation rule.
132
- * @type {Collection<Snowflake, GuildChannel|ThreadChannel>}
133
- */
74
+
134
75
  this.exemptChannels = new Collection(
135
76
  data.exempt_channels.map(exemptChannel => [exemptChannel, this.guild.channels.cache.get(exemptChannel)]),
136
77
  );
137
78
  }
138
79
  }
139
80
 
140
- /**
141
- * Edits this auto moderation rule.
142
- * @param {AutoModerationRuleEditOptions} options Options for editing this auto moderation rule
143
- * @returns {Promise<AutoModerationRule>}
144
- */
81
+
145
82
  edit(options) {
146
83
  return this.guild.autoModerationRules.edit(this.id, options);
147
84
  }
148
85
 
149
- /**
150
- * Deletes this auto moderation rule.
151
- * @param {string} [reason] The reason for deleting this auto moderation rule
152
- * @returns {Promise<void>}
153
- */
86
+
154
87
  delete(reason) {
155
88
  return this.guild.autoModerationRules.delete(this.id, reason);
156
89
  }
157
90
 
158
- /**
159
- * Sets the name for this auto moderation rule.
160
- * @param {string} name The name of this auto moderation rule
161
- * @param {string} [reason] The reason for changing the name of this auto moderation rule
162
- * @returns {Promise<AutoModerationRule>}
163
- */
91
+
164
92
  setName(name, reason) {
165
93
  return this.edit({ name, reason });
166
94
  }
167
95
 
168
- /**
169
- * Sets the event type for this auto moderation rule.
170
- * @param {AutoModerationRuleEventType} eventType The event type of this auto moderation rule
171
- * @param {string} [reason] The reason for changing the event type of this auto moderation rule
172
- * @returns {Promise<AutoModerationRule>}
173
- */
96
+
174
97
  setEventType(eventType, reason) {
175
98
  return this.edit({ eventType, reason });
176
99
  }
177
100
 
178
- /**
179
- * Sets the keyword filter for this auto moderation rule.
180
- * @param {string[]} keywordFilter The keyword filter of this auto moderation rule
181
- * @param {string} [reason] The reason for changing the keyword filter of this auto moderation rule
182
- * @returns {Promise<AutoModerationRule>}
183
- */
101
+
184
102
  setKeywordFilter(keywordFilter, reason) {
185
103
  return this.edit({ triggerMetadata: { ...this.triggerMetadata, keywordFilter }, reason });
186
104
  }
187
105
 
188
- /**
189
- * Sets the regular expression patterns for this auto moderation rule.
190
- * @param {string[]} regexPatterns The regular expression patterns of this auto moderation rule
191
- * <info>Only Rust-flavored regular expressions are supported.</info>
192
- * @param {string} [reason] The reason for changing the regular expression patterns of this auto moderation rule
193
- * @returns {Promise<AutoModerationRule>}
194
- */
106
+
195
107
  setRegexPatterns(regexPatterns, reason) {
196
108
  return this.edit({ triggerMetadata: { ...this.triggerMetadata, regexPatterns }, reason });
197
109
  }
198
110
 
199
- /**
200
- * Sets the presets for this auto moderation rule.
201
- * @param {AutoModerationRuleKeywordPresetType[]} presets The presets of this auto moderation rule
202
- * @param {string} [reason] The reason for changing the presets of this auto moderation rule
203
- * @returns {Promise<AutoModerationRule>}
204
- */
111
+
205
112
  setPresets(presets, reason) {
206
113
  return this.edit({ triggerMetadata: { ...this.triggerMetadata, presets }, reason });
207
114
  }
208
115
 
209
- /**
210
- * Sets the allow list for this auto moderation rule.
211
- * @param {string[]} allowList The substrings that will be exempt from triggering
212
- * {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.KeywordPreset}
213
- * @param {string} [reason] The reason for changing the allow list of this auto moderation rule
214
- * @returns {Promise<AutoModerationRule>}
215
- */
116
+
216
117
  setAllowList(allowList, reason) {
217
118
  return this.edit({ triggerMetadata: { ...this.triggerMetadata, allowList }, reason });
218
119
  }
219
120
 
220
- /**
221
- * Sets the mention total limit for this auto moderation rule.
222
- * @param {number} mentionTotalLimit The total number of unique role and user mentions allowed per message
223
- * @param {string} [reason] The reason for changing the mention total limit of this auto moderation rule
224
- * @returns {Promise<AutoModerationRule>}
225
- */
121
+
226
122
  setMentionTotalLimit(mentionTotalLimit, reason) {
227
123
  return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionTotalLimit }, reason });
228
124
  }
229
125
 
230
- /**
231
- * Sets whether to enable mention raid protection for this auto moderation rule.
232
- * @param {boolean} mentionRaidProtectionEnabled
233
- * Whether to enable mention raid protection for this auto moderation rule
234
- * @param {string} [reason] The reason for changing the mention raid protection of this auto moderation rule
235
- * @returns {Promise<AutoModerationRule>}
236
- */
126
+
237
127
  setMentionRaidProtectionEnabled(mentionRaidProtectionEnabled, reason) {
238
128
  return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionRaidProtectionEnabled }, reason });
239
129
  }
240
130
 
241
- /**
242
- * Sets the actions for this auto moderation rule.
243
- * @param {AutoModerationActionOptions[]} actions The actions of this auto moderation rule
244
- * @param {string} [reason] The reason for changing the actions of this auto moderation rule
245
- * @returns {Promise<AutoModerationRule>}
246
- */
131
+
247
132
  setActions(actions, reason) {
248
133
  return this.edit({ actions, reason });
249
134
  }
250
135
 
251
- /**
252
- * Sets whether this auto moderation rule should be enabled.
253
- * @param {boolean} [enabled=true] Whether to enable this auto moderation rule
254
- * @param {string} [reason] The reason for enabling or disabling this auto moderation rule
255
- * @returns {Promise<AutoModerationRule>}
256
- */
136
+
257
137
  setEnabled(enabled = true, reason) {
258
138
  return this.edit({ enabled, reason });
259
139
  }
260
140
 
261
- /**
262
- * Sets the exempt roles for this auto moderation rule.
263
- * @param {Collection<Snowflake, Role>|RoleResolvable[]} [exemptRoles]
264
- * The roles that should not be affected by the auto moderation rule
265
- * @param {string} [reason] The reason for changing the exempt roles of this auto moderation rule
266
- * @returns {Promise<AutoModerationRule>}
267
- */
141
+
268
142
  setExemptRoles(exemptRoles, reason) {
269
143
  return this.edit({ exemptRoles, reason });
270
144
  }
271
145
 
272
- /**
273
- * Sets the exempt channels for this auto moderation rule.
274
- * @param {Collection<Snowflake, GuildChannel|ThreadChannel>|GuildChannelResolvable[]} [exemptChannels]
275
- * The channels that should not be affected by the auto moderation rule
276
- * @param {string} [reason] The reason for changing the exempt channels of this auto moderation rule
277
- * @returns {Promise<AutoModerationRule>}
278
- */
146
+
279
147
  setExemptChannels(exemptChannels, reason) {
280
148
  return this.edit({ exemptChannels, reason });
281
149
  }