2019-10-05 19:13:24 -04:00
|
|
|
"""
|
|
|
|
Image cog for qrm
|
|
|
|
---
|
|
|
|
Copyright (C) 2019 Abigail Gold, 0x5c
|
|
|
|
|
|
|
|
This file is part of discord-qrmbot and is released under the terms of the GNU
|
|
|
|
General Public License, version 2.
|
|
|
|
"""
|
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
import io
|
|
|
|
from datetime import datetime
|
|
|
|
|
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-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
|
|
|
|
self.gs = bot.get_cog("GlobalSettings")
|
|
|
|
|
|
|
|
@commands.command(name="plan", aliases=['bands'])
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _bandplan(self, ctx: commands.Context, msg: str = ''):
|
2019-10-05 19:13:24 -04:00
|
|
|
'''Posts an image of Frequency Allocations.
|
|
|
|
Optional argument: `cn`, `ca`, `nl`, `us`, `mx`.'''
|
2019-10-08 19:43:09 -04:00
|
|
|
name = {'cn': 'Chinese',
|
|
|
|
'ca': 'Canadian',
|
|
|
|
'nl': 'Dutch',
|
|
|
|
'us': 'US',
|
|
|
|
'mx': 'Mexican'}
|
2019-10-05 19:13:24 -04:00
|
|
|
arg = msg.lower()
|
|
|
|
|
|
|
|
with ctx.typing():
|
2019-10-08 19:43:09 -04:00
|
|
|
if arg not in name:
|
|
|
|
arg = 'us'
|
2019-10-18 06:06:20 -04:00
|
|
|
img = discord.File(f"resources/images/bandchart/{arg}bandchart.png",
|
2019-10-08 19:43:09 -04:00
|
|
|
filename=f'{arg}bandchart.png')
|
|
|
|
embed = discord.Embed(title=f'{name[arg]} Amateur Radio Bands',
|
|
|
|
colour=self.gs.colours.good,
|
|
|
|
timestamp=datetime.utcnow())
|
|
|
|
embed.set_image(url=f'attachment://{arg}bandchart.png')
|
|
|
|
embed.set_footer(text=ctx.author.name,
|
|
|
|
icon_url=str(ctx.author.avatar_url))
|
|
|
|
|
|
|
|
await ctx.send(embed=embed, file=img)
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
@commands.command(name="cond", aliases=['condx'])
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _band_conditions(self, ctx: commands.Context):
|
2019-10-05 19:13:24 -04:00
|
|
|
'''Posts an image of HF Band Conditions.'''
|
|
|
|
with ctx.typing():
|
2019-10-08 19:43:09 -04:00
|
|
|
embed = discord.Embed(title='Current Solar Conditions',
|
|
|
|
colour=self.gs.colours.good,
|
|
|
|
timestamp=datetime.utcnow())
|
2019-10-18 08:27:05 -04:00
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
|
async with session.get('http://www.hamqsl.com/solarsun.php') as resp:
|
|
|
|
if resp.status != 200:
|
|
|
|
embed.description = 'Could not download file...'
|
|
|
|
embed.colour = self.gs.colours.bad
|
|
|
|
else:
|
|
|
|
data = io.BytesIO(await resp.read())
|
|
|
|
embed.set_image(url=f'attachment://condx.png')
|
2019-10-08 19:43:09 -04:00
|
|
|
embed.set_footer(text=ctx.author.name,
|
|
|
|
icon_url=str(ctx.author.avatar_url))
|
|
|
|
await ctx.send(embed=embed, file=discord.File(data, 'condx.png'))
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
@commands.command(name="grayline", aliases=['greyline', 'grey', 'gray', 'gl'])
|
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-10-08 19:43:09 -04:00
|
|
|
embed = discord.Embed(title='Current Greyline Conditions',
|
|
|
|
colour=self.gs.colours.good,
|
|
|
|
timestamp=datetime.utcnow())
|
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...'
|
|
|
|
embed.colour = self.gs.colours.bad
|
|
|
|
else:
|
|
|
|
data = io.BytesIO(await resp.read())
|
|
|
|
embed.set_image(url=f'attachment://greyline.jpg')
|
2019-10-08 19:43:09 -04:00
|
|
|
embed.set_footer(text=ctx.author.name,
|
|
|
|
icon_url=str(ctx.author.avatar_url))
|
|
|
|
await ctx.send(embed=embed, file=discord.File(data, 'greyline.jpg'))
|
2019-10-05 19:13:24 -04:00
|
|
|
|
|
|
|
@commands.command(name="map")
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _map(self, ctx: commands.Context, msg: str = ''):
|
2019-10-05 19:13:24 -04:00
|
|
|
'''Posts an image of Frequency Allocations.
|
|
|
|
Optional argument:`cq` = CQ Zones, `itu` = ITU Zones, `arrl` or `rac` =
|
|
|
|
ARRL/RAC sections, `cn` = Chinese Callsign Areas, `us` = US Callsign Areas.'''
|
|
|
|
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
|
|
|
|
|
|
|
arg = msg.lower()
|
|
|
|
with ctx.typing():
|
2019-10-08 19:43:09 -04:00
|
|
|
if arg not in map_titles:
|
|
|
|
arg = 'us'
|
2019-10-18 06:06:20 -04:00
|
|
|
img = discord.File(f"resources/images/map/{arg}map.png",
|
2019-10-08 19:43:09 -04:00
|
|
|
filename=f'{arg}map.png')
|
|
|
|
embed = discord.Embed(title=f'{map_titles[arg]} Map',
|
|
|
|
colour=self.gs.colours.good,
|
|
|
|
timestamp=datetime.utcnow())
|
|
|
|
embed.set_image(url=f'attachment://{arg}map.png')
|
|
|
|
embed.set_footer(text=ctx.author.name,
|
|
|
|
icon_url=str(ctx.author.avatar_url))
|
|
|
|
|
|
|
|
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))
|