mirror of
https://github.com/miaowware/qrm2.git
synced 2024-10-31 14:27:11 -04:00
add phonetic weight command (#215)
Fixes #170 Co-authored-by: 0x5c <dev@0x5c.io>
This commit is contained in:
parent
bc93462c29
commit
2cb4b03532
@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
|
- `?phoneticweight` command, which calculates a message's length in syllables.
|
||||||
- `?standards` command to display [xkcd 927](https://xkcd.com/927/).
|
- `?standards` command to display [xkcd 927](https://xkcd.com/927/).
|
||||||
### Changed
|
### Changed
|
||||||
- Python>=3.7 now required.
|
- Python>=3.7 now required.
|
||||||
|
20
exts/ham.py
20
exts/ham.py
@ -92,6 +92,26 @@ class HamCog(commands.Cog):
|
|||||||
embed.colour = cmn.colours.good
|
embed.colour = cmn.colours.good
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
@commands.command(name="phoneticweight", aliases=["pw"], category=cmn.cat.ref)
|
||||||
|
async def _weight(self, ctx: commands.Context, *, msg: str):
|
||||||
|
"""Calculates the phonetic weight of a callsign or message."""
|
||||||
|
embed = cmn.embed_factory(ctx)
|
||||||
|
msg = msg.upper()
|
||||||
|
weight = 0
|
||||||
|
for char in msg:
|
||||||
|
try:
|
||||||
|
weight += phonetics.pweights[char]
|
||||||
|
except KeyError:
|
||||||
|
embed.title = "Error in calculation of phonetic weight"
|
||||||
|
embed.description = f"Unknown character `{char}` in message"
|
||||||
|
embed.colour = cmn.colours.bad
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
return
|
||||||
|
embed.title = f"Phonetic Weight of {msg}"
|
||||||
|
embed.description = f"The phonetic weight is **{weight}**"
|
||||||
|
embed.colour = cmn.colours.good
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
|
|
||||||
def setup(bot: commands.Bot):
|
def setup(bot: commands.Bot):
|
||||||
bot.add_cog(HamCog(bot))
|
bot.add_cog(HamCog(bot))
|
||||||
|
@ -36,3 +36,43 @@ phonetics = {
|
|||||||
"y": "yankee",
|
"y": "yankee",
|
||||||
"z": "zulu"
|
"z": "zulu"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pweights = {
|
||||||
|
"A": 2,
|
||||||
|
"B": 2,
|
||||||
|
"C": 2,
|
||||||
|
"D": 2,
|
||||||
|
"E": 2,
|
||||||
|
"F": 2,
|
||||||
|
"G": 1,
|
||||||
|
"H": 2,
|
||||||
|
"I": 3,
|
||||||
|
"J": 3,
|
||||||
|
"K": 2,
|
||||||
|
"L": 2,
|
||||||
|
"M": 1,
|
||||||
|
"N": 3,
|
||||||
|
"O": 2,
|
||||||
|
"P": 2,
|
||||||
|
"Q": 2,
|
||||||
|
"R": 3,
|
||||||
|
"S": 3,
|
||||||
|
"T": 2,
|
||||||
|
"U": 3,
|
||||||
|
"V": 2,
|
||||||
|
"W": 2,
|
||||||
|
"X": 2,
|
||||||
|
"Y": 2,
|
||||||
|
"Z": 2,
|
||||||
|
"0": 2,
|
||||||
|
"1": 1,
|
||||||
|
"2": 1,
|
||||||
|
"3": 1,
|
||||||
|
"4": 1,
|
||||||
|
"5": 1,
|
||||||
|
"6": 1,
|
||||||
|
"7": 2,
|
||||||
|
"8": 1,
|
||||||
|
"9": 2,
|
||||||
|
"/": 1,
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user