refactore Keyboard class

This commit is contained in:
mamal72 2015-06-28 21:07:05 +04:30
parent 4485c17d3b
commit 099bda35cb

View File

@ -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;
}
}