2021-01-17 22:32:48 -05:00
|
|
|
"""
|
|
|
|
Propagation extension for qrm
|
|
|
|
---
|
2021-04-03 18:13:42 -04:00
|
|
|
Copyright (C) 2019-2021 classabbyamp, 0x5c
|
2021-01-17 22:32:48 -05:00
|
|
|
|
2021-06-26 20:23:55 -04:00
|
|
|
SPDX-License-Identifier: LiLiQ-Rplus-1.1
|
2021-01-17 22:32:48 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
2023-01-13 03:37:26 -05:00
|
|
|
from datetime import datetime
|
2021-01-17 22:32:48 -05:00
|
|
|
from io import BytesIO
|
|
|
|
|
|
|
|
import cairosvg
|
2023-01-13 03:37:26 -05:00
|
|
|
import httpx
|
2021-01-17 22:32:48 -05:00
|
|
|
|
|
|
|
import discord
|
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
|
|
|
import common as cmn
|
|
|
|
|
|
|
|
|
|
|
|
class PropagationCog(commands.Cog):
|
|
|
|
muf_url = "https://prop.kc2g.com/renders/current/mufd-normal-now.svg"
|
|
|
|
fof2_url = "https://prop.kc2g.com/renders/current/fof2-normal-now.svg"
|
2021-03-28 09:50:51 -04:00
|
|
|
gl_baseurl = "https://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=ETOPO1_day-m.evif&dynimg=y&opt=-p"
|
|
|
|
n0nbh_sun_url = "http://www.hamqsl.com/solarsun.php"
|
2021-01-17 22:32:48 -05:00
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
2023-01-13 03:37:26 -05:00
|
|
|
self.httpx_client: httpx.AsyncClient = bot.qrm.httpx_client
|
2021-01-17 22:32:48 -05:00
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.command(name="mufmap", aliases=["muf"], category=cmn.Cats.WEATHER)
|
2021-01-17 22:32:48 -05:00
|
|
|
async def mufmap(self, ctx: commands.Context):
|
|
|
|
"""Shows a world map of the Maximum Usable Frequency (MUF)."""
|
|
|
|
async with ctx.typing():
|
2023-01-13 03:37:26 -05:00
|
|
|
resp = await self.httpx_client.get(self.muf_url)
|
|
|
|
await resp.aclose()
|
|
|
|
if resp.status_code != 200:
|
|
|
|
raise cmn.BotHTTPError(resp)
|
|
|
|
out = BytesIO(cairosvg.svg2png(bytestring=await resp.aread()))
|
2021-01-17 22:32:48 -05:00
|
|
|
file = discord.File(out, "muf_map.png")
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "Maximum Usable Frequency Map"
|
|
|
|
embed.description = "Image from [prop.kc2g.com](https://prop.kc2g.com/)\nData sources listed on the page."
|
|
|
|
embed.set_image(url="attachment://muf_map.png")
|
|
|
|
await ctx.send(file=file, embed=embed)
|
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.command(name="fof2map", aliases=["fof2", "critfreq"], category=cmn.Cats.WEATHER)
|
2021-01-17 22:32:48 -05:00
|
|
|
async def fof2map(self, ctx: commands.Context):
|
|
|
|
"""Shows a world map of the Critical Frequency (foF2)."""
|
|
|
|
async with ctx.typing():
|
2023-01-13 03:37:26 -05:00
|
|
|
resp = await self.httpx_client.get(self.fof2_url)
|
|
|
|
await resp.aclose()
|
|
|
|
if resp.status_code != 200:
|
|
|
|
raise cmn.BotHTTPError(resp)
|
|
|
|
out = BytesIO(cairosvg.svg2png(bytestring=await resp.aread()))
|
2021-01-17 22:32:48 -05:00
|
|
|
file = discord.File(out, "fof2_map.png")
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "Critical Frequency (foF2) Map"
|
|
|
|
embed.description = "Image from [prop.kc2g.com](https://prop.kc2g.com/)\nData sources listed on the page."
|
|
|
|
embed.set_image(url="attachment://fof2_map.png")
|
|
|
|
await ctx.send(file=file, embed=embed)
|
|
|
|
|
2021-03-28 09:50:51 -04:00
|
|
|
@commands.command(name="grayline", aliases=["greyline", "grey", "gray", "gl"], category=cmn.Cats.WEATHER)
|
|
|
|
async def grayline(self, ctx: commands.Context):
|
|
|
|
"""Gets a map of the current greyline, where HF propagation is the best."""
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "Current Greyline Conditions"
|
|
|
|
embed.colour = cmn.colours.good
|
|
|
|
date_params = f"&date=1&utc={datetime.utcnow():%Y-%m-%d+%H:%M:%S}"
|
|
|
|
embed.set_image(url=self.gl_baseurl + date_params)
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2023-01-13 03:37:26 -05:00
|
|
|
@commands.command(name="solarweather", aliases=["solar"], category=cmn.Cats.WEATHER)
|
2021-03-28 09:50:51 -04:00
|
|
|
async def solarweather(self, ctx: commands.Context):
|
|
|
|
"""Gets a solar weather report."""
|
2023-01-13 03:37:26 -05:00
|
|
|
resp = await self.httpx_client.get(self.n0nbh_sun_url)
|
|
|
|
await resp.aclose()
|
|
|
|
if resp.status_code != 200:
|
|
|
|
raise cmn.BotHTTPError(resp)
|
|
|
|
img = BytesIO(await resp.aread())
|
|
|
|
file = discord.File(img, "solarweather.png")
|
2021-03-28 09:50:51 -04:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "☀️ Current Solar Weather"
|
|
|
|
embed.colour = cmn.colours.good
|
2023-01-13 03:37:26 -05:00
|
|
|
embed.set_image(url="attachment://solarweather.png")
|
|
|
|
await ctx.send(file=file, embed=embed)
|
2021-03-28 09:50:51 -04:00
|
|
|
|
2021-01-17 22:32:48 -05:00
|
|
|
|
|
|
|
def setup(bot: commands.Bot):
|
|
|
|
bot.add_cog(PropagationCog(bot))
|