fix parse and reply

This commit is contained in:
xeals 2023-04-26 17:14:42 +10:00
parent 648deb83db
commit 699a833285
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C
3 changed files with 7 additions and 7 deletions

2
bot.js
View File

@ -1,2 +0,0 @@
import calc from "./calc";

10
bot.py
View File

@ -75,16 +75,18 @@ class BotClient(discord.Client):
match message.content.split(" "): match message.content.split(" "):
case ["%calc", *args]: case ["%calc", *args]:
reply = await self._calculate(args) reply = await self._calculate(args)
await message.reply(content=reply) if reply:
await message.reply(content=reply.strip())
case _: case _:
_log.info(f"Unrecognised command {command}") _log.info(f"Unrecognised command {command}")
async def _calculate(self, args: list[str]) -> str: 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: if proc.returncode != 0:
_log.error(f"running calculator: {proc.stderr}") _log.error(f"running calculator: {proc.stderr}")
msg = proc.stdout or "" return proc.stdout
return msg.strip()
def is_replay(self, message: discord.Message) -> bool: def is_replay(self, message: discord.Message) -> bool:
if re.match("https://replay.pokemonshowdown.com/dl-.*", message.content): if re.match("https://replay.pokemonshowdown.com/dl-.*", message.content):

View File

@ -55,7 +55,7 @@ function buildLexer() {
}); });
const vs = chev.createToken({ const vs = chev.createToken({
name: "vs", name: "vs",
pattern: "vs.", pattern: /vs\.?/,
}); });
const terrainEnter = chev.createToken({ const terrainEnter = chev.createToken({