seyfert
Version:
The most advanced framework for discord bots
48 lines (47 loc) • 1.49 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PollBuilder = void 0;
const common_1 = require("../common");
const types_1 = require("../types");
class PollBuilder {
data;
constructor(data = {}) {
this.data = data;
this.data.layout_type = types_1.PollLayoutType.Default;
}
addAnswers(...answers) {
this.data.answers = (this.data.answers ?? []).concat(answers.flat().map(x => ({ poll_media: this.resolvedPollMedia(x) })));
return this;
}
setAnswers(...answers) {
this.data.answers = answers.flat().map(x => ({ poll_media: this.resolvedPollMedia(x) }));
return this;
}
setQuestion(data) {
this.data.question ??= {};
const { emoji, text } = this.resolvedPollMedia(data);
this.data.question.text = text;
this.data.question.emoji = emoji;
return this;
}
setDuration(hours) {
this.data.duration = hours;
return this;
}
allowMultiselect(value = true) {
this.data.allow_multiselect = value;
return this;
}
toJSON() {
return { ...this.data };
}
resolvedPollMedia(data) {
if (!data.emoji)
return { text: data.text };
const resolve = (0, common_1.resolvePartialEmoji)(data.emoji);
if (!resolve)
throw new Error('Invalid Emoji');
return { text: data.text, emoji: resolve };
}
}
exports.PollBuilder = PollBuilder;