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:
|
for name in card_names:
|
||||||
name = re.sub(r'<.*?>', '', name).strip()
|
name = re.sub(r'<.*?>', '', name).strip()
|
||||||
|
|
||||||
# Handle set codes
|
# Handle set codes and collector numbers
|
||||||
if '|' in name:
|
name, set_code, collector_num, *_ = (name.split('|') + ['']*2)
|
||||||
name, set_code, *_ = name.split('|')
|
|
||||||
else:
|
|
||||||
set_code = ''
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Check if any of the easter eggs should happen
|
# Check if any of the easter eggs should happen
|
||||||
|
@ -198,10 +195,26 @@ async def get_cards(card_names):
|
||||||
else:
|
else:
|
||||||
c = scrython.cards.Named(fuzzy=name, set=set_code)
|
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)
|
cards.append(c)
|
||||||
responses.append(f'{c.name()} - {c.scryfall_uri()}')
|
responses.append(f'{c.name()} - {c.scryfall_uri()}')
|
||||||
except scrython.foundation.ScryfallError:
|
except scrython.foundation.ScryfallError as e:
|
||||||
if set_code:
|
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.')
|
responses.append(f'No card named "{name}" from set with code {set_code.upper()} was found.')
|
||||||
else:
|
else:
|
||||||
responses.append(f'No card named "{name}" was found.')
|
responses.append(f'No card named "{name}" was found.')
|
||||||
|
|
Loading…
Reference in New Issue