Merge pull request #18 from int3l/master

Nicer pep number matching and extraction
This commit is contained in:
Anthony Sottile 2019-11-23 15:43:15 -08:00 committed by GitHub
commit 7481955842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 11 deletions

12
bot.py
View File

@ -295,17 +295,11 @@ def cmd_uptime(match: Match[str]) -> Response:
return UptimeResponse() return UptimeResponse()
@handle_message('!pep') @handle_message(r'!pep[ ]?(?P<pep_num>\d{1,4})', flags=re.ASCII)
def cmd_pep(match: Match[str]) -> Response: def cmd_pep(match: Match[str]) -> Response:
*_, msg = match.groups() *_, number = match.groups()
*_, rest = msg.partition(' ')
try:
pep = str(int(rest)).zfill(4)
except ValueError:
return MessageResponse(match, 'Please make sure you gave me a number!')
else:
return MessageResponse( return MessageResponse(
match, f'https://www.python.org/dev/peps/pep-{pep}/', match, f'https://www.python.org/dev/peps/pep-{number.zfill(4)}/',
) )