Compare commits

...

2 Commits

Author SHA1 Message Date
3a315a0a28
add calculator help 2023-04-27 11:31:39 +10:00
fa96d88964
auto-delete errors faster 2023-04-27 11:26:03 +10:00

14
bot.py
View File

@ -72,7 +72,9 @@ 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 message.content.split(" "): match re.split(" +", message.content):
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)
@ -80,11 +82,19 @@ 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=30 content="```\n" + str(e) + "\n```", delete_after=10
) )
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