77"""
88
99
10+ from datetime import datetime
1011from io import BytesIO
1112
12- import aiohttp
1313import cairosvg
14- from datetime import datetime
14+ import httpx
1515
1616import discord
1717import discord .ext .commands as commands
@@ -27,15 +27,17 @@ class PropagationCog(commands.Cog):
2727
2828 def __init__ (self , bot ):
2929 self .bot = bot
30- self .session = aiohttp . ClientSession ( connector = bot .qrm .connector )
30+ self .httpx_client : httpx . AsyncClient = bot .qrm .httpx_client
3131
3232 @commands .command (name = "mufmap" , aliases = ["muf" ], category = cmn .Cats .WEATHER )
3333 async def mufmap (self , ctx : commands .Context ):
3434 """Shows a world map of the Maximum Usable Frequency (MUF)."""
3535 async with ctx .typing ():
36- async with self .session .get (self .muf_url , headers = {"Connection" : "Upgrade" , "Upgrade" : "http/1.1" }) as r :
37- svg = await r .read ()
38- out = BytesIO (cairosvg .svg2png (bytestring = svg ))
36+ resp = await self .httpx_client .get (self .muf_url )
37+ await resp .aclose ()
38+ if resp .status_code != 200 :
39+ raise cmn .BotHTTPError (resp )
40+ out = BytesIO (cairosvg .svg2png (bytestring = await resp .aread ()))
3941 file = discord .File (out , "muf_map.png" )
4042 embed = cmn .embed_factory (ctx )
4143 embed .title = "Maximum Usable Frequency Map"
@@ -47,9 +49,11 @@ async def mufmap(self, ctx: commands.Context):
4749 async def fof2map (self , ctx : commands .Context ):
4850 """Shows a world map of the Critical Frequency (foF2)."""
4951 async with ctx .typing ():
50- async with self .session .get (self .fof2_url , headers = {"Connection" : "Upgrade" , "Upgrade" : "http/1.1" }) as r :
51- svg = await r .read ()
52- out = BytesIO (cairosvg .svg2png (bytestring = svg ))
52+ resp = await self .httpx_client .get (self .fof2_url )
53+ await resp .aclose ()
54+ if resp .status_code != 200 :
55+ raise cmn .BotHTTPError (resp )
56+ out = BytesIO (cairosvg .svg2png (bytestring = await resp .aread ()))
5357 file = discord .File (out , "fof2_map.png" )
5458 embed = cmn .embed_factory (ctx )
5559 embed .title = "Critical Frequency (foF2) Map"
@@ -67,15 +71,20 @@ async def grayline(self, ctx: commands.Context):
6771 embed .set_image (url = self .gl_baseurl + date_params )
6872 await ctx .send (embed = embed )
6973
70- @commands .command (name = "solarweather" , aliases = ["solar" ],
71- category = cmn .Cats .WEATHER )
74+ @commands .command (name = "solarweather" , aliases = ["solar" ], category = cmn .Cats .WEATHER )
7275 async def solarweather (self , ctx : commands .Context ):
7376 """Gets a solar weather report."""
77+ resp = await self .httpx_client .get (self .n0nbh_sun_url )
78+ await resp .aclose ()
79+ if resp .status_code != 200 :
80+ raise cmn .BotHTTPError (resp )
81+ img = BytesIO (await resp .aread ())
82+ file = discord .File (img , "solarweather.png" )
7483 embed = cmn .embed_factory (ctx )
7584 embed .title = "☀️ Current Solar Weather"
7685 embed .colour = cmn .colours .good
77- embed .set_image (url = self . n0nbh_sun_url )
78- await ctx .send (embed = embed )
86+ embed .set_image (url = "attachment://solarweather.png" )
87+ await ctx .send (file = file , embed = embed )
7988
8089
8190def setup (bot : commands .Bot ):
0 commit comments