add calculator help

This commit is contained in:
xeals 2023-04-27 11:31:39 +10:00
parent fa96d88964
commit 3a315a0a28
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C

12
bot.py
View File

@ -72,7 +72,9 @@ class BotClient(discord.Client):
return message.content.startswith("%")
async def on_command(self, message: discord.Message):
match message.content.split(" "):
match re.split(" +", message.content):
case ["%calc?"], ["%calc", "?"]:
await message.reply(content=self._help_calculate())
case ["%calc", *args]:
try:
calc = await self._calculate(args)
@ -85,6 +87,14 @@ class BotClient(discord.Client):
case _:
_log.info(f"Unrecognised command {command}")
async def _help_calculate(self) -> str:
return """
Run Showdown damage calculations.
Example format:
` -2 8 SpA Choice Specs Torkoal Overheat vs. 252 HP / 4+ SpD Assault Vest Abomasnow in Sun through Light Screen`
Supported: attacker/defender boosts, EVs, item, species; attacker ability; weather/terrain; screens.
"""
async def _calculate(self, args: list[str]) -> str:
proc = sp.run(
["node", "calc_main.js", "--"] + args, stdout=sp.PIPE, stderr=sp.PIPE