allow looking up cards with their collector number
This commit is contained in:
parent
f88fab0431
commit
f6335528f5
|
@ -183,11 +183,8 @@ async def get_cards(card_names):
|
|||
for name in card_names:
|
||||
name = re.sub(r'<.*?>', '', name).strip()
|
||||
|
||||
# Handle set codes
|
||||
if '|' in name:
|
||||
name, set_code, *_ = name.split('|')
|
||||
else:
|
||||
set_code = ''
|
||||
# Handle set codes and collector numbers
|
||||
name, set_code, collector_num, *_ = (name.split('|') + ['']*2)
|
||||
|
||||
try:
|
||||
# Check if any of the easter eggs should happen
|
||||
|
@ -198,10 +195,26 @@ async def get_cards(card_names):
|
|||
else:
|
||||
c = scrython.cards.Named(fuzzy=name, set=set_code)
|
||||
|
||||
if collector_num:
|
||||
c_by_num = scrython.cards.Collector(
|
||||
code=set_code,
|
||||
collector_number=collector_num,
|
||||
)
|
||||
# Make sure the provided name matches
|
||||
if c_by_num.name() != c.name():
|
||||
raise scrython.foundation.ScryfallError
|
||||
|
||||
c = c_by_num
|
||||
|
||||
cards.append(c)
|
||||
responses.append(f'{c.name()} - {c.scryfall_uri()}')
|
||||
except scrython.foundation.ScryfallError:
|
||||
if set_code:
|
||||
except scrython.foundation.ScryfallError as e:
|
||||
if collector_num:
|
||||
responses.append(
|
||||
f'No card named "{name}" from set with code '
|
||||
f'{set_code.upper()} and collector number {collector_num} '
|
||||
'was found.')
|
||||
elif set_code:
|
||||
responses.append(f'No card named "{name}" from set with code {set_code.upper()} was found.')
|
||||
else:
|
||||
responses.append(f'No card named "{name}" was found.')
|
||||
|
|
Loading…
Reference in New Issue