2019-10-05 19:54:04 -04:00
|
|
|
"""
|
2019-12-07 17:26:55 -05:00
|
|
|
Grid extension for qrm
|
2019-10-05 19:54:04 -04:00
|
|
|
---
|
2020-01-06 23:27:48 -05:00
|
|
|
Copyright (C) 2019-2020 Abigail Gold, 0x5c
|
2019-10-05 19:54:04 -04:00
|
|
|
|
2020-02-15 06:27:48 -05:00
|
|
|
This file is part of qrm2 and is released under the terms of
|
2020-01-31 06:50:50 -05:00
|
|
|
the GNU General Public License, version 2.
|
2019-10-05 19:54:04 -04:00
|
|
|
"""
|
|
|
|
|
2020-01-31 06:50:50 -05:00
|
|
|
|
2020-12-22 20:40:24 -05:00
|
|
|
import gridtools
|
2019-10-09 01:25:33 -04:00
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
import common as cmn
|
|
|
|
|
2019-10-05 19:54:04 -04:00
|
|
|
|
|
|
|
class GridCog(commands.Cog):
|
2019-10-18 08:27:05 -04:00
|
|
|
def __init__(self, bot: commands.Bot):
|
2019-10-05 19:54:04 -04:00
|
|
|
self.bot = bot
|
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.command(name="grid", category=cmn.Cats.MAPS)
|
2020-12-22 20:40:24 -05:00
|
|
|
async def _grid_sq_lookup(self, ctx: commands.Context, lat: float, lon: float):
|
|
|
|
("""Calculates the grid square for latitude and longitude coordinates."""
|
|
|
|
"""\n\nCoordinates should be in decimal format, with negative being latitude South and longitude West."""
|
|
|
|
"""\n\nTo calculate the latitude and longitude from a grid locator, use `latlong`""")
|
|
|
|
latlong = gridtools.LatLong(lat, lon)
|
|
|
|
grid = gridtools.Grid(latlong)
|
|
|
|
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = f"Maidenhead Grid Locator for {latlong.lat:.5f}, {latlong.long:.5f}"
|
|
|
|
embed.description = f"**{grid}**"
|
|
|
|
embed.colour = cmn.colours.good
|
2019-10-05 19:54:04 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.command(name="latlong", aliases=["latlon", "loc", "ungrid"], category=cmn.Cats.MAPS)
|
2020-12-22 20:40:24 -05:00
|
|
|
async def _location_lookup(self, ctx: commands.Context, grid: str):
|
|
|
|
("""Calculates the latitude and longitude for the center of a grid locator."""
|
|
|
|
"""\n\nTo calculate the grid locator from a latitude and longitude, use `grid`"""
|
|
|
|
"""\n\n*Warning: `ungrid` will be removed soon. Use one of the other names for this command.*""")
|
|
|
|
grid_obj = gridtools.Grid(grid)
|
|
|
|
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = f"Latitude and Longitude for {grid_obj}"
|
|
|
|
embed.colour = cmn.colours.good
|
|
|
|
embed.description = f"**{grid_obj.lat:.5f}, {grid_obj.long:.5f}**"
|
|
|
|
if ctx.invoked_with == "ungrid":
|
|
|
|
embed.add_field(name="Warning", value=(f"*`{ctx.prefix}ungrid` will be removed soon, use `{ctx.prefix}help "
|
|
|
|
"latlong` to see other names for this command.*"))
|
2019-10-05 19:54:04 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2021-03-28 02:38:36 -04:00
|
|
|
@commands.command(name="griddistance", aliases=["griddist", "distance", "dist"], category=cmn.Cats.MAPS)
|
2020-12-22 20:40:24 -05:00
|
|
|
async def _dist_lookup(self, ctx: commands.Context, grid1: str, grid2: str):
|
|
|
|
"""Calculates the great circle distance and azimuthal bearing between two grid locators."""
|
|
|
|
g1 = gridtools.Grid(grid1)
|
|
|
|
g2 = gridtools.Grid(grid2)
|
2019-10-18 08:27:05 -04:00
|
|
|
|
2020-12-22 20:40:24 -05:00
|
|
|
dist, bearing = gridtools.grid_distance(g1, g2)
|
|
|
|
dist_mi = 0.6214 * dist
|
|
|
|
|
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = f"Great Circle Distance and Bearing from {g1} to {g2}"
|
|
|
|
embed.description = f"**Distance:** {dist:.1f} km ({dist_mi:.1f} mi)\n**Bearing:** {bearing:.1f}°"
|
|
|
|
embed.colour = cmn.colours.good
|
|
|
|
await ctx.send(embed=embed)
|
2019-10-18 08:27:05 -04:00
|
|
|
|
|
|
|
|
|
|
|
def setup(bot: commands.Bot):
|
2019-10-05 19:54:04 -04:00
|
|
|
bot.add_cog(GridCog(bot))
|