예제 #1
0
 async def info(self, ctx):
     DATA = utils.from_json(utils.DATA_PATH)
     if ctx.author.is_on_mobile():
         header, text = utils.string_formatting(DATA)
         embed = discord.Embed(description=header + "\n\n" + text,
                               color=utils.COLOR,
                               timestamp=utils.discord_timestamp())
     else:
         my_csv = utils.from_json(utils.CSV_DATA_PATH)
         embed = utils.make_tab_embed_all()
         c, r, d = utils.difference_on_update(my_csv, DATA)
         tot = DATA['total']
         header = utils.mkheader(
             tot["confirmed"], c, tot["recovered"],
             utils.percentage(tot["confirmed"], tot["recovered"]),
             r, tot["deaths"],
             utils.percentage(tot["confirmed"], tot["deaths"]), d, False)
         embed.description = header
     embed.set_author(
         name=f"All countries affected by Coronavirus COVID-19",
         url="https://www.who.int/home",
         icon_url=self.author_thumb)
     embed.set_thumbnail(url=self.thumb)
     embed.set_footer(text=utils.last_update(utils.DATA_PATH),
                      icon_url=ctx.guild.me.avatar_url)
     with open("stats.png", "rb") as p:
         img = discord.File(p, filename="stats.png")
     embed.set_image(url=f'attachment://stats.png')
     await ctx.send(file=img, embed=embed)
예제 #2
0
 async def stats(self, ctx):
     DATA = utils.from_json(utils.DATA_PATH)
     my_csv = utils.from_json(utils.CSV_DATA_PATH)
     t, r, c = utils.difference_on_update(my_csv, DATA)
     confirmed = DATA['total']['confirmed']
     recovered = DATA['total']['recovered']
     deaths = DATA['total']['deaths']
     embed = discord.Embed(
         description="[+**CURRENT_UPDATE-MORNING_UPDATE**]",
         timestamp=utils.discord_timestamp(),
         color=utils.COLOR,
     )
     embed.set_author(name="Coronavirus COVID-19 Stats",
                      icon_url=self.author_thumb)
     embed.set_thumbnail(url=self.thumb)
     embed.add_field(name="<:confirmed:688686089548202004> Confirmed",
                     value=f"**{confirmed}** [+**{t}**]",
                     inline=False)
     embed.add_field(
         name="<:recov:688686059567185940> Recovered",
         value=
         f"**{recovered}** ({utils.percentage(confirmed, recovered)}) [+**{r}**]",
         inline=False)
     embed.add_field(
         name="<:_death:688686194917244928> Deaths",
         value=
         f"**{deaths}** ({utils.percentage(confirmed, deaths)}) [+**{c}**]",
         inline=False)
     embed.set_footer(text=utils.last_update("stats.png"),
                      icon_url=ctx.guild.me.avatar_url)
     with open("stats.png", "rb") as p:
         img = discord.File(p, filename="stats.png")
     embed.set_image(url=f'attachment://stats.png')
     await ctx.send(file=img, embed=embed)
예제 #3
0
    async def send_tracker(self):
        tracked = db.send_tracker()
        DATA = utils.from_json(utils.DATA_PATH)
        tot = DATA['total']
        my_csv = utils.from_json(utils.CSV_DATA_PATH)
        c, r, d = utils.difference_on_update(my_csv, DATA)
        header = utils.mkheader(
            tot["confirmed"], c, tot["recovered"],
            utils.percentage(tot["confirmed"],
                             tot["recovered"]), r, tot["deaths"],
            utils.percentage(tot["confirmed"], tot["deaths"]), d, False)
        for t in tracked:
            try:
                dm = self.bot.get_user(int(t["user_id"]))
                # embed = utils.make_tab_embed_all(is_country=True, params=t["country"].split(" "))
                header, text = utils.string_formatting(DATA,
                                                       t["country"].split(" "))
                embed = discord.Embed(description=header + "\n\n" + text,
                                      color=utils.COLOR,
                                      timestamp=utils.discord_timestamp())
                embed.set_author(
                    name="Personal tracker for Coronavirus COVID-19",
                    url="https://www.who.int/home",
                    icon_url=self.author_thumb)

                embed.set_thumbnail(url=self.thumb)
                try:
                    guild = self.bot.get_guild(int(t["guild_id"]))
                    embed.set_footer(text=utils.last_update(utils.DATA_PATH),
                                     icon_url=guild.me.avatar_url)
                except:
                    pass
                await dm.send(embed=embed)
            except:
                pass
