checked the string in pep command is a number, and escape input

This commit is contained in:
Hayden Young 2019-11-16 22:19:36 +00:00
parent 0e68e0efe7
commit 86a2049807
1 changed files with 11 additions and 3 deletions

14
bot.py
View File

@ -297,11 +297,19 @@ def cmd_uptime(match: Match[str]) -> Response:
@handle_message('!pep') @handle_message('!pep')
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 = esc(rest.zfill(4))
if not pep.isdigit():
return MessageResponse( return MessageResponse(
match, match,
f'https://www.python.org/dev/peps/pep-{rest.zfill(4)}/', 'Please make sure you gave me a number!',
)
return MessageResponse(
match,
f'https://www.python.org/dev/peps/pep-{pep}/',
) )