From 699a833285e4e0aad0d718e77d7148e22e83b376 Mon Sep 17 00:00:00 2001 From: xeals Date: Wed, 26 Apr 2023 17:14:42 +1000 Subject: [PATCH] fix parse and reply --- bot.js | 2 -- bot.py | 10 ++++++---- calc.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 bot.js diff --git a/bot.js b/bot.js deleted file mode 100644 index 894c505..0000000 --- a/bot.js +++ /dev/null @@ -1,2 +0,0 @@ -import calc from "./calc"; - diff --git a/bot.py b/bot.py index 0ae9000..6f84e52 100755 --- a/bot.py +++ b/bot.py @@ -75,16 +75,18 @@ class BotClient(discord.Client): match message.content.split(" "): case ["%calc", *args]: reply = await self._calculate(args) - await message.reply(content=reply) + if reply: + await message.reply(content=reply.strip()) case _: _log.info(f"Unrecognised command {command}") async def _calculate(self, args: list[str]) -> str: - proc = sp.run(["node", "calc_main.js", "--"] + args) + proc = sp.run( + ["node", "calc_main.js", "--"] + args, stdout=sp.PIPE, stderr=sp.PIPE + ) if proc.returncode != 0: _log.error(f"running calculator: {proc.stderr}") - msg = proc.stdout or "" - return msg.strip() + return proc.stdout def is_replay(self, message: discord.Message) -> bool: if re.match("https://replay.pokemonshowdown.com/dl-.*", message.content): diff --git a/calc.js b/calc.js index c481fc5..de889d3 100644 --- a/calc.js +++ b/calc.js @@ -55,7 +55,7 @@ function buildLexer() { }); const vs = chev.createToken({ name: "vs", - pattern: "vs.", + pattern: /vs\.?/, }); const terrainEnter = chev.createToken({