diff options
author | 2019-03-05 18:05:45 +0100 | |
---|---|---|
committer | 2019-03-05 18:05:45 +0100 | |
commit | 61346933195f96a5e13ef147fb85f8fa4a1182ef (patch) | |
tree | 30e374eec811f722026770fa0789133ab95cd06a | |
parent | Update myvalenstate.py to address requested changes (diff) |
Fix myvalenstate
A bug appeared, that, if a user were to have only one or two Valenstates,
would throw an IndexError, thus blocking the command to run at its fullest.
This commit aims at fixing this bug by refining how the leftovers are handled:
Before there was only one line determining the leftover string, that was
than put into the embed's add_field method with some extra stuff around
it and a fixed title.
This has now been changed to having a variable title changing with the
length of the matches list. For example if you have 3 original matches,
the matches list would be of length 2, thus the original title is displayed.
If you have only 2 or just 1 match however, the matches list would be of
length 1 or 0, each of which feature their own title and text now.
Some style changes have been made as well: the add_field and set_image
methods are now one liners.
-rw-r--r-- | bot/seasons/valentines/myvalenstate.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/bot/seasons/valentines/myvalenstate.py b/bot/seasons/valentines/myvalenstate.py index 1fd6916a..9f06553d 100644 --- a/bot/seasons/valentines/myvalenstate.py +++ b/bot/seasons/valentines/myvalenstate.py @@ -56,22 +56,27 @@ class MyValenstate: matches = [x for x, y in eq_chars.items() if y == min(eq_chars.values())] valenstate = choice(matches) matches.remove(valenstate) - leftovers = f"{', '.join(matches[:len(matches)-2])}, and {matches[len(matches)-1]}" + + embed_title = "But there are more!" + if len(matches) > 1: + leftovers = f"{', '.join(matches[:len(matches)-2])}, and {matches[len(matches)-1]}" + embed_text = f"You have {len(matches)} more matches, these being {leftovers}." + elif len(matches) == 1: + embed_title = "But there's another one!" + leftovers = str(matches) + embed_text = f"You have another match, this being {leftovers}." + else: + embed_title = "You have a true match!" + embed_text = "This state is your true Valenstate! There are no states that would suit" \ + " you better" embed = discord.Embed( title=f'Your Valenstate is {valenstate} \u2764', description=f'{STATES[valenstate]["text"]}', colour=Colours.pink ) - - if len(matches) > 1: - embed.add_field( - name="But there are more!", - value=f"You have {len(matches)} more matches, these being {leftovers}." - ) - embed.set_image( - url=STATES[valenstate]["flag"] - ) + embed.add_field(name=embed_title, value=embed_text) + embed.set_image(url=STATES[valenstate]["flag"]) await ctx.channel.send(embed=embed) |