fix parse and reply
This commit is contained in:
parent
648deb83db
commit
699a833285
10
bot.py
10
bot.py
@ -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):
|
||||||
|
Loading…
Reference in New Issue
Block a user