2019-12-11 02:33:11 -05:00
|
|
|
"""
|
|
|
|
Lookup extension for qrm
|
|
|
|
---
|
2020-01-06 23:27:48 -05:00
|
|
|
Copyright (C) 2019-2020 Abigail Gold, 0x5c
|
2019-12-11 02:33:11 -05:00
|
|
|
|
2020-01-31 06:50:50 -05:00
|
|
|
This file is part of discord-qrm2 and is released under the terms of
|
|
|
|
the GNU General Public License, version 2.
|
2019-12-11 02:33:11 -05:00
|
|
|
"""
|
|
|
|
|
2020-01-31 06:50:50 -05:00
|
|
|
|
2019-12-11 02:33:11 -05:00
|
|
|
import threading
|
|
|
|
|
|
|
|
from ctyparser import BigCty
|
|
|
|
|
2020-02-05 07:09:08 -05:00
|
|
|
from discord.ext import commands, tasks
|
|
|
|
|
2019-12-11 02:33:11 -05:00
|
|
|
import common as cmn
|
|
|
|
|
|
|
|
|
|
|
|
class LookupCog(commands.Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
try:
|
2020-01-30 06:15:42 -05:00
|
|
|
self.cty = BigCty("./data/cty.json")
|
2019-12-11 02:33:11 -05:00
|
|
|
except OSError:
|
|
|
|
self.cty = BigCty()
|
|
|
|
|
|
|
|
# TODO: See #107
|
|
|
|
# @commands.command(name="sat", category=cmn.cat.lookup)
|
|
|
|
# async def _sat_lookup(self, ctx: commands.Context, sat_name: str, grid1: str, grid2: str = None):
|
2020-01-30 06:15:42 -05:00
|
|
|
# """Links to info about satellite passes on satmatch.com."""
|
|
|
|
# now = datetime.utcnow().strftime("%Y-%m-%d%%20%H:%M")
|
|
|
|
# if grid2 is None or grid2 == "":
|
|
|
|
# await ctx.send(f"http://www.satmatch.com/satellite/{sat_name}/obs1/{grid1}"
|
|
|
|
# f"?search_start_time={now}&duration_hrs=24")
|
2019-12-11 02:33:11 -05:00
|
|
|
# else:
|
2020-01-30 06:15:42 -05:00
|
|
|
# await ctx.send(f"http://www.satmatch.com/satellite/{sat_name}/obs1/{grid1}"
|
|
|
|
# f"/obs2/{grid2}?search_start_time={now}&duration_hrs=24")
|
2019-12-11 02:33:11 -05:00
|
|
|
|
2020-01-30 06:15:42 -05:00
|
|
|
@commands.command(name="dxcc", aliases=["dx"], category=cmn.cat.lookup)
|
2019-12-11 02:33:11 -05:00
|
|
|
async def _dxcc_lookup(self, ctx: commands.Context, query: str):
|
2020-02-15 04:59:25 -05:00
|
|
|
"""Gets DXCC info about a callsign prefix."""
|
2019-12-11 02:33:11 -05:00
|
|
|
with ctx.typing():
|
|
|
|
query = query.upper()
|
|
|
|
full_query = query
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-02-05 07:30:14 -05:00
|
|
|
embed.title = "DXCC Info for "
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.description = f"*Last Updated: {self.cty.formatted_version}*"
|
2019-12-11 02:33:11 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
while query:
|
|
|
|
if query in self.cty.keys():
|
|
|
|
data = self.cty[query]
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.add_field(name="Entity", value=data["entity"])
|
|
|
|
embed.add_field(name="CQ Zone", value=data["cq"])
|
|
|
|
embed.add_field(name="ITU Zone", value=data["itu"])
|
|
|
|
embed.add_field(name="Continent", value=data["continent"])
|
2019-12-25 02:30:03 -05:00
|
|
|
embed.add_field(name="Time Zone",
|
2020-01-30 06:15:42 -05:00
|
|
|
value=f"+{data['tz']}" if data["tz"] > 0 else str(data["tz"]))
|
2019-12-11 02:33:11 -05:00
|
|
|
embed.title += query
|
|
|
|
embed.colour = cmn.colours.good
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
query = query[:-1]
|
|
|
|
else:
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.title += full_query + " not found"
|
2019-12-11 02:33:11 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
|
|
|
@tasks.loop(hours=24)
|
|
|
|
async def _update_cty(self):
|
|
|
|
update = threading.Thread(target=run_update, args=(self.cty, "./data/cty.json"))
|
|
|
|
update.start()
|
|
|
|
|
|
|
|
|
|
|
|
def run_update(cty_obj, dump_loc):
|
|
|
|
update = cty_obj.update()
|
|
|
|
if update:
|
|
|
|
cty_obj.dump(dump_loc)
|
|
|
|
|
|
|
|
|
|
|
|
def setup(bot: commands.Bot):
|
|
|
|
lookupcog = LookupCog(bot)
|
|
|
|
bot.add_cog(lookupcog)
|
|
|
|
lookupcog._update_cty.start()
|