예제 #4
0
 async def send_notifications(self, channels_id, old_data, new_data):
     # __, text = utils.string_formatting(new_data)
     confirmed = new_data['total']['confirmed']
     recovered = new_data['total']['recovered']
     deaths = new_data['total']['deaths']
     t, r, c = utils.difference_on_update(old_data, new_data)
     # header = f"""Total Confirmed **{tot['confirmed']}** [+{c}]
     # Total Recovered **{tot['recovered']}** ({utils.percentage(tot['confirmed'], tot['recovered'])}) [+{r}]
     # Total Deaths **{tot['deaths']}** ({utils.percentage(tot['confirmed'], tot['deaths'])}) [+{d}]\n"""
     embed = discord.Embed(
         # description=header + "\n" + text,
         description=
         "Below you can find the new stats for the past hour. (Data are updated ~ every 1 hour)",
         color=utils.COLOR,
         timestamp=utils.discord_timestamp())
     embed.set_author(name="Notification Coronavirus COVID-19",
                      url="https://www.who.int/home",
                      icon_url=self.author_thumb)
     embed.set_thumbnail(url=self.thumb)
     embed.add_field(name="Confirmed",
                     value=f"**{confirmed}** [+**{t}**]",
                     inline=False)
     embed.add_field(
         name="Recovered",
         value=
         f"**{recovered}** ({utils.percentage(confirmed, recovered)}) [+**{r}**]",
         inline=False)
     embed.add_field(
         name="Deaths",
         value=
         f"**{deaths}** ({utils.percentage(confirmed, deaths)}) [+**{c}**]",
         inline=False)
     for _ in channels_id:
         try:
             with open("stats.png", "rb") as p:
                 img = discord.File(p, filename="stats.png")
             embed.set_image(url=f'attachment://stats.png')
             channel = self.bot.get_channel(int(_["channel_id"]))
             try:
                 guild = self.bot.get_guild(int(_["guild_id"]))
                 embed.set_footer(text=utils.last_update(utils.DATA_PATH),
                                  icon_url=guild.me.avatar_url)
             except:
                 pass
             await channel.send(file=img, embed=embed)
         except Exception as e:
             pass
     logger.info("Notifications sended")
예제 #5
0
 async def send_notifications(self, old_data, new_data):
     confirmed = new_data['total']['confirmed']
     recovered = new_data['total']['recovered']
     deaths = new_data['total']['deaths']
     channels_id = db.to_send()
     t, r, c = utils.difference_on_update(old_data, new_data)
     embed = discord.Embed(
         description=
         "Below you can find the new stats for the past hour. (Data are updated ~ every 1 hour)\n[+**CURRENT_UPDATE-LAST_HOUR_UPDATE**]",
         color=utils.COLOR,
         timestamp=utils.discord_timestamp())
     embed.set_author(name="Notification Coronavirus COVID-19",
                      url="https://www.who.int/home",
                      icon_url=self.author_thumb)
     embed.set_thumbnail(url=self.thumb)
     embed.add_field(name="<:confirmed:688686089548202004> Confirmed",
                     value=f"**{confirmed}** [+**{t}**]",
                     inline=False)
     embed.add_field(
         name="<:recov:688686059567185940> Recovered",
         value=
         f"**{recovered}** ({utils.percentage(confirmed, recovered)}) [+**{r}**]",
         inline=False)
     embed.add_field(
         name="<:_death:688686194917244928> Deaths",
         value=
         f"**{deaths}** ({utils.percentage(confirmed, deaths)}) [+**{c}**]",
         inline=False)
     if t or c or r:
         for _ in channels_id:
             try:
                 with open("stats.png", "rb") as p:
                     img = discord.File(p, filename="stats.png")
                 embed.set_image(url=f'attachment://stats.png')
                 channel = self.bot.get_channel(int(_["channel_id"]))
                 try:
                     guild = self.bot.get_guild(int(_["guild_id"]))
                     embed.set_footer(text=utils.last_update(
                         utils.DATA_PATH),
                                      icon_url=guild.me.avatar_url)
                 except:
                     pass
                 await channel.send(file=img, embed=embed)
             except Exception as e:
                 pass
     logger.info("Notifications sended")
