@ayanaware/bentocord
Version:
Bentocord is a Bento plugin designed to rapidly build fully functional Discord Bots.
57 lines • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConfirmPrompt = void 0;
const Button_1 = require("../../components/helpers/Button");
const PaginationPrompt_1 = require("../PaginationPrompt");
class ConfirmPrompt extends PaginationPrompt_1.PaginationPrompt {
constructor(ctx, paginator) {
super(ctx, paginator);
this.validator = this.handleText.bind(this);
}
async start() {
// add buttons
this.btnYes = await new Button_1.Button(this.ctx, 'yes', this.yes.bind(this))
.success().labelTranslated('WORD_YES', null, 'Yes');
this.btnNo = await new Button_1.Button(this.ctx, 'no', this.no.bind(this))
.danger().labelTranslated('WORD_NO', null, 'No');
// Pagination.start() calls update
return super.start();
}
async close() {
await this.cleanup();
// confirm close needs to resolve with false
this.resolve(false);
}
async draw() {
this.clearRows();
// draw pagination
await super.draw();
// add yes/no
this.addRow([this.btnYes, this.btnNo]);
}
async yes(btn) {
if (btn)
await btn.deferUpdate();
await this.cleanup();
this.resolve(true);
}
async no(btn) {
if (btn)
await btn.deferUpdate();
await this.cleanup();
this.resolve(false);
}
async handleText(response) {
if (/^(true|t|yes|y|1)$/i.exec(response)) {
await this.cleanup();
return [true, true];
}
else if (/^(false|f|no|n|0)$/i.exec(response)) {
await this.cleanup();
return [true, false];
}
return super.handleText(response);
}
}
exports.ConfirmPrompt = ConfirmPrompt;
//# sourceMappingURL=ConfirmPrompt.js.map