Improve pep check to use ascii integers

This commit is contained in:
Anthony Sottile 2019-11-16 14:28:54 -08:00
parent 885872db0d
commit 5d2c6489c3
1 changed files with 4 additions and 4 deletions

8
bot.py
View File

@ -299,13 +299,13 @@ def cmd_uptime(match: Match[str]) -> Response:
def cmd_pep(match: Match[str]) -> Response: def cmd_pep(match: Match[str]) -> Response:
*_, msg = match.groups() *_, msg = match.groups()
*_, rest = msg.partition(' ') *_, rest = msg.partition(' ')
pep = rest.strip() try:
pep = str(int(rest)).zfill(4)
if not pep.isdigit() or len(pep) > 4: except ValueError:
return MessageResponse(match, 'Please make sure you gave me a number!') return MessageResponse(match, 'Please make sure you gave me a number!')
else: else:
return MessageResponse( return MessageResponse(
match, f'https://www.python.org/dev/peps/pep-{pep.zfill(4)}/', match, f'https://www.python.org/dev/peps/pep-{pep}/',
) )