Merge pull request #18 from int3l/master
Nicer pep number matching and extraction
This commit is contained in:
commit
7481955842
16
bot.py
16
bot.py
|
|
@ -295,18 +295,12 @@ def cmd_uptime(match: Match[str]) -> Response:
|
|||
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:
|
||||
*_, msg = 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(
|
||||
match, f'https://www.python.org/dev/peps/pep-{pep}/',
|
||||
)
|
||||
*_, number = match.groups()
|
||||
return MessageResponse(
|
||||
match, f'https://www.python.org/dev/peps/pep-{number.zfill(4)}/',
|
||||
)
|
||||
|
||||
|
||||
COMMAND_RE = re.compile(r'!\w+')
|
||||
|
|
|
|||
Loading…
Reference in New Issue