async def info_command(bot, ctx: Union[commands.Context, SlashContext]): data = await utils.get(bot.http_session, "/all") text = utils.string_formatting(data) embed = discord.Embed(description=text, color=utils.COLOR, timestamp=utils.discord_timestamp()) embed.set_author(name=f"All countries affected by Coronavirus COVID-19", url="https://www.who.int/home", icon_url=bot.author_thumb) embed.set_thumbnail(url=bot.thumb + str(time.time())) embed.set_footer(text="coronavirus.jessicoh.com/api | " + utils.last_update(data[0]["lastUpdate"]), icon_url=bot.user.avatar_url) if not os.path.exists(utils.STATS_PATH): history_confirmed = await utils.get(bot.http_session, f"/history/confirmed/total") history_recovered = await utils.get(bot.http_session, f"/history/recovered/total") history_deaths = await utils.get(bot.http_session, f"/history/deaths/total") await plot_csv(utils.STATS_PATH, history_confirmed, history_recovered, history_deaths) with open(utils.STATS_PATH, "rb") as p: img = discord.File(p, filename=utils.STATS_PATH) embed.set_image(url=f'attachment://{utils.STATS_PATH}') await ctx.send(file=img, embed=embed)
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)
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) header, text = utils.string_formatting( DATA, country ) if len(text) > 0: embed = discord.Embed( description=header + "\n" + text, color=utils.COLOR, timestamp=utils.discord_timestamp() ) else: embed = discord.Embed( description="Wrong country selected or this country/region is not affected by Coronavirus COVID-19", color=utils.COLOR, timestamp=utils.discord_timestamp() ) embed.set_author(name="Current Region/Country 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 ) await ctx.send(embed=embed)
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
async def track(self, ctx, *country): if not len(country): embed = discord.Embed( description= f"No country provided. **`{ctx.prefix}track <COUNTRY>`** work like **`{ctx.prefix}country <COUNTRY>`** see `{ctx.prefix}help`", color=utils.COLOR, timestamp=utils.discord_timestamp()) embed.set_author(name=f"{ctx.prefix}track", icon_url=self.bot.author_thumb) elif ''.join(country) == "disable": embed = discord.Embed( description= f"If you want to reactivate the tracker : **`{ctx.prefix}track <COUNTRY>`**", color=utils.COLOR, timestamp=utils.discord_timestamp()) embed.set_author(name="Tracker has been disabled!", icon_url=self.bot.author_thumb) try: db.delete_tracker(str(ctx.author.id)) except: pass else: header, text = utils.string_formatting(self.bot._data, country) embed = discord.Embed(description=header + "\n\n" + text, color=utils.COLOR, timestamp=utils.discord_timestamp()) if len(text) > 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.bot.author_thumb) else: embed = discord.Embed(description="Wrong country selected.", color=utils.COLOR, timestamp=utils.discord_timestamp()) embed.set_author(name=f"{ctx.prefix}track", icon_url=self.bot.author_thumb) embed.set_thumbnail(url=self.bot.thumb + str(time.time())) embed.set_footer(text=utils.last_update(utils.DATA_PATH), icon_url=ctx.me.avatar_url) await ctx.send(embed=embed)
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)
async def info_error(self, ctx, error): DATA = utils.from_json(utils.DATA_PATH) header, text = utils.string_formatting(DATA) embed = discord.Embed( description=header + "\n" + text, color=utils.COLOR, timestamp=utils.discord_timestamp() ) embed.set_author(name="Country/Region affected by Coronavirus COVID-19 (Cases confirmed)", 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)
async def info(self, ctx): DATA = self.bot._data header, text = utils.string_formatting(DATA) embed = discord.Embed(description=header + "\n\n" + text, color=utils.COLOR, timestamp=utils.discord_timestamp()) embed.set_author( name=f"All countries affected by Coronavirus COVID-19", url="https://www.who.int/home", icon_url=self.bot.author_thumb) embed.set_thumbnail(url=self.thumb + str(uuid.uuid4())) embed.set_footer(text=utils.last_update(utils.DATA_PATH), icon_url=ctx.guild.me.avatar_url) with open(utils.STATS_PATH, "rb") as p: img = discord.File(p, filename=utils.STATS_PATH) embed.set_image(url=f'attachment://{utils.STATS_PATH}') await ctx.send(file=img, embed=embed)
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: header, text = utils.string_formatting(self.bot._data, country) embed = discord.Embed(description=header + "\n\n" + text, color=utils.COLOR, timestamp=utils.discord_timestamp()) if not len(text): embed = discord.Embed(description="Wrong country selected", 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.bot.author_thumb) embed.set_thumbnail(url=self.bot.thumb + str(time.time())) embed.set_footer(text=utils.last_update(utils.DATA_PATH), icon_url=ctx.me.avatar_url) await ctx.send(embed=embed)
async def send_tracker(self): embed = discord.Embed( description= "You can support me on [Kofi](https://ko-fi.com/takitsu) and vote on [top.gg](https://top.gg/bot/682946560417333283/vote) for the bot.\n[World Health Organization advices](https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public)", timestamp=dt.datetime.utcnow(), color=utils.COLOR) embed.set_author(name="Personal tracker for Coronavirus COVID-19", icon_url=self.bot.author_thumb) embed.set_thumbnail(url=self.bot.thumb + str(uuid.uuid4())) embed.add_field(name="<:confirmed:688686089548202004> Confirmed", value=f"{self.bot._data['total']['confirmed']:,}") embed.add_field( name="<:recov:688686059567185940> Recovered", value= f"{self.bot._data['total']['recovered']:,} (**{utils.percentage(self.bot._data['total']['confirmed'], self.bot._data['total']['recovered'])}**)" ) embed.add_field( name="<:_death:688686194917244928> Deaths", value= f"{self.bot._data['total']['deaths']:,} (**{utils.percentage(self.bot._data['total']['confirmed'], self.bot._data['total']['deaths'])}**)" ) embed.add_field( name="<:_calendar:692860616930623698> Today confirmed", value= f"+{self.bot._data['total']['today']['confirmed']:,} (**{utils.percentage(self.bot._data['total']['confirmed'], self.bot._data['total']['today']['confirmed'])}**)" ) embed.add_field( name="<:_calendar:692860616930623698> Today recovered", value= f"+{self.bot._data['total']['today']['recovered']:,} (**{utils.percentage(self.bot._data['total']['confirmed'], self.bot._data['total']['today']['recovered'])}**)" ) embed.add_field( name="<:_calendar:692860616930623698> Today deaths", value= f"+{self.bot._data['total']['today']['deaths']:,} (**{utils.percentage(self.bot._data['total']['confirmed'], self.bot._data['total']['today']['deaths'])}**)" ) embed.add_field( name="<:bed_hospital:692857285499682878> Active", value= f"{self.bot._data['total']['active']:,} (**{utils.percentage(self.bot._data['total']['confirmed'], self.bot._data['total']['active'])}**)" ) tracked = db.send_tracker() for t in tracked: try: dm = self.bot.get_user(int(t["user_id"])) header, text = utils.string_formatting(self.bot._data, t["country"].split(" ")) embed.description = "You can support me on <:kofi:693473314433138718>[Kofi](https://ko-fi.com/takitsu) and vote on [top.gg](https://top.gg/bot/682946560417333283/vote) for the bot. <:github:693519776022003742> [Source code](https://github.com/takitsu21/covid-19-tracker)\n\n" + text with open("stats.png", "rb") as p: img = discord.File(p, filename="stats.png") embed.set_image(url=f'attachment://stats.png') 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(file=img, embed=embed) except Exception as e: pass
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)
async def info(self, ctx): DATA = utils.from_json(utils.DATA_PATH) header, text = utils.string_formatting(DATA) # pages = self.generate_pages(DATA, len(header)) # index = 0 # page_length = len(pages) # print(page_length) # if page_length > 1: # page_left = "⬅️" # page_right = "➡️" # base_reactions = [page_left, page_right] # embed.set_author( # name=f"Page {index + 1}", # url="https://www.who.int/home", # icon_url=self.author_thumb # ) # pagination = await ctx.send(embed=embed) # for reaction in base_reactions: # await pagination.add_reaction(reaction) # while True: # def check(reaction, user): # return user == ctx.message.author and str(reaction.emoji) in base_reactions # try: # reaction, user = await self.bot.wait_for('reaction_add', check=check, timeout=300.0) # emoji = str(reaction.emoji) # except asyncio.TimeoutError: # try: # await ctx.message.delete() # except: # pass # return await pagination.delete() # if page_left in emoji and index > 0: # index -= 1 # elif page_right in emoji and index < page_length: # index += 1 # if index >= 0 and index <= page_length: # embed = discord.Embed( # description=pages[0][index] # ) # embed.set_author( # name=f"Page {index + 1}", # url="https://www.who.int/home", # icon_url=self.author_thumb # ) # embed.color = utils.COLOR # embed.timestamp = utils.discord_timestamp() # embed.set_thumbnail(url=self.thumb) # embed.set_footer(text=utils.last_update(utils.DATA_PATH), # icon_url=ctx.guild.me.avatar_url) # await pagination.edit(embed=embed) # for i, _p in enumerate(pages): # embed = discord.Embed( # description=header + "\n" + _p[i], # color=utils.COLOR, # timestamp=utils.discord_timestamp() # ) # embed.set_author( # name=f"Coronavrius COVID-19 Pages {i + 1}/{page_length} (Cases confirmed)", # url="https://www.who.int/home", # icon_url=self.author_thumb # ) # embed.color = utils.COLOR # embed.timestamp = utils.discord_timestamp() # 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) # else: embed = discord.Embed( description=header + "\n" + text, color=utils.COLOR, timestamp=utils.discord_timestamp() ) embed.set_author( name=f"Country/Region affected by Coronavirus COVID-19 (Cases confirmed)", url="https://www.who.int/home", icon_url=self.author_thumb ) embed.color = utils.COLOR embed.timestamp = utils.discord_timestamp() 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)