From 5d2c6489c3225d2abc1f50ec644645f47f0e7cd5 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 16 Nov 2019 14:28:54 -0800 Subject: [PATCH] Improve pep check to use ascii integers --- bot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot.py b/bot.py index 4786aa9..9249387 100644 --- a/bot.py +++ b/bot.py @@ -299,13 +299,13 @@ def cmd_uptime(match: Match[str]) -> Response: def cmd_pep(match: Match[str]) -> Response: *_, msg = match.groups() *_, rest = msg.partition(' ') - pep = rest.strip() - - if not pep.isdigit() or len(pep) > 4: + try: + pep = str(int(rest)).zfill(4) + except ValueError: return MessageResponse(match, 'Please make sure you gave me a number!') else: return MessageResponse( - match, f'https://www.python.org/dev/peps/pep-{pep.zfill(4)}/', + match, f'https://www.python.org/dev/peps/pep-{pep}/', )