Nicer pep number matching and extraction
Covers the following cases: !pep 1234 test !pep 1234test !pep1234 test !pep1245test !pep test !pep
This commit is contained in:
parent
c89740f1f2
commit
b8e368b94e
16
bot.py
16
bot.py
|
|
@ -295,18 +295,12 @@ def cmd_uptime(match: Match[str]) -> Response:
|
||||||
return UptimeResponse()
|
return UptimeResponse()
|
||||||
|
|
||||||
|
|
||||||
@handle_message('!pep')
|
@handle_message('!pep[ ]?(?P<pep_num>\d{1,4})')
|
||||||
def cmd_pep(match: Match[str]) -> Response:
|
def cmd_pep(match: Match[str]) -> Response:
|
||||||
*_, msg = match.groups()
|
*_, number = match.groups()
|
||||||
*_, rest = msg.partition(' ')
|
return MessageResponse(
|
||||||
try:
|
match, f'https://www.python.org/dev/peps/pep-{number.zfill(4)}/',
|
||||||
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}/',
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
COMMAND_RE = re.compile(r'!\w+')
|
COMMAND_RE = re.compile(r'!\w+')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue