seyfert
Version:
The most advanced framework for discord bots
38 lines (37 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Poll = void 0;
const common_1 = require("../common");
const Base_1 = require("./extra/Base");
class Poll extends Base_1.Base {
channelId;
messageId;
constructor(client, data, channelId, messageId) {
super(client);
this.channelId = channelId;
this.messageId = messageId;
Object.assign(this, (0, common_1.toCamelCase)(data));
}
get expiryTimestamp() {
return Date.parse(this.expiry);
}
get expiryAt() {
return new Date(this.expiry);
}
end() {
return this.client.messages.endPoll(this.channelId, this.messageId);
}
/**
* @param id - The ID of the answer whose voters need to be fetched.
* @param checkAnswer - A flag that determines if the answer ID should be validated before fetching voters.
* Default is `false`. If `true`, the method checks if the answer ID exists in the list
* of answers and throws an error if not.
*/
async getAnswerVoters(id, checkAnswer = false) {
if (checkAnswer && !this.answers.find(answer => answer.answerId === id)) {
throw new common_1.SeyfertError('INVALID_ANSWER_ID', { metadata: { detail: 'Invalid answer id' } });
}
return this.client.messages.getAnswerVoters(this.channelId, this.messageId, id);
}
}
exports.Poll = Poll;