@discordjs/structures 0.2.0-dev.1769083302-838cd2da3 → 0.2.0-dev.1769385723-323d8e757

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.
package/dist/index.mjs CHANGED
@@ -1,6 +1,338 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/utils/symbols.ts
5
+ var kData = /* @__PURE__ */ Symbol.for("djs.structures.data");
6
+ var kClone = /* @__PURE__ */ Symbol.for("djs.structures.clone");
7
+ var kPatch = /* @__PURE__ */ Symbol.for("djs.structures.patch");
8
+ var kExpiresTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.expiresTimestamp");
9
+ var kEndedTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.endedTimestamp");
10
+ var kCreatedTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.createdTimestamp");
11
+ var kEditedTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.editedTimestamp");
12
+ var kArchiveTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.archiveTimestamp");
13
+ var kStartsTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.startsTimestamp");
14
+ var kEndsTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.endsTimestamp");
15
+ var kAllow = /* @__PURE__ */ Symbol.for("djs.structures.allow");
16
+ var kDeny = /* @__PURE__ */ Symbol.for("djs.structures.deny");
17
+ var kBurstColors = /* @__PURE__ */ Symbol.for("djs.structures.burstColors");
18
+ var kLastPinTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.lastPinTimestamp");
19
+ var kMixinConstruct = /* @__PURE__ */ Symbol.for("djs.structures.mixin.construct");
20
+ var kMixinToJSON = /* @__PURE__ */ Symbol.for("djs.structures.mixin.toJSON");
21
+
22
+ // src/Structure.ts
23
+ var DataTemplatePropertyName = "DataTemplate";
24
+ var OptimizeDataPropertyName = "optimizeData";
25
+ var Structure = class {
26
+ static {
27
+ __name(this, "Structure");
28
+ }
29
+ /**
30
+ * The template used for removing data from the raw data stored for each Structure.
31
+ *
32
+ * @remarks This template should be overridden in all subclasses to provide more accurate type information.
33
+ * The template in the base {@link Structure} class will have no effect on most subclasses for this reason.
34
+ */
35
+ static DataTemplate = {};
36
+ /**
37
+ * @returns A cloned version of the data template, ready to create a new data object.
38
+ */
39
+ getDataTemplate() {
40
+ return Object.create(this.constructor.DataTemplate);
41
+ }
42
+ /**
43
+ * The raw data from the API for this structure
44
+ *
45
+ * @internal
46
+ */
47
+ [kData];
48
+ /**
49
+ * Creates a new structure to represent API data
50
+ *
51
+ * @param data - the data from the API that this structure will represent
52
+ * @remarks To be made public in subclasses
53
+ * @internal
54
+ */
55
+ constructor(data, ..._rest) {
56
+ this[kData] = Object.assign(this.getDataTemplate(), data);
57
+ this[kMixinConstruct]?.(data);
58
+ }
59
+ /**
60
+ * Patches the raw data of this object in place
61
+ *
62
+ * @param data - the updated data from the API to patch with
63
+ * @remarks To be made public in subclasses
64
+ * @returns this
65
+ * @internal
66
+ */
67
+ [kPatch](data) {
68
+ this[kData] = Object.assign(this.getDataTemplate(), this[kData], data);
69
+ this.optimizeData(data);
70
+ return this;
71
+ }
72
+ /**
73
+ * Creates a clone of this structure
74
+ *
75
+ * @returns a clone of this
76
+ * @internal
77
+ */
78
+ [kClone](patchPayload) {
79
+ const clone = this.toJSON();
80
+ return new this.constructor(
81
+ // Ensure the ts-expect-error only applies to the constructor call
82
+ patchPayload ? Object.assign(clone, patchPayload) : clone
83
+ );
84
+ }
85
+ /**
86
+ * Function called to ensure stored raw data is in optimized formats, used in tandem with a data template
87
+ *
88
+ * @example created_timestamp is an ISO string, this can be stored in optimized form as a number
89
+ * @param _data - the raw data received from the API to optimize
90
+ * @remarks Implementation to be done in subclasses and mixins where needed.
91
+ * For typescript users, mixins must use the closest ancestors access modifier.
92
+ * @remarks Automatically called in Structure[kPatch] but must be called manually in the constructor
93
+ * of any class implementing this method.
94
+ * @remarks Additionally, when implementing, ensure to call `super._optimizeData` if any class in the super chain aside
95
+ * from Structure contains an implementation.
96
+ * Note: mixins do not need to call super ever as the process of mixing walks the prototype chain.
97
+ * @virtual
98
+ * @internal
99
+ */
100
+ optimizeData(_data) {
101
+ }
102
+ /**
103
+ * Transforms this object to its JSON format with raw API data (or close to it),
104
+ * automatically called by `JSON.stringify()` when this structure is stringified
105
+ *
106
+ * @remarks
107
+ * The type of this data is determined by omissions at runtime and is only guaranteed for default omissions
108
+ * @privateRemarks
109
+ * When omitting properties at the library level, this must be overridden to re-add those properties
110
+ */
111
+ toJSON() {
112
+ const data = (
113
+ // Spread is way faster than structuredClone, but is shallow. So use it only if there is no nested objects
114
+ Object.values(this[kData]).some((value) => typeof value === "object" && value !== null) ? structuredClone(this[kData]) : { ...this[kData] }
115
+ );
116
+ this[kMixinToJSON]?.(data);
117
+ return data;
118
+ }
119
+ };
120
+
121
+ // src/automoderation/actions/AutoModerationAction.ts
122
+ var AutoModerationAction = class extends Structure {
123
+ static {
124
+ __name(this, "AutoModerationAction");
125
+ }
126
+ /**
127
+ * The template used for removing data from the raw data stored for each auto moderation action
128
+ */
129
+ static DataTemplate = {};
130
+ /**
131
+ * @param data - The raw data received from the API for the auto moderation action
132
+ */
133
+ constructor(data) {
134
+ super(data);
135
+ }
136
+ /**
137
+ * The {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types | action type}
138
+ */
139
+ get type() {
140
+ return this[kData].type;
141
+ }
142
+ };
143
+
144
+ // src/automoderation/actions/AutoModerationActionMetadata.ts
145
+ var AutoModerationActionMetadata = class extends Structure {
146
+ static {
147
+ __name(this, "AutoModerationActionMetadata");
148
+ }
149
+ /**
150
+ * The template used for removing data from the raw data stored for each auto moderation action metadata
151
+ */
152
+ static DataTemplate = {};
153
+ /**
154
+ * @param data - The raw data received from the API for the auto moderation action metadata
155
+ */
156
+ constructor(data) {
157
+ super(data);
158
+ }
159
+ /**
160
+ * Channel to which user content should be logged. This must be an existing channel
161
+ *
162
+ * Associated action types: {@link AutoModerationActionType.SendAlertMessage}
163
+ */
164
+ get channelId() {
165
+ return this[kData].channel_id;
166
+ }
167
+ /**
168
+ * Timeout duration in seconds. Maximum of 2419200 seconds (4 weeks).
169
+ *
170
+ * A `TIMEOUT` action can only be set up for {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.MentionSpam}.
171
+ *
172
+ * The `MODERATE_MEMBERS` permission is required to use {@link AutoModerationActionType.Timeout} actions.
173
+ *
174
+ * Associated action types: {@link AutoModerationActionType.Timeout}
175
+ */
176
+ get durationSeconds() {
177
+ return this[kData].duration_seconds;
178
+ }
179
+ /**
180
+ * Additional explanation that will be shown to members whenever their message is blocked. Maximum of 150 characters
181
+ *
182
+ * Associated action types: {@link AutoModerationActionType.BlockMessage}
183
+ */
184
+ get customMessage() {
185
+ return this[kData].custom_message;
186
+ }
187
+ };
188
+
189
+ // src/automoderation/AutoModerationRule.ts
190
+ var AutoModerationRule = class extends Structure {
191
+ static {
192
+ __name(this, "AutoModerationRule");
193
+ }
194
+ /**
195
+ * The template used for removing data from the raw data stored for each auto moderation rule
196
+ */
197
+ static DataTemplate = {};
198
+ /**
199
+ * @param data - The raw data received from the API for the auto moderation rule
200
+ */
201
+ constructor(data) {
202
+ super(data);
203
+ }
204
+ /**
205
+ * The id of this rule
206
+ */
207
+ get id() {
208
+ return this[kData].id;
209
+ }
210
+ /**
211
+ * The id of the guild which this rule belongs to
212
+ */
213
+ get guildId() {
214
+ return this[kData].guild_id;
215
+ }
216
+ /**
217
+ * The rule name
218
+ */
219
+ get name() {
220
+ return this[kData].name;
221
+ }
222
+ /**
223
+ * The user who first created this rule
224
+ */
225
+ get creatorId() {
226
+ return this[kData].creator_id;
227
+ }
228
+ /**
229
+ * The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types | event type}
230
+ */
231
+ get eventType() {
232
+ return this[kData].event_type;
233
+ }
234
+ /**
235
+ * The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | trigger type}
236
+ */
237
+ get triggerType() {
238
+ return this[kData].trigger_type;
239
+ }
240
+ /**
241
+ * Whether the rule is enabled
242
+ */
243
+ get enabled() {
244
+ return this[kData].enabled;
245
+ }
246
+ };
247
+
248
+ // src/automoderation/AutoModerationRuleTriggerMetadata.ts
249
+ var AutoModerationRuleTriggerMetadata = class extends Structure {
250
+ static {
251
+ __name(this, "AutoModerationRuleTriggerMetadata");
252
+ }
253
+ /**
254
+ * The template used for removing data from the raw data stored for each auto moderation rule trigger metadata
255
+ */
256
+ static DataTemplate = {};
257
+ /**
258
+ * @param data - The raw data received from the API for the auto moderation rule trigger metadata
259
+ */
260
+ constructor(data) {
261
+ super(data);
262
+ }
263
+ /**
264
+ * Substrings which will be searched for in content (Maximum of 1000)
265
+ *
266
+ * A keyword can be a phrase which contains multiple words.
267
+ *
268
+ * Wildcard symbols can be used to customize how each keyword will be matched. Each keyword must be 60 characters or less.
269
+ *
270
+ * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies | Keyword matching strategies}
271
+ *
272
+ * Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.MemberProfile}
273
+ */
274
+ get keywordFilter() {
275
+ return this[kData].keyword_filter;
276
+ }
277
+ /**
278
+ * Regular expression patterns which will be matched against content (Maximum of 10)
279
+ *
280
+ * Only Rust flavored regex is currently supported, which can be tested in online editors such as {@link https://rustexp.lpil.uk/ | Rustexp}.
281
+ *
282
+ * Each regex pattern must be 260 characters or less.
283
+ *
284
+ * Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.MemberProfile}
285
+ */
286
+ get regexPatterns() {
287
+ return this[kData].regex_patterns;
288
+ }
289
+ /**
290
+ * The internally pre-defined wordsets which will be searched for in content
291
+ *
292
+ * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types | Keyword preset types}
293
+ *
294
+ * Associated trigger types: {@link AutoModerationRuleTriggerType.KeywordPreset}
295
+ */
296
+ get presets() {
297
+ return this[kData].presets;
298
+ }
299
+ /**
300
+ * Substrings which should not trigger the rule (Maximum of 100 or 1000).
301
+ *
302
+ * Wildcard symbols can be used to customize how each keyword will be matched (see Keyword matching strategies).
303
+ *
304
+ * Each `allow_list` keyword can be a phrase which contains multiple words.
305
+ *
306
+ * Rules with `KEYWORD` triggerType accept a maximum of 100 keywords.
307
+ *
308
+ * Rules with `KEYWORD_PRESET` triggerType accept a maximum of 1000 keywords.
309
+ *
310
+ * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | triggerType}
311
+ * @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies | Keyword matching strategies}
312
+ *
313
+ * Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.KeywordPreset}, {@link AutoModerationRuleTriggerType.MemberProfile}
314
+ */
315
+ get allowList() {
316
+ return this[kData].allow_list;
317
+ }
318
+ /**
319
+ * Total number of unique role and user mentions allowed per message (Maximum of 50)
320
+ *
321
+ * Associated trigger types: {@link AutoModerationRuleTriggerType.MentionSpam}
322
+ */
323
+ get mentionTotalLimit() {
324
+ return this[kData].mention_total_limit;
325
+ }
326
+ /**
327
+ * Whether to automatically detect mention raids
328
+ *
329
+ * Associated trigger types: {@link AutoModerationRuleTriggerType.MentionSpam}
330
+ */
331
+ get mentionRaidProtectionEnabled() {
332
+ return this[kData].mention_raid_protection_enabled;
333
+ }
334
+ };
335
+
4
336
  // src/bitfields/BitField.ts
5
337
  var BitField = class _BitField {
6
338
  static {
@@ -271,24 +603,6 @@ var PermissionsBitField = class extends BitField {
271
603
  }
272
604
  };
273
605
 
274
- // src/utils/symbols.ts
275
- var kData = /* @__PURE__ */ Symbol.for("djs.structures.data");
276
- var kClone = /* @__PURE__ */ Symbol.for("djs.structures.clone");
277
- var kPatch = /* @__PURE__ */ Symbol.for("djs.structures.patch");
278
- var kExpiresTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.expiresTimestamp");
279
- var kEndedTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.endedTimestamp");
280
- var kCreatedTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.createdTimestamp");
281
- var kEditedTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.editedTimestamp");
282
- var kArchiveTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.archiveTimestamp");
283
- var kStartsTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.startsTimestamp");
284
- var kEndsTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.endsTimestamp");
285
- var kAllow = /* @__PURE__ */ Symbol.for("djs.structures.allow");
286
- var kDeny = /* @__PURE__ */ Symbol.for("djs.structures.deny");
287
- var kBurstColors = /* @__PURE__ */ Symbol.for("djs.structures.burstColors");
288
- var kLastPinTimestamp = /* @__PURE__ */ Symbol.for("djs.structures.lastPinTimestamp");
289
- var kMixinConstruct = /* @__PURE__ */ Symbol.for("djs.structures.mixin.construct");
290
- var kMixinToJSON = /* @__PURE__ */ Symbol.for("djs.structures.mixin.toJSON");
291
-
292
606
  // src/channels/mixins/AppliedTagsMixin.ts
293
607
  var AppliedTagsMixin = class {
294
608
  static {
@@ -645,105 +959,6 @@ var VoiceChannelMixin = class extends TextChannelMixin {
645
959
  }
646
960
  };
647
961
 
648
- // src/Structure.ts
649
- var DataTemplatePropertyName = "DataTemplate";
650
- var OptimizeDataPropertyName = "optimizeData";
651
- var Structure = class {
652
- static {
653
- __name(this, "Structure");
654
- }
655
- /**
656
- * The template used for removing data from the raw data stored for each Structure.
657
- *
658
- * @remarks This template should be overridden in all subclasses to provide more accurate type information.
659
- * The template in the base {@link Structure} class will have no effect on most subclasses for this reason.
660
- */
661
- static DataTemplate = {};
662
- /**
663
- * @returns A cloned version of the data template, ready to create a new data object.
664
- */
665
- getDataTemplate() {
666
- return Object.create(this.constructor.DataTemplate);
667
- }
668
- /**
669
- * The raw data from the API for this structure
670
- *
671
- * @internal
672
- */
673
- [kData];
674
- /**
675
- * Creates a new structure to represent API data
676
- *
677
- * @param data - the data from the API that this structure will represent
678
- * @remarks To be made public in subclasses
679
- * @internal
680
- */
681
- constructor(data, ..._rest) {
682
- this[kData] = Object.assign(this.getDataTemplate(), data);
683
- this[kMixinConstruct]?.(data);
684
- }
685
- /**
686
- * Patches the raw data of this object in place
687
- *
688
- * @param data - the updated data from the API to patch with
689
- * @remarks To be made public in subclasses
690
- * @returns this
691
- * @internal
692
- */
693
- [kPatch](data) {
694
- this[kData] = Object.assign(this.getDataTemplate(), this[kData], data);
695
- this.optimizeData(data);
696
- return this;
697
- }
698
- /**
699
- * Creates a clone of this structure
700
- *
701
- * @returns a clone of this
702
- * @internal
703
- */
704
- [kClone](patchPayload) {
705
- const clone = this.toJSON();
706
- return new this.constructor(
707
- // Ensure the ts-expect-error only applies to the constructor call
708
- patchPayload ? Object.assign(clone, patchPayload) : clone
709
- );
710
- }
711
- /**
712
- * Function called to ensure stored raw data is in optimized formats, used in tandem with a data template
713
- *
714
- * @example created_timestamp is an ISO string, this can be stored in optimized form as a number
715
- * @param _data - the raw data received from the API to optimize
716
- * @remarks Implementation to be done in subclasses and mixins where needed.
717
- * For typescript users, mixins must use the closest ancestors access modifier.
718
- * @remarks Automatically called in Structure[kPatch] but must be called manually in the constructor
719
- * of any class implementing this method.
720
- * @remarks Additionally, when implementing, ensure to call `super._optimizeData` if any class in the super chain aside
721
- * from Structure contains an implementation.
722
- * Note: mixins do not need to call super ever as the process of mixing walks the prototype chain.
723
- * @virtual
724
- * @internal
725
- */
726
- optimizeData(_data) {
727
- }
728
- /**
729
- * Transforms this object to its JSON format with raw API data (or close to it),
730
- * automatically called by `JSON.stringify()` when this structure is stringified
731
- *
732
- * @remarks
733
- * The type of this data is determined by omissions at runtime and is only guaranteed for default omissions
734
- * @privateRemarks
735
- * When omitting properties at the library level, this must be overridden to re-add those properties
736
- */
737
- toJSON() {
738
- const data = (
739
- // Spread is way faster than structuredClone, but is shallow. So use it only if there is no nested objects
740
- Object.values(this[kData]).some((value) => typeof value === "object" && value !== null) ? structuredClone(this[kData]) : { ...this[kData] }
741
- );
742
- this[kMixinToJSON]?.(data);
743
- return data;
744
- }
745
- };
746
-
747
962
  // src/channels/ForumTag.ts
748
963
  var ForumTag = class extends Structure {
749
964
  static {
@@ -4044,6 +4259,10 @@ export {
4044
4259
  AppliedTagsMixin,
4045
4260
  Attachment,
4046
4261
  AttachmentFlagsBitField,
4262
+ AutoModerationAction,
4263
+ AutoModerationActionMetadata,
4264
+ AutoModerationRule,
4265
+ AutoModerationRuleTriggerMetadata,
4047
4266
  AvatarDecorationData,
4048
4267
  BitField,
4049
4268
  ButtonComponent,