@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.mjs CHANGED
@@ -2979,8 +2979,327 @@ var EmbedBuilder = class {
2979
2979
  }
2980
2980
  };
2981
2981
 
2982
+ // src/messages/poll/Assertions.ts
2983
+ import { PollLayoutType } from "discord-api-types/v10";
2984
+ import { z as z8 } from "zod";
2985
+ var pollQuestionPredicate = z8.object({ text: z8.string().min(1).max(300) });
2986
+ var pollAnswerMediaPredicate = z8.object({
2987
+ text: z8.string().min(1).max(55),
2988
+ emoji: emojiPredicate.nullish()
2989
+ });
2990
+ var pollAnswerPredicate = z8.object({ poll_media: pollAnswerMediaPredicate });
2991
+ var pollPredicate = z8.object({
2992
+ question: pollQuestionPredicate,
2993
+ answers: z8.array(pollAnswerPredicate).max(10),
2994
+ duration: z8.number().min(1).max(768).optional(),
2995
+ allow_multiselect: z8.boolean().optional(),
2996
+ layout_type: z8.nativeEnum(PollLayoutType).optional()
2997
+ });
2998
+
2999
+ // src/messages/poll/PollMedia.ts
3000
+ var PollMediaBuilder = class {
3001
+ static {
3002
+ __name(this, "PollMediaBuilder");
3003
+ }
3004
+ data;
3005
+ /**
3006
+ * Creates new poll media from API data.
3007
+ *
3008
+ * @param data - The API data to use
3009
+ */
3010
+ constructor(data = {}) {
3011
+ this.data = structuredClone(data);
3012
+ }
3013
+ /**
3014
+ * Sets the text for this poll media.
3015
+ *
3016
+ * @param text - The text to use
3017
+ */
3018
+ setText(text) {
3019
+ this.data.text = text;
3020
+ return this;
3021
+ }
3022
+ };
3023
+
3024
+ // src/messages/poll/PollAnswerMedia.ts
3025
+ var PollAnswerMediaBuilder = class extends PollMediaBuilder {
3026
+ static {
3027
+ __name(this, "PollAnswerMediaBuilder");
3028
+ }
3029
+ /**
3030
+ * Sets the emoji for this poll answer.
3031
+ *
3032
+ * @param emoji - The emoji to use
3033
+ */
3034
+ setEmoji(emoji) {
3035
+ this.data.emoji = emoji;
3036
+ return this;
3037
+ }
3038
+ /**
3039
+ * Clears the emoji for this poll answer.
3040
+ */
3041
+ clearEmoji() {
3042
+ this.data.emoji = void 0;
3043
+ return this;
3044
+ }
3045
+ toJSON(validationOverride) {
3046
+ const clone = structuredClone(this.data);
3047
+ validate(pollAnswerMediaPredicate, clone, validationOverride);
3048
+ return clone;
3049
+ }
3050
+ };
3051
+
3052
+ // src/messages/poll/PollAnswer.ts
3053
+ var PollAnswerBuilder = class {
3054
+ static {
3055
+ __name(this, "PollAnswerBuilder");
3056
+ }
3057
+ data;
3058
+ constructor(data = {}) {
3059
+ this.data = {
3060
+ ...structuredClone(data),
3061
+ poll_media: new PollAnswerMediaBuilder(data.poll_media)
3062
+ };
3063
+ }
3064
+ /**
3065
+ * Sets the media for this poll answer.
3066
+ *
3067
+ * @param options - The data to use for this poll answer's media
3068
+ */
3069
+ setMedia(options) {
3070
+ this.data.poll_media = resolveBuilder(options, PollAnswerMediaBuilder);
3071
+ return this;
3072
+ }
3073
+ /**
3074
+ * Updates the media of this poll answer.
3075
+ *
3076
+ * @param updater - The function to update the media with
3077
+ */
3078
+ updateMedia(updater) {
3079
+ updater(this.data.poll_media ??= new PollAnswerMediaBuilder());
3080
+ }
3081
+ /**
3082
+ * Serializes this builder to API-compatible JSON data.
3083
+ *
3084
+ * Note that by disabling validation, there is no guarantee that the resulting object will be valid.
3085
+ *
3086
+ * @param validationOverride - Force validation to run/not run regardless of your global preference
3087
+ */
3088
+ toJSON(validationOverride) {
3089
+ const data = {
3090
+ ...structuredClone(this.data),
3091
+ // Disable validation because the pollAnswerPredicate below will validate this as well
3092
+ poll_media: this.data.poll_media?.toJSON(false)
3093
+ };
3094
+ validate(pollAnswerPredicate, data, validationOverride);
3095
+ return data;
3096
+ }
3097
+ };
3098
+
3099
+ // src/messages/poll/PollQuestion.ts
3100
+ var PollQuestionBuilder = class extends PollMediaBuilder {
3101
+ static {
3102
+ __name(this, "PollQuestionBuilder");
3103
+ }
3104
+ toJSON(validationOverride) {
3105
+ const clone = structuredClone(this.data);
3106
+ validate(pollQuestionPredicate, clone, validationOverride);
3107
+ return clone;
3108
+ }
3109
+ };
3110
+
3111
+ // src/messages/poll/Poll.ts
3112
+ var PollBuilder = class {
3113
+ static {
3114
+ __name(this, "PollBuilder");
3115
+ }
3116
+ /**
3117
+ * The API data associated with this poll.
3118
+ */
3119
+ data;
3120
+ /**
3121
+ * Gets the answers of this poll.
3122
+ */
3123
+ get answers() {
3124
+ return this.data.answers;
3125
+ }
3126
+ /**
3127
+ * Creates a new poll from API data.
3128
+ *
3129
+ * @param data - The API data to create this poll with
3130
+ */
3131
+ constructor(data = {}) {
3132
+ this.data = {
3133
+ ...structuredClone(data),
3134
+ question: new PollQuestionBuilder(data.question),
3135
+ answers: data.answers?.map((answer) => new PollAnswerBuilder(answer)) ?? []
3136
+ };
3137
+ }
3138
+ /**
3139
+ * Appends answers to the poll.
3140
+ *
3141
+ * @remarks
3142
+ * This method accepts either an array of answers or a variable number of answer parameters.
3143
+ * The maximum amount of answers that can be added is 10.
3144
+ * @example
3145
+ * Using an array:
3146
+ * ```ts
3147
+ * const answers: APIPollMedia[] = ...;
3148
+ * const poll = new PollBuilder()
3149
+ * .addAnswers(answers);
3150
+ * ```
3151
+ * @example
3152
+ * Using rest parameters (variadic):
3153
+ * ```ts
3154
+ * const poll = new PollBuilder()
3155
+ * .addAnswers(
3156
+ * { text: 'Answer 1' },
3157
+ * { text: 'Answer 2' },
3158
+ * );
3159
+ * ```
3160
+ * @param answers - The answers to add
3161
+ */
3162
+ addAnswers(...answers) {
3163
+ const normalizedAnswers = normalizeArray(answers);
3164
+ const resolved = normalizedAnswers.map((answer) => resolveBuilder(answer, PollAnswerBuilder));
3165
+ this.data.answers.push(...resolved);
3166
+ return this;
3167
+ }
3168
+ /**
3169
+ * Removes, replaces, or inserts answers for this poll.
3170
+ *
3171
+ * @remarks
3172
+ * This method behaves similarly
3173
+ * to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice | Array.prototype.splice()}.
3174
+ * The maximum amount of answers that can be added is 10.
3175
+ *
3176
+ * It's useful for modifying and adjusting order of the already-existing answers of a poll.
3177
+ * @example
3178
+ * Remove the first answer:
3179
+ * ```ts
3180
+ * poll.spliceAnswers(0, 1);
3181
+ * ```
3182
+ * @example
3183
+ * Remove the first n answers:
3184
+ * ```ts
3185
+ * const n = 4;
3186
+ * poll.spliceAnswers(0, n);
3187
+ * ```
3188
+ * @example
3189
+ * Remove the last answer:
3190
+ * ```ts
3191
+ * poll.spliceAnswers(-1, 1);
3192
+ * ```
3193
+ * @param index - The index to start at
3194
+ * @param deleteCount - The number of answers to remove
3195
+ * @param answers - The replacing answer objects
3196
+ */
3197
+ spliceAnswers(index, deleteCount, ...answers) {
3198
+ const normalizedAnswers = normalizeArray(answers);
3199
+ const resolved = normalizedAnswers.map((answer) => resolveBuilder(answer, PollAnswerBuilder));
3200
+ this.data.answers.splice(index, deleteCount, ...resolved);
3201
+ return this;
3202
+ }
3203
+ /**
3204
+ * Sets the answers for this poll.
3205
+ *
3206
+ * @remarks
3207
+ * This method is an alias for {@link PollBuilder.spliceAnswers}. More specifically,
3208
+ * it splices the entire array of answers, replacing them with the provided answers.
3209
+ *
3210
+ * You can set a maximum of 10 answers.
3211
+ * @param answers - The answers to set
3212
+ */
3213
+ setAnswers(...answers) {
3214
+ return this.spliceAnswers(0, this.data.answers.length, ...normalizeArray(answers));
3215
+ }
3216
+ /**
3217
+ * Sets the question for this poll.
3218
+ *
3219
+ * @param options - The data to use for this poll's question
3220
+ */
3221
+ setQuestion(options) {
3222
+ this.data.question = resolveBuilder(options, PollQuestionBuilder);
3223
+ return this;
3224
+ }
3225
+ /**
3226
+ * Updates the question of this poll.
3227
+ *
3228
+ * @param updater - The function to update the question with
3229
+ */
3230
+ updateQuestion(updater) {
3231
+ updater(this.data.question ??= new PollQuestionBuilder());
3232
+ return this;
3233
+ }
3234
+ /**
3235
+ * Sets the layout type for this poll.
3236
+ *
3237
+ * @remarks
3238
+ * This method is redundant while only one type of poll layout exists (`PollLayoutType.Default`)
3239
+ * with Discord using that as the layout type if none is specified.
3240
+ * @param type - The type of poll layout to use
3241
+ */
3242
+ setLayoutType(type) {
3243
+ this.data.layout_type = type;
3244
+ return this;
3245
+ }
3246
+ /**
3247
+ * Clears the layout type for this poll.
3248
+ */
3249
+ clearLayoutType() {
3250
+ this.data.layout_type = void 0;
3251
+ return this;
3252
+ }
3253
+ /**
3254
+ * Sets whether multi-select is enabled for this poll.
3255
+ *
3256
+ * @param multiSelect - Whether to allow multi-select
3257
+ */
3258
+ setMultiSelect(multiSelect = true) {
3259
+ this.data.allow_multiselect = multiSelect;
3260
+ return this;
3261
+ }
3262
+ /**
3263
+ * Sets how long this poll will be open for in hours.
3264
+ *
3265
+ * @remarks
3266
+ * Minimum duration is `1`, with maximum duration being `768` (32 days).
3267
+ * Default if none specified is `24` (one day).
3268
+ * @param duration - The amount of hours this poll will be open for
3269
+ */
3270
+ setDuration(duration) {
3271
+ this.data.duration = duration;
3272
+ return this;
3273
+ }
3274
+ /**
3275
+ * Clears the duration for this poll.
3276
+ */
3277
+ clearDuration() {
3278
+ this.data.duration = void 0;
3279
+ return this;
3280
+ }
3281
+ /**
3282
+ * Serializes this builder to API-compatible JSON data.
3283
+ *
3284
+ * Note that by disabling validation, there is no guarantee that the resulting object will be valid.
3285
+ *
3286
+ * @param validationOverride - Force validation to run/not run regardless of your global preference
3287
+ */
3288
+ toJSON(validationOverride) {
3289
+ const { answers, question, ...rest } = this.data;
3290
+ const data = {
3291
+ ...structuredClone(rest),
3292
+ // Disable validation because the pollPredicate below will validate those as well
3293
+ answers: answers.map((answer) => answer.toJSON(false)),
3294
+ question: question.toJSON(false)
3295
+ };
3296
+ validate(pollPredicate, data, validationOverride);
3297
+ return data;
3298
+ }
3299
+ };
3300
+
2982
3301
  // src/index.ts
