renaming shortcut_btns to keyboard

This commit is contained in:
Christof 2020-12-20 16:50:42 +01:00
parent bf92099486
commit 621105df9a
3 changed files with 14 additions and 14 deletions

View File

@ -87,7 +87,7 @@ Example configuration showing the different settings:
},
```
## Create a custom keyboard (command shortcuts buttons)
## Create a custom keyboard (command shortcut buttons)
Telegram allows us to create a custom keyboard with buttons for commands.
The default custom keyboard looks like this.
```python
@ -104,7 +104,7 @@ You can create your own keyboard in `config.json`:
"enabled": true,
"token": "your_telegram_token",
"chat_id": "your_telegram_chat_id",
"shortcut_btns": [
"keyboard": [
["/daily", "/stats", "/balance", "/profit"],
["/status table", "/performance"],
["/reload_config", "/count", "/logs"]

View File

@ -882,17 +882,17 @@ class Telegram(RPC):
'/logs', '/whitelist', '/blacklist', '/edge',
'/help', '/version']
# custom shortcuts specified in config.json
shortcut_btns = self._config['telegram'].get('shortcut_btns', [])
if shortcut_btns:
cust_keyboard = self._config['telegram'].get('keyboard', [])
if cust_keyboard:
# check for valid shortcuts
invalid_shortcut_btns = [b for b in chain.from_iterable(shortcut_btns)
invalid_keys = [b for b in chain.from_iterable(cust_keyboard)
if b not in valid_btns]
if len(invalid_shortcut_btns):
if len(invalid_keys):
logger.warning('rpc.telegram: invalid commands for custom '
f'keyboard: {invalid_shortcut_btns}')
f'keyboard: {invalid_keys}')
logger.info('rpc.telegram: using default keyboard.')
else:
keyboard = shortcut_btns
keyboard = cust_keyboard
logger.info('rpc.telegram using custom keyboard from '
f'config.json: {[btn for btn in keyboard]}')

View File

@ -1750,15 +1750,15 @@ def test__send_msg_keyboard(default_conf, mocker, caplog) -> None:
['/count', '/start', '/reload_config', '/help']]
custom_keyboard = ReplyKeyboardMarkup(custom_keys_list)
# no shortcut_btns in config -> default keyboard
# no keyboard in config -> default keyboard
telegram._config['telegram']['enabled'] = True
telegram._send_msg('test')
used_keyboard = bot.send_message.call_args.kwargs['reply_markup']
assert used_keyboard == default_keyboard
# invalid shortcut_btns in config -> default keyboard
# invalid keyboard in config -> default keyboard
telegram._config['telegram']['enabled'] = True
telegram._config['telegram']['shortcut_btns'] = invalid_keys_list
telegram._config['telegram']['keyboard'] = invalid_keys_list
telegram._send_msg('test')
used_keyboard = bot.send_message.call_args.kwargs['reply_markup']
assert used_keyboard == default_keyboard
@ -1766,9 +1766,9 @@ def test__send_msg_keyboard(default_conf, mocker, caplog) -> None:
"['/not_valid', '/alsoinvalid']", caplog)
assert log_has('rpc.telegram: using default keyboard.', caplog)
# valid shortcut_btns in config -> custom keyboard
# valid keyboard in config -> custom keyboard
telegram._config['telegram']['enabled'] = True
telegram._config['telegram']['shortcut_btns'] = custom_keys_list
telegram._config['telegram']['keyboard'] = custom_keys_list
telegram._send_msg('test')
used_keyboard = bot.send_message.call_args.kwargs['reply_markup']
assert used_keyboard == custom_keyboard