mirror of
https://github.com/miaowware/qrm2.git
synced 2025-09-04 22:17:47 -04:00
updates for review
This commit is contained in:
parent
b980c8e2fa
commit
69c2ae587f
@ -12,8 +12,8 @@ import threading
|
|||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
|
|
||||||
from ctyparser import BigCty
|
from ctyparser import BigCty
|
||||||
|
|
||||||
import common as cmn
|
import common as cmn
|
||||||
|
|
||||||
|
|
||||||
@ -21,47 +21,37 @@ class LookupCog(commands.Cog):
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
try:
|
try:
|
||||||
self.CTY = BigCty('./data/cty.json')
|
self.cty = BigCty('./data/cty.json')
|
||||||
except OSError:
|
except OSError:
|
||||||
self.CTY = BigCty()
|
self.cty = BigCty()
|
||||||
update = threading.Thread(target=run_update, args=(self.CTY, "./data/cty.json"))
|
|
||||||
update.start()
|
|
||||||
|
|
||||||
@commands.command(name="sat", category=cmn.cat.lookup)
|
# TODO: See #107
|
||||||
async def _sat_lookup(self, ctx: commands.Context, sat: str, grid1: str, grid2: str = None):
|
# @commands.command(name="sat", category=cmn.cat.lookup)
|
||||||
'''Links to info about satellite passes on satmatch.com.
|
# async def _sat_lookup(self, ctx: commands.Context, sat_name: str, grid1: str, grid2: str = None):
|
||||||
Usage: `?sat sat_name grid1 grid2`'''
|
# '''Links to info about satellite passes on satmatch.com.'''
|
||||||
now = datetime.utcnow().strftime('%Y-%m-%d%%20%H:%M')
|
# now = datetime.utcnow().strftime('%Y-%m-%d%%20%H:%M')
|
||||||
if grid2 is None or grid2 == '':
|
# if grid2 is None or grid2 == '':
|
||||||
await ctx.send(f'http://www.satmatch.com/satellite/{sat}/obs1/{grid1}'
|
# await ctx.send(f'http://www.satmatch.com/satellite/{sat_name}/obs1/{grid1}'
|
||||||
f'?search_start_time={now}&duration_hrs=24')
|
# f'?search_start_time={now}&duration_hrs=24')
|
||||||
else:
|
# else:
|
||||||
await ctx.send(f'http://www.satmatch.com/satellite/{sat}/obs1/{grid1}'
|
# await ctx.send(f'http://www.satmatch.com/satellite/{sat_name}/obs1/{grid1}'
|
||||||
f'/obs2/{grid2}?search_start_time={now}&duration_hrs=24')
|
# f'/obs2/{grid2}?search_start_time={now}&duration_hrs=24')
|
||||||
|
|
||||||
@commands.command(name="dxcc", aliases=['dx'], category=cmn.cat.lookup)
|
@commands.command(name="dxcc", aliases=['dx'], category=cmn.cat.lookup)
|
||||||
async def _dxcc_lookup(self, ctx: commands.Context, query: str):
|
async def _dxcc_lookup(self, ctx: commands.Context, query: str):
|
||||||
'''Gets info about a prefix.'''
|
'''Gets info about a DXCC prefix.'''
|
||||||
with ctx.typing():
|
with ctx.typing():
|
||||||
noMatch = True
|
|
||||||
queryMatch = None
|
|
||||||
query = query.upper()
|
query = query.upper()
|
||||||
embed = discord.Embed(title=f'DXCC Info for {query} not found',
|
full_query = query
|
||||||
|
embed = discord.Embed(title=f'DXCC Info for ',
|
||||||
timestamp=datetime.utcnow())
|
timestamp=datetime.utcnow())
|
||||||
embed.set_footer(text=f'{ctx.author.name}',
|
embed.set_footer(text=f'{ctx.author.name}',
|
||||||
icon_url=str(ctx.author.avatar_url))
|
icon_url=str(ctx.author.avatar_url))
|
||||||
embed.description = f'*Last Updated: {self.CTY.formatted_version}*'
|
embed.description = f'*Last Updated: {self.cty.formatted_version}*'
|
||||||
embed.colour = cmn.colours.bad
|
embed.colour = cmn.colours.bad
|
||||||
while noMatch:
|
while query:
|
||||||
if query in self.CTY.keys():
|
if query in self.cty.keys():
|
||||||
queryMatch = query
|
data = self.cty[query]
|
||||||
noMatch = False
|
|
||||||
else:
|
|
||||||
query = query[:-1]
|
|
||||||
if len(query) == 0:
|
|
||||||
noMatch = False
|
|
||||||
if queryMatch is not None:
|
|
||||||
data = self.CTY[queryMatch]
|
|
||||||
embed.add_field(name="Entity",
|
embed.add_field(name="Entity",
|
||||||
value=data['entity'])\
|
value=data['entity'])\
|
||||||
.add_field(name="CQ Zone",
|
.add_field(name="CQ Zone",
|
||||||
@ -72,18 +62,21 @@ class LookupCog(commands.Cog):
|
|||||||
value=data['continent'])\
|
value=data['continent'])\
|
||||||
.add_field(name="Time Zone",
|
.add_field(name="Time Zone",
|
||||||
value=f'+{data["tz"]}' if data['tz'] > 0 else str(data['tz']))
|
value=f'+{data["tz"]}' if data['tz'] > 0 else str(data['tz']))
|
||||||
embed.title = f'DXCC Info for {query}'
|
embed.title += query
|
||||||
embed.colour = cmn.colours.good
|
embed.colour = cmn.colours.good
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
query = query[:-1]
|
||||||
|
else:
|
||||||
|
embed.title += f'{full_query} not found'
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@tasks.loop(hours=24)
|
@tasks.loop(hours=24)
|
||||||
async def _update_cty(self):
|
async def _update_cty(self):
|
||||||
update = threading.Thread(target=run_update, args=(self.CTY, "./data/cty.json"))
|
update = threading.Thread(target=run_update, args=(self.cty, "./data/cty.json"))
|
||||||
update.start()
|
update.start()
|
||||||
|
|
||||||
def cog_unload(self):
|
|
||||||
self.CTY.dump("./data/cty.json")
|
|
||||||
|
|
||||||
|
|
||||||
def run_update(cty_obj, dump_loc):
|
def run_update(cty_obj, dump_loc):
|
||||||
update = cty_obj.update()
|
update = cty_obj.update()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user