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
|
|
|
---
|
|
|
|
Copyright (C) 2019 Abigail Gold, 0x5c
|
|
|
|
|
2019-12-08 15:35:58 -05:00
|
|
|
This file is part of discord-qrm2 and is released under the terms of the GNU
|
2019-10-05 19:13:24 -04:00
|
|
|
General Public License, version 2.
|
|
|
|
"""
|
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
import io
|
|
|
|
|
2019-10-05 19:13:24 -04:00
|
|
|
import discord
|
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
|
|
|
import aiohttp
|
2019-10-08 19:43:09 -04:00
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
import common as cmn
|
|
|
|
|
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
|
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
@commands.command(name="bandplan", aliases=['plan', 'bands'], category=cmn.cat.ref)
|
|
|
|
async def _bandplan(self, ctx: commands.Context, region: str = ''):
|
|
|
|
'''Posts an image of Frequency Allocations.'''
|
2019-10-08 19:43:09 -04:00
|
|
|
name = {'cn': 'Chinese',
|
|
|
|
'ca': 'Canadian',
|
|
|
|
'nl': 'Dutch',
|
|
|
|
'us': 'US',
|
|
|
|
'mx': 'Mexican'}
|
2019-12-06 01:19:42 -05:00
|
|
|
arg = region.lower()
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
with ctx.typing():
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2019-10-08 19:43:09 -04:00
|
|
|
if arg not in name:
|
2019-10-18 08:45:56 -04:00
|
|
|
desc = 'Possible arguments are:\n'
|
|
|
|
for abbrev, title in name.items():
|
|
|
|
desc += f'`{abbrev}`: {title}\n'
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.title = f'Bandplan Not Found!'
|
|
|
|
embed.description = desc
|
|
|
|
embed.colour = cmn.colours.bad
|
2019-10-18 08:45:56 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
else:
|
|
|
|
img = discord.File(f"resources/images/bandchart/{arg}bandchart.png",
|
|
|
|
filename=f'{arg}bandchart.png')
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.title = f'{name[arg]} Amateur Radio Bands'
|
|
|
|
embed.colour = cmn.colours.good
|
2019-10-18 08:45:56 -04:00
|
|
|
embed.set_image(url=f'attachment://{arg}bandchart.png')
|
|
|
|
await ctx.send(embed=embed, file=img)
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2019-12-06 01:19: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):
|
2019-10-05 19:13:24 -04:00
|
|
|
'''Posts a map of the current greyline, where HF propagation is the best.'''
|
2019-10-18 08:27:05 -04:00
|
|
|
gl_url = ('http://www.fourmilab.ch/cgi-bin/uncgi/Earth?img=NOAAtopo.evif'
|
|
|
|
'&imgsize=320&dynimg=y&opt=-p&lat=&lon=&alt=&tle=&date=0&utc=&jd=')
|
2019-10-05 19:13:24 -04:00
|
|
|
with ctx.typing():
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = 'Current Greyline Conditions'
|
|
|
|
embed.colour = cmn.colours.good
|
2019-10-18 08:27:05 -04:00
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get(gl_url) as resp:
|
|
|
|
if resp.status != 200:
|
|
|
|
embed.description = 'Could not download file...'
|
2019-12-06 01:19:42 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2019-10-18 08:27:05 -04:00
|
|
|
else:
|
|
|
|
data = io.BytesIO(await resp.read())
|
|
|
|
embed.set_image(url=f'attachment://greyline.jpg')
|
2019-10-08 19:43:09 -04:00
|
|
|
await ctx.send(embed=embed, file=discord.File(data, 'greyline.jpg'))
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
@commands.command(name="map", category=cmn.cat.maps)
|
|
|
|
async def _map(self, ctx: commands.Context, map_id: str = ''):
|
|
|
|
'''Posts an image of a ham-relevant map.'''
|
2019-10-05 19:13:24 -04:00
|
|
|
map_titles = {"cq": 'Worldwide CQ Zones Map',
|
|
|
|
"itu": 'Worldwide ITU Zones Map',
|
|
|
|
"arrl": 'ARRL/RAC Section Map',
|
|
|
|
"rac": 'ARRL/RAC Section Map',
|
|
|
|
"cn": 'Chinese Callsign Areas',
|
2019-10-08 19:43:09 -04:00
|
|
|
"us": 'US Callsign Areas'}
|
2019-10-05 19:13:24 -04:00
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
arg = map_id.lower()
|
2019-10-05 19:13:24 -04:00
|
|
|
with ctx.typing():
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2019-10-08 19:43:09 -04:00
|
|
|
if arg not in map_titles:
|
2019-10-18 08:45:56 -04:00
|
|
|
desc = 'Possible arguments are:\n'
|
|
|
|
for abbrev, title in map_titles.items():
|
|
|
|
desc += f'`{abbrev}`: {title}\n'
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.title = 'Map Not Found!'
|
|
|
|
embed.description = desc
|
|
|
|
embed.colour = cmn.colours.bad
|
2019-10-18 08:45:56 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
else:
|
|
|
|
img = discord.File(f"resources/images/map/{arg}map.png",
|
|
|
|
filename=f'{arg}map.png')
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.title = f'{map_titles[arg]}'
|
|
|
|
embed.colour = cmn.colours.good
|
2019-10-18 08:45:56 -04:00
|
|
|
embed.set_image(url=f'attachment://{arg}map.png')
|
|
|
|
await ctx.send(embed=embed, file=img)
|
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))
|