2019-10-05 19:13:24 -04:00
|
|
|
"""
|
2019-12-07 17:26:55 -05:00
|
|
|
Image extension for qrm
|
2019-10-05 19:13:24 -04:00
|
|
|
---
|
2020-01-06 23:27:48 -05:00
|
|
|
Copyright (C) 2019-2020 Abigail Gold, 0x5c
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2020-02-15 06:27:48 -05:00
|
|
|
This file is part of qrm2 and is released under the terms of
|
2020-01-31 06:50:50 -05:00
|
|
|
the GNU General Public License, version 2.
|
2019-10-05 19:13:24 -04:00
|
|
|
"""
|
|
|
|
|
2020-01-31 06:50:50 -05:00
|
|
|
|
2020-01-07 05:36:09 -05:00
|
|
|
import aiohttp
|
2021-01-18 00:28:16 -05:00
|
|
|
from datetime import datetime
|
2020-01-07 05:36:09 -05:00
|
|
|
|
2019-10-05 19:13:24 -04:00
|
|
|
import discord
|
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
import common as cmn
|
|
|
|
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
class ImageCog(commands.Cog):
|
2021-01-18 00:28:16 -05:00
|
|
|
gl_baseurl = "https://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=ETOPO1_day-m.evif&dynimg=y&opt=-p"
|
2020-01-20 03:17:50 -05:00
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
def __init__(self, bot: commands.Bot):
|
2019-10-05 19:13:24 -04:00
|
|
|
self.bot = bot
|
2019-12-23 20:51:31 -05:00
|
|
|
self.bandcharts = cmn.ImagesGroup(cmn.paths.bandcharts / "meta.json")
|
|
|
|
self.maps = cmn.ImagesGroup(cmn.paths.maps / "meta.json")
|
2020-01-07 05:36:09 -05:00
|
|
|
self.session = aiohttp.ClientSession(connector=bot.qrm.connector)
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2020-01-30 06:15:42 -05:00
|
|
|
@commands.command(name="bandplan", aliases=["plan", "bands"], category=cmn.cat.ref)
|
|
|
|
async def _bandplan(self, ctx: commands.Context, region: str = ""):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Gets the frequency allocations chart for a given country."""
|
2020-01-20 03:17:50 -05:00
|
|
|
async with ctx.typing():
|
|
|
|
arg = region.lower()
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2019-12-23 20:51:31 -05:00
|
|
|
if arg not in self.bandcharts:
|
2020-01-30 06:15:42 -05:00
|
|
|
desc = "Possible arguments are:\n"
|
2019-12-23 20:51:31 -05:00
|
|
|
for key, img in self.bandcharts.items():
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += f"`{key}`: {img.name}{(' ' + img.emoji if img.emoji else '')}\n"
|
2020-02-05 07:30:14 -05:00
|
|
|
embed.title = "Bandplan Not Found!"
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.description = desc
|
|
|
|
embed.colour = cmn.colours.bad
|
2019-10-18 08:45:56 -04:00
|
|
|
await ctx.send(embed=embed)
|
2020-01-20 03:17:50 -05:00
|
|
|
return
|
|
|
|
metadata: cmn.ImageMetadata = self.bandcharts[arg]
|
|
|
|
img = discord.File(cmn.paths.bandcharts / metadata.filename,
|
|
|
|
filename=metadata.filename)
|
|
|
|
if metadata.description:
|
|
|
|
embed.description = metadata.description
|
|
|
|
if metadata.source:
|
|
|
|
embed.add_field(name="Source", value=metadata.source)
|
|
|
|
embed.title = metadata.long_name + (" " + metadata.emoji if metadata.emoji else "")
|
|
|
|
embed.colour = cmn.colours.good
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.set_image(url="attachment://" + metadata.filename)
|
2020-01-20 03:17:50 -05:00
|
|
|
await ctx.send(embed=embed, file=img)
|
2019-12-23 20:51:31 -05:00
|
|
|
|
|
|
|
@commands.command(name="map", category=cmn.cat.maps)
|
2020-01-30 06:15:42 -05:00
|
|
|
async def _map(self, ctx: commands.Context, map_id: str = ""):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Posts a ham-relevant map."""
|
2020-01-20 03:17:50 -05:00
|
|
|
async with ctx.typing():
|
|
|
|
arg = map_id.lower()
|
2019-12-23 20:51:31 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
if arg not in self.maps:
|
2020-01-30 06:15:42 -05:00
|
|
|
desc = "Possible arguments are:\n"
|
2019-12-23 20:51:31 -05:00
|
|
|
for key, img in self.maps.items():
|
2020-01-30 06:15:42 -05:00
|
|
|
desc += f"`{key}`: {img.name}{(' ' + img.emoji if img.emoji else '')}\n"
|
|
|
|
embed.title = "Map Not Found!"
|
2019-12-23 20:51:31 -05:00
|
|
|
embed.description = desc
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
await ctx.send(embed=embed)
|
2020-01-20 03:17:50 -05:00
|
|
|
return
|
|
|
|
metadata: cmn.ImageMetadata = self.maps[arg]
|
|
|
|
img = discord.File(cmn.paths.maps / metadata.filename,
|
|
|
|
filename=metadata.filename)
|
|
|
|
if metadata.description:
|
|
|
|
embed.description = metadata.description
|
|
|
|
if metadata.source:
|
|
|
|
embed.add_field(name="Source", value=metadata.source)
|
|
|
|
embed.title = metadata.long_name + (" " + metadata.emoji if metadata.emoji else "")
|
|
|
|
embed.colour = cmn.colours.good
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.set_image(url="attachment://" + metadata.filename)
|
2020-01-20 03:17:50 -05:00
|
|
|
await ctx.send(embed=embed, file=img)
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2020-01-30 06:15:42 -05:00
|
|
|
@commands.command(name="grayline", aliases=["greyline", "grey", "gray", "gl"], category=cmn.cat.maps)
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _grayline(self, ctx: commands.Context):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Gets a map of the current greyline, where HF propagation is the best."""
|
2020-10-30 05:22:16 -04:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "Current Greyline Conditions"
|
|
|
|
embed.colour = cmn.colours.good
|
2021-01-18 00:28:16 -05:00
|
|
|
date_params = f"&date=1&utc={datetime.utcnow():%Y-%m-%d+%H:%M:%S}"
|
|
|
|
embed.set_image(url=self.gl_baseurl + date_params)
|
2020-10-30 05:22:16 -04:00
|
|
|
await ctx.send(embed=embed)
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
def setup(bot: commands.Bot):
|
2019-10-05 19:13:24 -04:00
|
|
|
bot.add_cog(ImageCog(bot))
|