2983
- var version = "2.0.0-dev.1740679933-8a37b7b93";
3302
+ var version = "2.0.0-dev.1740744295-88bfeaab2";
2984
3303
  export {
2985
3304
  ActionRowBuilder,
2986
3305
  ApplicationCommandNumericOptionMinMaxValueMixin,
@@ -3018,6 +3337,11 @@ export {
3018
3337
  MentionableSelectMenuBuilder,
3019
3338
  MessageContextCommandBuilder,
3020
3339
  ModalBuilder,
3340
+ PollAnswerBuilder,
3341
+ PollAnswerMediaBuilder,
3342
+ PollBuilder,
3343
+ PollMediaBuilder,
3344
+ PollQuestionBuilder,
3021
3345
  PremiumButtonBuilder,
3022
3346
  PrimaryButtonBuilder,
3023
3347
  RoleSelectMenuBuilder,
@@ -3057,7 +3381,12 @@ export {
3057
3381
  modalPredicate,
3058
3382
  normalizeArray,
3059
3383
  numberOptionPredicate,
3384
+ pollAnswerMediaPredicate,
3385
+ pollAnswerPredicate,
3386
+ pollPredicate,
3387
+ pollQuestionPredicate,
3060
3388
  refineURLPredicate,
3389
+ resolveBuilder,
3061
3390
  selectMenuChannelPredicate,
3062
3391
  selectMenuMentionablePredicate,
3063
3392
  selectMenuRolePredicate,