From aec7b7043acb0bf62a1b5624b20816b0bd9b2c34 Mon Sep 17 00:00:00 2001 From: flifloo Date: Fri, 27 Dec 2019 13:53:14 +0100 Subject: [PATCH] Error when kfet is down --- Languages/en.json | 1 + TelegramEDT/kfet.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Languages/en.json b/Languages/en.json index e6337bc..6dabd69 100644 --- a/Languages/en.json +++ b/Languages/en.json @@ -9,6 +9,7 @@ "setedt_wait": "Send a QR code, resource number or the url of the calendar !", "notif_event": "\uD83D\uDD14An event is coming !\n", "kfet": "\uD83D\uDD14Your command is ready !", + "kfet_error": "Cant connect to server !", "kfet_prb": "\u26A0Your command got a problem, go check whats happening", "kfet_err": "\u274CYour order is not out", "kfet_list": "\uD83D\uDDD2Kfet commands ready:\n", diff --git a/TelegramEDT/kfet.py b/TelegramEDT/kfet.py index 69727de..bf58089 100644 --- a/TelegramEDT/kfet.py +++ b/TelegramEDT/kfet.py @@ -32,10 +32,14 @@ async def kfet(message: types.Message): msg = lang(user, "kfet_close") else: msg = lang(user, "kfet_list") - cmds = requests.get(KFET_URL).json() - if cmds: - for c in cmds: - msg += markdown.code(c) + " " if cmds[c] == "ok" else "" + try: + cmds = requests.get(KFET_URL).json() + except (requests.exceptions.ConnectionError, requests.exceptions.ConnectTimeout): + msg = markdown.bold(lang(user, "kfet_error")) + else: + if cmds: + for c in cmds: + msg += markdown.code(c) + " " if cmds[c] == "ok" else "" await message.reply(msg, parse_mode=ParseMode.MARKDOWN, reply_markup=key)