telegram: Formatting typings

This commit is contained in:
Gonzalo Matheu 2021-04-15 09:31:20 -03:00
parent e3c5a4b3fc
commit 7a98de10ea

View File

@ -8,7 +8,7 @@ import logging
from datetime import timedelta from datetime import timedelta
from html import escape from html import escape
from itertools import chain from itertools import chain
from typing import Any, Callable, Dict, List, Union from typing import Any, Callable, Dict, List, Optional, Union, cast
import arrow import arrow
from tabulate import tabulate from tabulate import tabulate
@ -88,7 +88,7 @@ class Telegram(RPCHandler):
Validates the keyboard configuration from telegram config Validates the keyboard configuration from telegram config
section. section.
""" """
self._keyboard: List[List[Union[str, KeyboardButton]]] = [ self._keyboard: List[List[Union[str, KeyboardButton, InlineKeyboardButton]]] = [
['/daily', '/profit', '/balance'], ['/daily', '/profit', '/balance'],
['/status', '/status table', '/performance'], ['/status', '/status table', '/performance'],
['/count', '/start', '/stop', '/help'] ['/count', '/start', '/stop', '/help']
@ -170,7 +170,7 @@ class Telegram(RPCHandler):
[h.command for h in handles] [h.command for h in handles]
) )
self._current_callback_query_handler = None self._current_callback_query_handler: Optional[CallbackQueryHandler] = None
self._callback_query_handlers = { self._callback_query_handlers = {
'forcebuy': CallbackQueryHandler(self._forcebuy_inline) 'forcebuy': CallbackQueryHandler(self._forcebuy_inline)
} }
@ -623,11 +623,12 @@ class Telegram(RPCHandler):
self._send_msg(str(e)) self._send_msg(str(e))
def _forcebuy_inline(self, update: Update, _: CallbackContext) -> None: def _forcebuy_inline(self, update: Update, _: CallbackContext) -> None:
query = update.callback_query if update.callback_query:
pair = query.data query = update.callback_query
query.answer() pair = query.data
query.edit_message_text(text=f"Force Buying: {pair}") query.answer()
self._forcebuy_action(pair) query.edit_message_text(text=f"Force Buying: {pair}")
self._forcebuy_action(pair)
@staticmethod @staticmethod
def _layout_inline_keyboard(buttons: List[InlineKeyboardButton], def _layout_inline_keyboard(buttons: List[InlineKeyboardButton],
@ -983,12 +984,13 @@ class Telegram(RPCHandler):
self._current_callback_query_handler = self._callback_query_handlers[callback_query_handler] self._current_callback_query_handler = self._callback_query_handlers[callback_query_handler]
self._updater.dispatcher.add_handler(self._current_callback_query_handler) self._updater.dispatcher.add_handler(self._current_callback_query_handler)
self._send_msg(msg, parse_mode, disable_notification, keyboard, self._send_msg(msg, parse_mode, disable_notification,
cast(List[List[Union[str, KeyboardButton, InlineKeyboardButton]]], keyboard),
reply_markup=InlineKeyboardMarkup) reply_markup=InlineKeyboardMarkup)
def _send_msg(self, msg: str, parse_mode: str = ParseMode.MARKDOWN, def _send_msg(self, msg: str, parse_mode: str = ParseMode.MARKDOWN,
disable_notification: bool = False, disable_notification: bool = False,
keyboard: List[List[Union[str, KeyboardButton]]] = None, keyboard: List[List[Union[str, KeyboardButton, InlineKeyboardButton]]] = None,
reply_markup=ReplyKeyboardMarkup) -> None: reply_markup=ReplyKeyboardMarkup) -> None:
""" """
Send given markdown message Send given markdown message