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
|
|
|
---
|
2021-03-28 13:57:03 -04:00
|
|
|
Copyright (C) 2019-2021 classabbyamp, 0x5c
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2021-06-26 20:23:55 -04:00
|
|
|
SPDX-License-Identifier: LiLiQ-Rplus-1.1
|
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
|
|
|
|
|
2019-10-05 19:13:24 -04:00
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
import common as cmn
|
|
|
|
|
2021-03-18 09:17:30 -04:00
|
|
|
import data.options as opt
|
|
|
|
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
class ImageCog(commands.Cog):
|
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
|
2021-03-18 09:17:30 -04:00
|
|
|
self.bandcharts = cmn.ImagesGroup(cmn.paths.resources / "bandcharts.1.json")
|
|
|
|
self.maps = cmn.ImagesGroup(cmn.paths.resources / "maps.1.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
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.command(name="bandchart", aliases=["bandplan", "plan", "bands"], category=cmn.Cats.REF)
|
2021-03-27 18:00:28 -04:00
|
|
|
async def _bandcharts(self, ctx: commands.Context, chart_id: str = ""):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Gets the frequency allocations chart for a given country."""
|
2021-03-27 18:00:28 -04:00
|
|
|
await ctx.send(embed=create_embed(ctx, "Bandchart", self.bandcharts, chart_id))
|
2019-12-23 20:51:31 -05:00
|
|
|
|
2021-03-28 09:50:51 -04:00
|
|
|
@commands.command(name="map", category=cmn.Cats.REF)
|
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."""
|
2021-03-27 18:00:28 -04:00
|
|
|
await ctx.send(embed=create_embed(ctx, "Map", self.maps, map_id))
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
|
2021-03-27 18:00:28 -04:00
|
|
|
def create_embed(ctx: commands.Context, not_found_name: str, db: cmn.ImagesGroup, img_id: str):
|
|
|
|
"""Creates an embed for the image and its metadata, or list available images in the group."""
|
|
|
|
img_id = img_id.lower()
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
if img_id not in db:
|
|
|
|
desc = "Possible arguments are:\n"
|
|
|
|
for key, img in db.items():
|
|
|
|
desc += f"`{key}`: {img.name}{(' ' + img.emoji if img.emoji else '')}\n"
|
|
|
|
embed.title = f"{not_found_name} Not Found!"
|
|
|
|
embed.description = desc
|
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
return embed
|
|
|
|
metadata = db[img_id]
|
|
|
|
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
|
|
|
|
embed.set_image(url=opt.resources_url + metadata.filename)
|
|
|
|
return embed
|
|
|
|
|
|
|
|
|
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))
|