2019-10-05 19:36:45 -04:00
|
|
|
"""
|
2019-12-07 17:26:55 -05:00
|
|
|
Ham extension for qrm
|
2019-10-05 19:36:45 -04:00
|
|
|
---
|
2020-01-06 23:27:48 -05:00
|
|
|
Copyright (C) 2019-2020 Abigail Gold, 0x5c
|
2019-10-05 19:36:45 -04:00
|
|
|
|
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:36:45 -04:00
|
|
|
General Public License, version 2.
|
|
|
|
"""
|
2019-12-25 00:42:54 -05:00
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
from datetime import datetime
|
2019-10-05 19:36:45 -04:00
|
|
|
|
|
|
|
import discord.ext.commands as commands
|
|
|
|
|
2019-12-06 01:19:42 -05:00
|
|
|
import common as cmn
|
2019-11-28 23:48:11 -05:00
|
|
|
from resources import callsign_info
|
2019-12-25 00:42:54 -05:00
|
|
|
from resources import phonetics
|
|
|
|
from resources import qcodes
|
2019-11-28 23:48:11 -05:00
|
|
|
|
2019-10-05 19:36:45 -04:00
|
|
|
|
|
|
|
class HamCog(commands.Cog):
|
2019-10-18 08:27:05 -04:00
|
|
|
def __init__(self, bot: commands.Bot):
|
2019-10-05 19:36:45 -04:00
|
|
|
self.bot = bot
|
|
|
|
|
2020-01-30 06:15:42 -05:00
|
|
|
@commands.command(name="qcode", aliases=["q"], category=cmn.cat.ref)
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _qcode_lookup(self, ctx: commands.Context, qcode: str):
|
2020-01-30 06:15:42 -05:00
|
|
|
"""Look up a Q Code."""
|
2019-10-05 19:36:45 -04:00
|
|
|
with ctx.typing():
|
2019-10-18 08:27:05 -04:00
|
|
|
qcode = qcode.upper()
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2019-12-25 00:42:54 -05:00
|
|
|
if qcode in qcodes.qcodes:
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.title = qcode
|
2019-12-25 00:42:54 -05:00
|
|
|
embed.description = qcodes.qcodes[qcode]
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2019-10-09 01:25:33 -04:00
|
|
|
else:
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.title = f"Q Code {qcode} not found"
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
2019-10-05 19:36:45 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2020-01-30 06:15:42 -05:00
|
|
|
@commands.command(name="phonetics", aliases=["ph", "phoneticize", "phoneticise", "phone"], category=cmn.cat.ref)
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _phonetics_lookup(self, ctx: commands.Context, *, msg: str):
|
2020-01-30 06:15:42 -05:00
|
|
|
"""Get phonetics for a word or phrase."""
|
2019-10-05 19:36:45 -04:00
|
|
|
with ctx.typing():
|
2020-01-30 06:15:42 -05:00
|
|
|
result = ""
|
2019-10-05 19:36:45 -04:00
|
|
|
for char in msg.lower():
|
|
|
|
if char.isalpha():
|
2019-12-25 00:42:54 -05:00
|
|
|
result += phonetics.phonetics[char]
|
2019-10-05 19:36:45 -04:00
|
|
|
else:
|
|
|
|
result += char
|
2020-01-30 06:15:42 -05:00
|
|
|
result += " "
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.title = f"Phonetics for {msg}"
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.description = result.title()
|
|
|
|
embed.colour = cmn.colours.good
|
2019-10-05 19:36:45 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2020-01-30 06:15:42 -05:00
|
|
|
@commands.command(name="utc", aliases=["z"], category=cmn.cat.ref)
|
2019-10-18 08:27:05 -04:00
|
|
|
async def _utc_lookup(self, ctx: commands.Context):
|
2020-01-30 06:15:42 -05:00
|
|
|
"""Gets the current time in UTC."""
|
2019-10-05 19:36:45 -04:00
|
|
|
with ctx.typing():
|
2019-10-18 08:27:05 -04:00
|
|
|
now = datetime.utcnow()
|
2020-01-30 06:15:42 -05:00
|
|
|
result = "**" + now.strftime("%Y-%m-%d %H:%M") + "Z**"
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.title = "The current time is:"
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.description = result
|
|
|
|
embed.colour = cmn.colours.good
|
2019-10-05 19:36:45 -04:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2020-01-04 14:46:40 -05:00
|
|
|
@commands.command(name="prefixes", aliases=["vanity", "pfx", "vanities", "prefix"], category=cmn.cat.ref)
|
2019-11-28 23:48:11 -05:00
|
|
|
async def _vanity_prefixes(self, ctx: commands.Context, country: str = None):
|
2020-01-30 06:15:42 -05:00
|
|
|
"""Lists valid prefixes for countries."""
|
2019-11-28 23:48:11 -05:00
|
|
|
if country is None:
|
|
|
|
await ctx.send_help(ctx.command)
|
|
|
|
return
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
2019-11-28 23:48:11 -05:00
|
|
|
if country.lower() not in callsign_info.options:
|
2020-01-30 06:15:42 -05:00
|
|
|
embed.title = f"{country} not found!",
|
|
|
|
embed.description = f"Valid countries: {', '.join(callsign_info.options.keys())}",
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.colour = cmn.colours.bad
|
|
|
|
else:
|
|
|
|
embed.title = callsign_info.options[country.lower()][0]
|
|
|
|
embed.description = callsign_info.options[country.lower()][1]
|
|
|
|
embed.colour = cmn.colours.good
|
2019-11-28 23:48:11 -05:00
|
|
|
|
2019-12-16 03:49:34 -05:00
|
|
|
for name, val in callsign_info.options[country.lower()][2].items():
|
|
|
|
embed.add_field(name=name, value=val, inline=False)
|
2019-11-28 23:48:11 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2019-12-15 12:51:43 -05:00
|
|
|
@commands.command(name="contests", aliases=["cc", "tests"], category=cmn.cat.ref)
|
|
|
|
async def _contests(self, ctx: commands.Context):
|
2019-12-16 03:49:34 -05:00
|
|
|
embed = cmn.embed_factory(ctx)
|
|
|
|
embed.title = "Contest Calendar"
|
2019-12-15 12:51:43 -05:00
|
|
|
embed.description = ("*We are currently rewriting the old, Chrome-based `contests` command. In the meantime, "
|
|
|
|
"use [the website](https://www.contestcalendar.com/weeklycont.php).*")
|
2019-12-16 03:49:34 -05:00
|
|
|
embed.colour = cmn.colours.good
|
2019-12-15 12:51:43 -05:00
|
|
|
await ctx.send(embed=embed)
|
|
|
|
|
2019-10-05 19:36:45 -04:00
|
|
|
|
2019-10-18 08:27:05 -04:00
|
|
|
def setup(bot: commands.Bot):
|
2019-10-05 19:36:45 -04:00
|
|
|
bot.add_cog(HamCog(bot))
|