Update telegram.py

This commit is contained in:
Eko Aprili Trisno 2021-02-14 01:40:04 +07:00 committed by GitHub
parent 54d0ac9d20
commit ba32708ed4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,14 +5,14 @@ This module manage Telegram communication
""" """
import json import json
import logging import logging
from datetime import timedelta from datetime import timedelta, datetime
from itertools import chain from itertools import chain
from typing import Any, Callable, Dict, List, Union from typing import Any, Callable, Dict, List, Union
import arrow import arrow
from tabulate import tabulate from tabulate import tabulate
from telegram import KeyboardButton, ParseMode, ReplyKeyboardMarkup, Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram import KeyboardButton, ParseMode, ReplyKeyboardMarkup, Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.error import NetworkError, TelegramError, BadRequest from telegram.error import NetworkError, TelegramError
from telegram.ext import CallbackContext, CommandHandler, Updater, CallbackQueryHandler from telegram.ext import CallbackContext, CommandHandler, Updater, CallbackQueryHandler
from telegram.utils.helpers import escape_markdown from telegram.utils.helpers import escape_markdown
@ -154,7 +154,7 @@ class Telegram(RPCHandler):
CommandHandler('logs', self._logs), CommandHandler('logs', self._logs),
CommandHandler('edge', self._edge), CommandHandler('edge', self._edge),
CommandHandler('help', self._help), CommandHandler('help', self._help),
CommandHandler('version', self._version) CommandHandler('version', self._version),
] ]
callbacks = [ callbacks = [
CallbackQueryHandler(self._status_table, pattern='update_status_table'), CallbackQueryHandler(self._status_table, pattern='update_status_table'),
@ -945,6 +945,7 @@ class Telegram(RPCHandler):
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Refresh", callback_data=callback_path)]]) reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Refresh", callback_data=callback_path)]])
else: else:
reply_markup = InlineKeyboardMarkup([[]]) reply_markup = InlineKeyboardMarkup([[]])
msg+="\nUpdated: {}".format(datetime.now().ctime())
try: try:
try: try:
self._updater.bot.edit_message_text( self._updater.bot.edit_message_text(
@ -976,10 +977,10 @@ class Telegram(RPCHandler):
:param parse_mode: telegram parse mode :param parse_mode: telegram parse mode
:return: None :return: None
""" """
if reload_able: if reload_able and self._config['telegram'].get('reload',True):
reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Refresh", callback_data=callback_path)]]) reply_markup = InlineKeyboardMarkup([[InlineKeyboardButton("Refresh", callback_data=callback_path)]])
else: else:
reply_markup = ReplyKeyboardMarkup(self._keyboard) reply_markup = ReplyKeyboardMarkup(self._keyboard, resize_keyboard=True)
try: try:
try: try:
self._updater.bot.send_message( self._updater.bot.send_message(