예제 #6
0
 async def country(self, ctx, *country):
     if not len(country):
         embed = discord.Embed(
             description=
             "No args provided, I can't tell you which country/region is affected if you won't tell me everything!",
             color=utils.COLOR,
             timestamp=utils.discord_timestamp())
     else:
         DATA = utils.from_json(utils.DATA_PATH)
         is_mobile = ctx.author.is_on_mobile()
         if is_mobile:
             header, text = utils.string_formatting(DATA, country)
             embed = discord.Embed(description=header + "\n\n" + text,
                                   color=utils.COLOR,
                                   timestamp=utils.discord_timestamp())
         else:
             try:
                 embed = utils.make_tab_embed_all(is_country=True,
                                                  params=country)
                 c, r, d = utils.difference_on_update(
                     utils.from_json(utils.CSV_DATA_PATH), DATA)
                 tot = DATA['total']
                 header = utils.mkheader(
                     tot["confirmed"], c, tot["recovered"],
                     utils.percentage(tot["confirmed"],
                                      tot["recovered"]), r, tot["deaths"],
                     utils.percentage(tot["confirmed"], tot["deaths"]), d,
                     is_mobile)
                 embed.description = header
             except:
                 embed = discord.Embed(
                     description=
                     "Wrong country selected.\nViews information about multiple chosen country/region. You can either use autocompletion or country code. Valid country/region are listed in `c!info`.\nExample : `c!country fr germ it poland`",
                     color=utils.COLOR,
                     timestamp=utils.discord_timestamp())
     embed.set_author(name="Country affected by COVID-19",
                      url="https://www.who.int/home",
                      icon_url=self.author_thumb)
     embed.set_thumbnail(url=self.thumb)
     embed.set_footer(text=utils.last_update(utils.DATA_PATH),
                      icon_url=ctx.guild.me.avatar_url)
     await ctx.send(embed=embed)
예제 #7
0
    async def track(self, ctx, *country):
        if not len(country):
            embed = discord.Embed(
                description=
                "No country provided. **`c!track <COUNTRY>`** work like **`c!country <COUNTRY>`** see `c!help`",
                color=utils.COLOR,
                timestamp=utils.discord_timestamp())
            embed.set_author(name="c!track", icon_url=self.author_thumb)
        elif ''.join(country) == "disable":
            embed = discord.Embed(
                description=
                "If you want to reactivate the tracker : **`c!track <COUNTRY>`**",
                color=utils.COLOR,
                timestamp=utils.discord_timestamp())
            embed.set_author(name="Tracker has been disabled!",
                             icon_url=self.author_thumb)
            try:
                db.delete_tracker(str(ctx.author.id))
            except:
                pass
        else:
            DATA = utils.from_json(utils.DATA_PATH)
            if ctx.author.is_on_mobile():
                header, text = utils.string_formatting(DATA, country)
                embed = discord.Embed(description=header + "\n\n" + text,
                                      color=utils.COLOR,
                                      timestamp=utils.discord_timestamp())
                if len(embed.description) > 0:
                    try:
                        db.insert_tracker(str(ctx.author.id),
                                          str(ctx.guild.id), ' '.join(country))
                    except IntegrityError:
                        db.update_tracker(str(ctx.author.id),
                                          ' '.join(country))

                    embed.set_author(
                        name=
                        "Tracker has been set up! You can see your tracked list. Updates will be send in DM",
                        icon_url=self.author_thumb)
                else:
                    embed = discord.Embed(
                        description="Wrong country selected.",
                        color=utils.COLOR,
                        timestamp=utils.discord_timestamp())
                    embed.set_author(name="c!track",
                                     icon_url=self.author_thumb)
            else:
                embed = utils.make_tab_embed_all(is_country=True,
                                                 params=country)
                my_csv = utils.from_json(utils.CSV_DATA_PATH)
                c, r, d = utils.difference_on_update(my_csv, DATA)
                tot = DATA['total']
                header = utils.mkheader(
                    tot["confirmed"], c, tot["recovered"],
                    utils.percentage(tot["confirmed"],
                                     tot["recovered"]), r, tot["deaths"],
                    utils.percentage(tot["confirmed"], tot["deaths"]), d,
                    False)
                embed.description = header
                if len(embed.fields[0].value) > 0:
                    try:
                        db.insert_tracker(str(ctx.author.id),
                                          str(ctx.guild.id), ' '.join(country))
                    except IntegrityError:
                        db.update_tracker(str(ctx.author.id),
                                          ' '.join(country))

                    embed.set_author(
                        name=
                        "Tracker has been set up! You can see your tracked list. Updates will be send in DM",
                        icon_url=self.author_thumb)
                else:
                    embed = discord.Embed(
                        description="Wrong country selected.",
                        color=utils.COLOR,
                        timestamp=utils.discord_timestamp())
                    embed.set_author(name="c!track",
                                     icon_url=self.author_thumb)
        embed.set_thumbnail(url=self.thumb)
        embed.set_footer(text=utils.last_update(utils.DATA_PATH),
                         icon_url=ctx.guild.me.avatar_url)
        await ctx.send(embed=embed)