@discordjs/builders 2.0.0-dev.1740679933-8a37b7b93 → 2.0.0-dev.1740744295-88bfeaab2

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.js CHANGED
@@ -57,6 +57,11 @@ __export(index_exports, {
57
57
  MentionableSelectMenuBuilder: () => MentionableSelectMenuBuilder,
58
58
  MessageContextCommandBuilder: () => MessageContextCommandBuilder,
59
59
  ModalBuilder: () => ModalBuilder,
60
+ PollAnswerBuilder: () => PollAnswerBuilder,
61
+ PollAnswerMediaBuilder: () => PollAnswerMediaBuilder,
62
+ PollBuilder: () => PollBuilder,
63
+ PollMediaBuilder: () => PollMediaBuilder,
64
+ PollQuestionBuilder: () => PollQuestionBuilder,
60
65
  PremiumButtonBuilder: () => PremiumButtonBuilder,
61
66
  PrimaryButtonBuilder: () => PrimaryButtonBuilder,
62
67
  RoleSelectMenuBuilder: () => RoleSelectMenuBuilder,
@@ -96,7 +101,12 @@ __export(index_exports, {
96
101
  modalPredicate: () => modalPredicate,
97
102
  normalizeArray: () => normalizeArray,
98
103
  numberOptionPredicate: () => numberOptionPredicate,
104
+ pollAnswerMediaPredicate: () => pollAnswerMediaPredicate,
105
+ pollAnswerPredicate: () => pollAnswerPredicate,
106
+ pollPredicate: () => pollPredicate,
107
+ pollQuestionPredicate: () => pollQuestionPredicate,
99
108
  refineURLPredicate: () => refineURLPredicate,
109
+ resolveBuilder: () => resolveBuilder,
100
110
  selectMenuChannelPredicate: () => selectMenuChannelPredicate,
101
111
  selectMenuMentionablePredicate: () => selectMenuMentionablePredicate,
102
112
  selectMenuRolePredicate: () => selectMenuRolePredicate,
@@ -3070,8 +3080,327 @@ var EmbedBuilder = class {
3070
3080
  }
3071
3081
  };
3072
3082
 
3083
+ // src/messages/poll/Assertions.ts
3084
+ var import_v1032 = require("discord-api-types/v10");
3085
+ var import_zod8 = require("zod");
3086
+ var pollQuestionPredicate = import_zod8.z.object({ text: import_zod8.z.string().min(1).max(300) });
3087
+ var pollAnswerMediaPredicate = import_zod8.z.object({
3088
+ text: import_zod8.z.string().min(1).max(55),
3089
+ emoji: emojiPredicate.nullish()
3090
+ });
3091
+ var pollAnswerPredicate = import_zod8.z.object({ poll_media: pollAnswerMediaPredicate });
3092
+ var pollPredicate = import_zod8.z.object({
3093
+ question: pollQuestionPredicate,
3094
+ answers: import_zod8.z.array(pollAnswerPredicate).max(10),
3095
+ duration: import_zod8.z.number().min(1).max(768).optional(),
3096
+ allow_multiselect: import_zod8.z.boolean().optional(),
3097
+ layout_type: import_zod8.z.nativeEnum(import_v1032.PollLayoutType).optional()
3098
+ });
3099
+
3100
+ // src/messages/poll/PollMedia.ts
3101
+ var PollMediaBuilder = class {
3102
+ static {
3103
+ __name(this, "PollMediaBuilder");
3104
+ }
3105
+ data;
3106
+ /**
3107
+ * Creates new poll media from API data.
3108
+ *
3109
+ * @param data - The API data to use
3110
+ */
3111
+ constructor(data = {}) {
3112
+ this.data = structuredClone(data);
3113
+ }
3114
+ /**
3115
+ * Sets the text for this poll media.
3116
+ *
3117
+ * @param text - The text to use
3118
+ */
3119
+ setText(text) {
3120
+ this.data.text = text;
3121
+ return this;
3122
+ }
3123
+ };
3124
+
3125
+ // src/messages/poll/PollAnswerMedia.ts
3126
+ var PollAnswerMediaBuilder = class extends PollMediaBuilder {
3127
+ static {
3128
+ __name(this, "PollAnswerMediaBuilder");
3129
+ }
3130
+ /**
3131
+ * Sets the emoji for this poll answer.
3132
+ *
3133
+ * @param emoji - The emoji to use
3134
+ */
3135
+ setEmoji(emoji) {
3136
+ this.data.emoji = emoji;
3137
+ return this;
3138
+ }
3139
+ /**
3140
+ * Clears the emoji for this poll answer.
3141
+ */
3142
+ clearEmoji() {
3143
+ this.data.emoji = void 0;
3144
+ return this;
3145
+ }
3146
+ toJSON(validationOverride) {
3147
+ const clone = structuredClone(this.data);
3148
+ validate(pollAnswerMediaPredicate, clone, validationOverride);
3149
+ return clone;
3150
+ }
3151
+ };
3152
+
3153
+ // src/messages/poll/PollAnswer.ts
3154
+ var PollAnswerBuilder = class {
3155
+ static {
3156
+ __name(this, "PollAnswerBuilder");
3157
+ }
3158
+ data;
3159
+ constructor(data = {}) {
3160
+ this.data = {
3161
+ ...structuredClone(data),
3162
+ poll_media: new PollAnswerMediaBuilder(data.poll_media)
3163
+ };
3164
+ }
3165
+ /**
3166
+ * Sets the media for this poll answer.
3167
+ *
3168
+ * @param options - The data to use for this poll answer's media
3169
+ */
3170
+ setMedia(options) {
3171
+ this.data.poll_media = resolveBuilder(options, PollAnswerMediaBuilder);
3172
+ return this;
3173
+ }
3174
+ /**
3175
+ * Updates the media of this poll answer.
3176
+ *
3177
+ * @param updater - The function to update the media with
3178
+ */
3179
+ updateMedia(updater) {
3180
+ updater(this.data.poll_media ??= new PollAnswerMediaBuilder());
3181
+ }
3182
+ /**
3183
+ * Serializes this builder to API-compatible JSON data.
3184
+ *
3185
+ * Note that by disabling validation, there is no guarantee that the resulting object will be valid.
3186
+ *
3187
+ * @param validationOverride - Force validation to run/not run regardless of your global preference
3188
+ */
3189
+ toJSON(validationOverride) {
3190
+ const data = {
3191
+ ...structuredClone(this.data),
3192
+ // Disable validation because the pollAnswerPredicate below will validate this as well
3193
+ poll_media: this.data.poll_media?.toJSON(false)
3194
+ };
3195
+ validate(pollAnswerPredicate, data, validationOverride);
3196
+ return data;
3197
+ }
3198
+ };
3199
+
3200
+ // src/messages/poll/PollQuestion.ts
3201
+ var PollQuestionBuilder = class extends PollMediaBuilder {
3202
+ static {
3203
+ __name(this, "PollQuestionBuilder");
3204
+ }
3205
+ toJSON(validationOverride) {
3206
+ const clone = structuredClone(this.data);
3207
+ validate(pollQuestionPredicate, clone, validationOverride);
3208
+ return clone;
3209
+ }
3210
+ };
3211
+
3212
+ // src/messages/poll/Poll.ts
3213
+ var PollBuilder = class {
3214
+ static {
3215
+ __name(this, "PollBuilder");
3216
+ }
3217
+ /**
3218
+ * The API data associated with this poll.
3219
+ */
3220
+ data;
3221
+ /**
3222
+ * Gets the answers of this poll.
3223
+ */
3224
+ get answers() {
3225
+ return this.data.answers;
3226
+ }
3227
+ /**
3228
+ * Creates a new poll from API data.
3229
+ *
3230
+ * @param data - The API data to create this poll with
3231
+ */
3232
+ constructor(data = {}) {
3233
+ this.data = {
3234
+ ...structuredClone(data),
3235
+ question: new PollQuestionBuilder(data.question),
3236
+ answers: data.answers?.map((answer) => new PollAnswerBuilder(answer)) ?? []
3237
+ };
3238
+ }
3239
+ /**
3240
+ * Appends answers to the poll.
3241
+ *
3242
+ * @remarks
3243
+ * This method accepts either an array of answers or a variable number of answer parameters.
3244
+ * The maximum amount of answers that can be added is 10.
3245
+ * @example
3246
+ * Using an array:
3247
+ * ```ts
3248
+ * const answers: APIPollMedia[] = ...;
3249
+ * const poll = new PollBuilder()
3250
+ * .addAnswers(answers);
3251
+ * ```
3252
+ * @example
3253
+ * Using rest parameters (variadic):
3254
+ * ```ts
3255
+ * const poll = new PollBuilder()
3256
+ * .addAnswers(
3257
+ * { text: 'Answer 1' },
3258
+ * { text: 'Answer 2' },
3259
+ * );
3260
+ * ```
3261
+ * @param answers - The answers to add
3262
+ */
3263
+ addAnswers(...answers) {
3264
+ const normalizedAnswers = normalizeArray(answers);
3265
+ const resolved = normalizedAnswers.map((answer) => resolveBuilder(answer, PollAnswerBuilder));
3266
+ this.data.answers.push(...resolved);
3267
+ return this;
3268
+ }
3269
+ /**
3270
+ * Removes, replaces, or inserts answers for this poll.
3271
+ *
3272
+ * @remarks
3273
+ * This method behaves similarly
3274
+ * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
3275
+ * The maximum amount of answers that can be added is 10.
3276
+ *
3277
+ * It's useful for modifying and adjusting order of the already-existing answers of a poll.
3278
+ * @example
3279
+ * Remove the first answer:
3280
+ * ```ts
3281
+ * poll.spliceAnswers(0, 1);
3282
+ * ```
3283
+ * @example
3284
+ * Remove the first n answers:
3285
+ * ```ts
3286
+ * const n = 4;
3287
+ * poll.spliceAnswers(0, n);
3288
+ * ```
3289
+ * @example
3290
+ * Remove the last answer:
3291
+ * ```ts
3292
+ * poll.spliceAnswers(-1, 1);
3293
+ * ```
3294
+ * @param index - The index to start at
3295
+ * @param deleteCount - The number of answers to remove
3296
+ * @param answers - The replacing answer objects
3297
+ */
3298
+ spliceAnswers(index, deleteCount, ...answers) {
3299
+ const normalizedAnswers = normalizeArray(answers);
3300
+ const resolved = normalizedAnswers.map((answer) => resolveBuilder(answer, PollAnswerBuilder));
3301
+ this.data.answers.splice(index, deleteCount, ...resolved);
3302
+ return this;
3303
+ }
3304
+ /**
3305
+ * Sets the answers for this poll.
3306
+ *
3307
+ * @remarks
3308
+ * This method is an alias for {@link PollBuilder.spliceAnswers}. More specifically,
3309
+ * it splices the entire array of answers, replacing them with the provided answers.
3310
+ *
3311
+ * You can set a maximum of 10 answers.
3312
+ * @param answers - The answers to set
3313
+ */
3314
+ setAnswers(...answers) {
3315
+ return this.spliceAnswers(0, this.data.answers.length, ...normalizeArray(answers));
3316
+ }
3317
+ /**
3318
+ * Sets the question for this poll.
3319
+ *
3320
+ * @param options - The data to use for this poll's question
3321
+ */
3322
+ setQuestion(options) {
3323
+ this.data.question = resolveBuilder(options, PollQuestionBuilder);
3324
+ return this;
3325
+ }
3326
+ /**
3327
+ * Updates the question of this poll.
3328
+ *
3329
+ * @param updater - The function to update the question with
3330
+ */
3331
+ updateQuestion(updater) {
3332
+ updater(this.data.question ??= new PollQuestionBuilder());
3333
+ return this;
3334
+ }
3335
+ /**
3336
+ * Sets the layout type for this poll.
3337
+ *
3338
+ * @remarks
3339
+ * This method is redundant while only one type of poll layout exists (`PollLayoutType.Default`)
3340
+ * with Discord using that as the layout type if none is specified.
3341
+ * @param type - The type of poll layout to use
3342
+ */
3343
+ setLayoutType(type) {
3344
+ this.data.layout_type = type;
3345
+ return this;
3346
+ }
3347
+ /**
3348
+ * Clears the layout type for this poll.
3349
+ */
3350
+ clearLayoutType() {
3351
+ this.data.layout_type = void 0;
3352
+ return this;
3353
+ }
3354
+ /**
3355
+ * Sets whether multi-select is enabled for this poll.
3356
+ *
3357
+ * @param multiSelect - Whether to allow multi-select
3358
+ */
3359
+ setMultiSelect(multiSelect = true) {
3360
+ this.data.allow_multiselect = multiSelect;
3361
+ return this;
3362
+ }
3363
+ /**
3364
+ * Sets how long this poll will be open for in hours.
3365
+ *
3366
+ * @remarks
3367
+ * Minimum duration is `1`, with maximum duration being `768` (32 days).
3368
+ * Default if none specified is `24` (one day).
3369
+ * @param duration - The amount of hours this poll will be open for
3370
+ */
3371
+ setDuration(duration) {
3372
+ this.data.duration = duration;
3373
+ return this;
3374
+ }
3375
+ /**
3376
+ * Clears the duration for this poll.
3377
+ */
3378
+ clearDuration() {
3379
+ this.data.duration = void 0;
3380
+ return this;
3381
+ }
3382
+ /**
3383
+ * Serializes this builder to API-compatible JSON data.
3384
+ *
3385
+ * Note that by disabling validation, there is no guarantee that the resulting object will be valid.
3386
+ *
3387
+ * @param validationOverride - Force validation to run/not run regardless of your global preference
3388
+ */
3389
+ toJSON(validationOverride) {
3390
+ const { answers, question, ...rest } = this.data;
3391
+ const data = {
3392
+ ...structuredClone(rest),
3393
+ // Disable validation because the pollPredicate below will validate those as well
3394
+ answers: answers.map((answer) => answer.toJSON(false)),
3395
+ question: question.toJSON(false)
3396
+ };
3397
+ validate(pollPredicate, data, validationOverride);
3398
+ return data;
3399
+ }
3400
+ };
3401
+
3073
3402
  // src/index.ts
3074
- var version = "2.0.0-dev.1740679933-8a37b7b93";
3403
+ var version = "2.0.0-dev.1740744295-88bfeaab2";
3075
3404
  // Annotate the CommonJS export names for ESM import in node:
3076
3405
  0 && (module.exports = {
3077
3406
  ActionRowBuilder,
@@ -3110,6 +3439,11 @@ var version = "2.0.0-dev.1740679933-8a37b7b93";
3110
3439
  MentionableSelectMenuBuilder,
3111
3440
  MessageContextCommandBuilder,
3112
3441
  ModalBuilder,
3442
+ PollAnswerBuilder,
3443
+ PollAnswerMediaBuilder,
3444
+ PollBuilder,
3445
+ PollMediaBuilder,
3446
+ PollQuestionBuilder,
3113
3447
  PremiumButtonBuilder,
3114
3448
  PrimaryButtonBuilder,
3115
3449
  RoleSelectMenuBuilder,
@@ -3149,7 +3483,12 @@ var version = "2.0.0-dev.1740679933-8a37b7b93";
3149
3483
  modalPredicate,
3150
3484
  normalizeArray,
3151
3485
  numberOptionPredicate,
3486
+ pollAnswerMediaPredicate,
3487
+ pollAnswerPredicate,
3488
+ pollPredicate,
3489
+ pollQuestionPredicate,
3152
3490
  refineURLPredicate,
3491
+ resolveBuilder,
3153
3492
  selectMenuChannelPredicate,
3154
3493
  selectMenuMentionablePredicate,
3155
3494
  selectMenuRolePredicate,