Refactor classes and utils #3
@ -1,61 +1,45 @@
|
|||||||
export default class Keyboard {
|
export default class Keyboard {
|
||||||
constructor(message, options = {}) {
|
constructor(options = {keyboard: [], resize_keyboard: false, one_time_keyboard: false, selective: false}) {
|
||||||
this.message = message;
|
this.properties = options;
|
||||||
this.replyMarkup = options;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
keys(keys) {
|
set keyboard(value) {
|
||||||
this.setProperties({
|
this.setProperties({keyboard: value});
|
||||||
keyboard: keys,
|
|
||||||
hide_keyboard: false
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
force(enable = true) {
|
set resizeKeyboard(value) {
|
||||||
this.setProperties({
|
this.setProperties({resize_keyboard: value});
|
||||||
force_keyboard: enable
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resize(enable = true) {
|
set oneTimeKeyboard(value) {
|
||||||
this.setProperties({
|
this.setProperties({one_time_keyboard: value});
|
||||||
resize: enable
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oneTime(enable = true) {
|
set selective(value) {
|
||||||
this.setProperties({
|
this.setProperties({selective: value});
|
||||||
one_time_keyboard: enable
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selective(enable = true) {
|
get keyboard() {
|
||||||
this.setProperties({
|
return this.getProperties('keyboard');
|
||||||
selective: enable
|
|
||||||
});
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hide() {
|
get resizeKeyboard() {
|
||||||
this.replyMarkup = {
|
this.getProperties('resize_keyboard');
|
||||||
hide_keyboard: true
|
|
||||||
};
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get replyMarkup() {
|
get oneTimeKeyboard() {
|
||||||
return JSON.parse(this.message.params.reply_markup);
|
this.getProperties('one_time_keyboard');
|
||||||
}
|
}
|
||||||
set replyMarkup(json) {
|
|
||||||
this.message.params.reply_markup = JSON.stringify(json);
|
get selective() {
|
||||||
|
this.getProperties('selective');
|
||||||
}
|
}
|
||||||
|
|
||||||
setProperties(object) {
|
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