From fdc48d8b200a689c5f0a1ab793e0e19db2af0929 Mon Sep 17 00:00:00 2001 From: Nick80835 Date: Fri, 3 Apr 2020 12:04:34 -0400 Subject: [PATCH] improve corona command --- ubot/modules/corona.py | 27 +++++++++++++++++++++++++++ ubot/modules/evaluation.py | 7 ------- 2 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 ubot/modules/corona.py diff --git a/ubot/modules/corona.py b/ubot/modules/corona.py new file mode 100644 index 0000000..028ad22 --- /dev/null +++ b/ubot/modules/corona.py @@ -0,0 +1,27 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +from requests import get + +from ubot.micro_bot import micro_bot + +ldr = micro_bot.loader + + +@ldr.add(pattern="corona") +async def corona(event): + text_arg = event.pattern_match.group(1) + + if text_arg: + with get(f"https://corona.lmao.ninja/countries/{text_arg}") as response: + if response.status_code == 200: + response = response.json() + else: + await event.reply(f"`An error occurred, response code: `**{response.status}**") + return + + response_text = f"`Stats for `**{response['country']}**\n\n`Cases: `**{response['cases']}**\n`Deaths: `**{response['deaths']}**\n`Recoveries: `**{response['recovered']}**" + await event.reply(response_text) + else: + corona_data = get("https://corona.lmao.ninja/all").json() + response_text = f"`Global stats`\n\n`Cases: `**{corona_data['cases']}**\n`Deaths: `**{corona_data['deaths']}**\n`Recoveries: `**{corona_data['recovered']}**" + await event.reply(response_text) diff --git a/ubot/modules/evaluation.py b/ubot/modules/evaluation.py index a6dc81b..69b640c 100644 --- a/ubot/modules/evaluation.py +++ b/ubot/modules/evaluation.py @@ -11,13 +11,6 @@ from ubot.micro_bot import micro_bot ldr = micro_bot.loader -@ldr.add(pattern="corona") -async def corona(event): - corona_data = get("https://corona.lmao.ninja/all").json() - response_text = f"`Cases: `**{corona_data['cases']}**\n`Deaths: `**{corona_data['deaths']}**\n`Recoveries: `**{corona_data['recovered']}**" - await event.reply(response_text) - - @ldr.add(pattern="chatid") async def chatidgetter(event): if event.is_reply: