Compare commits

..

No commits in common. "3a315a0a28ced9dec16282ca931328052f537e4e" and "cf3906be94d9c7ca5115d9f83ee82ae2285db7d5" have entirely different histories.

14
bot.py
View File

@ -72,9 +72,7 @@ class BotClient(discord.Client):
return message.content.startswith("%") return message.content.startswith("%")
async def on_command(self, message: discord.Message): async def on_command(self, message: discord.Message):
match re.split(" +", message.content): match message.content.split(" "):
case ["%calc?"], ["%calc", "?"]:
await message.reply(content=self._help_calculate())
case ["%calc", *args]: case ["%calc", *args]:
try: try:
calc = await self._calculate(args) calc = await self._calculate(args)
@ -82,19 +80,11 @@ class BotClient(discord.Client):
except Exception as e: except Exception as e:
_log.exception("running calculation") _log.exception("running calculation")
await message.reply( await message.reply(
content="```\n" + str(e) + "\n```", delete_after=10 content="```\n" + str(e) + "\n```", delete_after=30
) )
case _: case _:
_log.info(f"Unrecognised command {command}") _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: async def _calculate(self, args: list[str]) -> str:
proc = sp.run( proc = sp.run(
["node", "calc_main.js", "--"] + args, stdout=sp.PIPE, stderr=sp.PIPE ["node", "calc_main.js", "--"] + args, stdout=sp.PIPE, stderr=sp.PIPE