diff options
| author | 2019-02-21 11:28:02 +0530 | |
|---|---|---|
| committer | 2019-02-21 11:28:02 +0530 | |
| commit | 1eb90872d23f040ba246ae07986d4ba1fde17384 (patch) | |
| tree | 7cab5606916c6fffa5db103fe999fe21c6ae2352 /bot | |
| parent | Wrote the command as described in the issue #107 (diff) | |
Made the try catch block narrow and only catching KeyErrors
Diffstat (limited to 'bot')
| -rw-r--r-- | bot/seasons/valentines/valentine_zodiac.py | 42 | 
1 files changed, 21 insertions, 21 deletions
| diff --git a/bot/seasons/valentines/valentine_zodiac.py b/bot/seasons/valentines/valentine_zodiac.py index 8f15255c..cdb4221f 100644 --- a/bot/seasons/valentines/valentine_zodiac.py +++ b/bot/seasons/valentines/valentine_zodiac.py @@ -26,28 +26,28 @@ class ValentineZodiac:          """          Provides a counter compatible zodiac sign to the given user's zodiac sign.          """ -        try: -            with open(Path('bot', 'resources', 'valentines', 'zodiac_compatibility.json'), 'r', encoding="utf8") as f: -                zodiacs = load(f) + +        with open(Path('bot', 'resources', 'valentines', 'zodiac_compatibility.json'), 'r', encoding="utf8") as f: +            zodiacs = load(f) + +            try:                  compatible_zodiac = random.choice(zodiacs[zodiac_sign.lower()]) -                emoji1 = random.choice(HEART_EMOJIS) -                emoji2 = random.choice(HEART_EMOJIS) -                embed = discord.Embed( -                    title="Zodic Compatibility", -                    description=f'{zodiac_sign.capitalize()}{emoji1}{compatible_zodiac["Zodiac"]}\n' -                                f'{emoji2}Compatibility meter : {compatible_zodiac["compatibility_score"]}{emoji2}', -                    color=Colours.pink -                ) -                embed.add_field( -                    name=f'A letter from Dr.Zodiac {LETTER_EMOJI}', -                    value=compatible_zodiac['description'] -                ) -                await ctx.send(embed=embed) -        except Exception as e: -            if isinstance(e, KeyError): -                await ctx.send(zodiac_sign.capitalize() + " zodiac sign does not exist.") -            else: -                raise e +            except KeyError: +                return await ctx.send(zodiac_sign.capitalize() + " zodiac sign does not exist.") + +            emoji1 = random.choice(HEART_EMOJIS) +            emoji2 = random.choice(HEART_EMOJIS) +            embed = discord.Embed( +                title="Zodic Compatibility", +                description=f'{zodiac_sign.capitalize()}{emoji1}{compatible_zodiac["Zodiac"]}\n' +                            f'{emoji2}Compatibility meter : {compatible_zodiac["compatibility_score"]}{emoji2}', +                color=Colours.pink +            ) +            embed.add_field( +                name=f'A letter from Dr.Zodiac {LETTER_EMOJI}', +                value=compatible_zodiac['description'] +            ) +            await ctx.send(embed=embed)  def setup(bot): | 
