From 6443f7b849ef8a8d91728cc82bc42b9adde25c01 Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 17 Dec 2021 20:44:58 +0000 Subject: [PATCH] Refactor easter eggs into a separate file --- easter_eggs.py | 14 ++++++++++++++ mtgcardlookup.py | 11 +++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 easter_eggs.py diff --git a/easter_eggs.py b/easter_eggs.py new file mode 100644 index 0000000..a701698 --- /dev/null +++ b/easter_eggs.py @@ -0,0 +1,14 @@ +# List of easter eggs +# If the function retuns True on the supplied name, operate on the card name here instead of the supplied one + +longest_card_elemental = ''' +Our Market Research Shows That +Players Like Really Long Card +Names So We Made this Card to Have +the Absolute Longest Card Name Ever +Elemental'''.strip().replace('\n', ' ') + +eggs = [ + (lambda s: len(s) > 141, longest_card_elemental), + (lambda s: not s, '______'), +] \ No newline at end of file diff --git a/mtgcardlookup.py b/mtgcardlookup.py index a123a68..b39b33f 100755 --- a/mtgcardlookup.py +++ b/mtgcardlookup.py @@ -21,6 +21,7 @@ nest_asyncio.apply() # It has something to do with Scrython using asyncio, which # I'm sorry, it's completely beyond me. Look it up. import face +from easter_eggs import eggs from debug import * @@ -121,12 +122,14 @@ async def get_cards(card_names): set_code = '' try: - if len(name) > 141: - c = scrython.cards.Named(fuzzy='Our Market Research Shows That Players Like Really Long Card Names So We Made this Card to Have the Absolute Longest Card Name Ever Elemental') - elif len(name) == 0: - c = scrython.cards.Named(fuzzy='_____') + # Check if any of the easter eggs should happen + for func, replacement in eggs: + if func(name): + c = scrython.cards.Named(fuzzy=replacement) + break else: c = scrython.cards.Named(fuzzy=name, set=set_code) + cards.append(c) responses.append(f'{c.name()} - {c.scryfall_uri()}') except scrython.foundation.ScryfallError: