Refactor classes and utils #3
@ -1,61 +1,45 @@
|
||||
export default class Keyboard {
|
||||
constructor(message, options = {}) {
|
||||
this.message = message;
|
||||
this.replyMarkup = options;
|
||||
constructor(options = {keyboard: [], resize_keyboard: false, one_time_keyboard: false, selective: false}) {
|
||||
this.properties = options;
|
||||
}
|
||||
|
||||
keys(keys) {
|
||||
this.setProperties({
|
||||
keyboard: keys,
|
||||
hide_keyboard: false
|
||||
});
|
||||
return this;
|
||||
set keyboard(value) {
|
||||
this.setProperties({keyboard: value});
|
||||
}
|
||||
|
||||
force(enable = true) {
|
||||
this.setProperties({
|
||||
force_keyboard: enable
|
||||
});
|
||||
return this;
|
||||
set resizeKeyboard(value) {
|
||||
this.setProperties({resize_keyboard: value});
|
||||
}
|
||||
|
||||
resize(enable = true) {
|
||||
this.setProperties({
|
||||
resize: enable
|
||||
});
|
||||
return this;
|
||||
set oneTimeKeyboard(value) {
|
||||
this.setProperties({one_time_keyboard: value});
|
||||
}
|
||||
|
||||
oneTime(enable = true) {
|
||||
this.setProperties({
|
||||
one_time_keyboard: enable
|
||||
});
|
||||
return this;
|
||||
set selective(value) {
|
||||
this.setProperties({selective: value});
|
||||
}
|
||||
|
||||
selective(enable = true) {
|
||||
this.setProperties({
|
||||
selective: enable
|
||||
});
|
||||
return this;
|
||||
get keyboard() {
|
||||
return this.getProperties('keyboard');
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.replyMarkup = {
|
||||
hide_keyboard: true
|
||||
};
|
||||
|
||||
return this;
|
||||
get resizeKeyboard() {
|
||||
this.getProperties('resize_keyboard');
|
||||
}
|
||||
|
||||
get replyMarkup() {
|
||||
return JSON.parse(this.message.params.reply_markup);
|
||||
get oneTimeKeyboard() {
|
||||
this.getProperties('one_time_keyboard');
|
||||
}
|
||||
set replyMarkup(json) {
|
||||
this.message.params.reply_markup = JSON.stringify(json);
|
||||
|
||||
get selective() {
|
||||
this.getProperties('selective');
|
||||
}
|
||||
|
||||
setProperties(object) {
|
||||
this.replyMarkup = Object.assign(this.replyMarkup, object);
|
||||
this.properties = Object.assign(this.properties, object);
|
||||
}
|
||||
|
||||
getProperties(object) {
|
||||
return object ? this.properties[object] : this.properties;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user