From 8c3b8d8d270026591053cbf3a31013dd8e69080e Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 16:12:01 -0500 Subject: Update static files for new code functionality --- bot/constants.py | 2 +- bot/resources/advent_of_code/about.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/constants.py b/bot/constants.py index b57eb714..917b82af 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -15,7 +15,7 @@ log = logging.getLogger(__name__) class AdventOfCode: leaderboard_cache_age_threshold_seconds = 3600 leaderboard_id = 363275 - leaderboard_join_code = "363275-442b6939" + leaderboard_join_code = str(environ.get("AOC_JOIN_CODE", None)) leaderboard_max_displayed_members = 10 year = 2018 channel_id = int(environ.get("AOC_CHANNEL_ID", 517745814039166986)) diff --git a/bot/resources/advent_of_code/about.json b/bot/resources/advent_of_code/about.json index 3fe6fcc9..4abf9145 100644 --- a/bot/resources/advent_of_code/about.json +++ b/bot/resources/advent_of_code/about.json @@ -21,7 +21,7 @@ }, { "name": "Join our private leaderboard!", - "value": "In addition to the global leaderboard, AoC also offers private leaderboards, where you can compete against a smaller group of friends!\n\nHead over to AoC's [private leaderboard page](https://adventofcode.com/leaderboard/private) and enter code `363275-442b6939` to join the PyDis private leaderboard!", + "value": "In addition to the global leaderboard, AoC also offers private leaderboards, where you can compete against a smaller group of friends!\n\nGet the join code using `.aoc join` and head over to AoC's [private leaderboard page](https://adventofcode.com/leaderboard/private) to join the PyDis private leaderboard!", "inline": false } ] \ No newline at end of file -- cgit v1.2.3 From 0de62cc2ba50b2cef6e998cc797aaba1685d50b1 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 16:46:06 -0500 Subject: Refactor aoc join to DM user with join code --- bot/seasons/christmas/adventofcode.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 458eb19f..b61e77c0 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -19,6 +19,7 @@ log = logging.getLogger(__name__) AOC_REQUEST_HEADER = {"user-agent": "PythonDiscord AoC Event Bot"} AOC_SESSION_COOKIE = {"session": Tokens.aoc_session_cookie} +AOC_JOIN_CODE = AocConfig.leaderboard_join_code # Constant so staff can update without redeploying EST = timezone("EST") COUNTDOWN_STEP = 60 * 5 @@ -196,14 +197,23 @@ class AdventOfCode: @adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join PyDis' private AoC leaderboard") async def join_leaderboard(self, ctx: commands.Context): """ - Retrieve the link to join the PyDis AoC private leaderboard + DM the user the information for joining the PyDis AoC private leaderboard """ + author = ctx.message.author + log.info(f"{author.name} ({author.id}) has requested the PyDis AoC leaderboard code") + info_str = ( "Head over to https://adventofcode.com/leaderboard/private " - f"with code `{AocConfig.leaderboard_join_code}` to join the PyDis private leaderboard!" + f"with code `{AOC_JOIN_CODE}` to join the PyDis private leaderboard!" ) - await ctx.send(info_str) + try: + await author.send(info_str) + except discord.errors.Forbidden: + log.debug(f"{author.name} ({author.id}) has disabled DMs from server members") + await ctx.send( + f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' + ) @adventofcode_group.command( name="leaderboard", -- cgit v1.2.3 From acde36e17e0a3365f5db7357d76b5a9c8ddc0ff2 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 17:30:01 -0500 Subject: Add staff command to change AoC leaderboard join code --- bot/seasons/christmas/adventofcode.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index b61e77c0..0d4fd966 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -13,7 +13,8 @@ from bs4 import BeautifulSoup from discord.ext import commands from pytz import timezone -from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Tokens +from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Roles, Tokens +from bot.decorators import with_role log = logging.getLogger(__name__) @@ -215,6 +216,20 @@ class AdventOfCode: f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' ) + @with_role(Roles.admin, Roles.owner) + @adventofcode_group.command(name="changecode", hidden=True) + async def update_aoc_join_code(self, ctx: commands.Context, new_code: str): + """ + Staff command to update the AoC join code constant locally to allow for the code to be updated + on regeneration without having to redeploy the bot + """ + + author = ctx.message.author + log.info(f"{author.name} ({author.id}) has changed the PyDis AoC leaderboard code") + + global AOC_JOIN_CODE # Necessary (probably?) evil to update the code without redeploying + AOC_JOIN_CODE = new_code + @adventofcode_group.command( name="leaderboard", aliases=("board", "lb"), -- cgit v1.2.3 From ebe67c3b469a52a1f4b4bcb2a6c2f231c30cfdd1 Mon Sep 17 00:00:00 2001 From: sco1 Date: Mon, 10 Dec 2018 17:34:38 -0500 Subject: Remove extraneous whitespace --- bot/seasons/christmas/adventofcode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 0d4fd966..056c36ab 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -223,7 +223,7 @@ class AdventOfCode: Staff command to update the AoC join code constant locally to allow for the code to be updated on regeneration without having to redeploy the bot """ - + author = ctx.message.author log.info(f"{author.name} ({author.id}) has changed the PyDis AoC leaderboard code") -- cgit v1.2.3 From 191d8abceabff5b442cf1e0ce0aa5fe238520341 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 26 Dec 2018 10:00:08 -0500 Subject: Remove local env var modification command --- bot/seasons/christmas/adventofcode.py | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 056c36ab..113f959d 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -20,7 +20,6 @@ log = logging.getLogger(__name__) AOC_REQUEST_HEADER = {"user-agent": "PythonDiscord AoC Event Bot"} AOC_SESSION_COOKIE = {"session": Tokens.aoc_session_cookie} -AOC_JOIN_CODE = AocConfig.leaderboard_join_code # Constant so staff can update without redeploying EST = timezone("EST") COUNTDOWN_STEP = 60 * 5 @@ -206,7 +205,7 @@ class AdventOfCode: info_str = ( "Head over to https://adventofcode.com/leaderboard/private " - f"with code `{AOC_JOIN_CODE}` to join the PyDis private leaderboard!" + f"with code `{AocConfig.leaderboard_join_code}` to join the PyDis private leaderboard!" ) try: await author.send(info_str) @@ -216,20 +215,6 @@ class AdventOfCode: f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' ) - @with_role(Roles.admin, Roles.owner) - @adventofcode_group.command(name="changecode", hidden=True) - async def update_aoc_join_code(self, ctx: commands.Context, new_code: str): - """ - Staff command to update the AoC join code constant locally to allow for the code to be updated - on regeneration without having to redeploy the bot - """ - - author = ctx.message.author - log.info(f"{author.name} ({author.id}) has changed the PyDis AoC leaderboard code") - - global AOC_JOIN_CODE # Necessary (probably?) evil to update the code without redeploying - AOC_JOIN_CODE = new_code - @adventofcode_group.command( name="leaderboard", aliases=("board", "lb"), -- cgit v1.2.3 From 01470fc31cd429164a7c314f01fb5b3c81f600d2 Mon Sep 17 00:00:00 2001 From: sco1 Date: Wed, 26 Dec 2018 10:01:30 -0500 Subject: Remove unused imports --- bot/seasons/christmas/adventofcode.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index 113f959d..e9853222 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -13,8 +13,7 @@ from bs4 import BeautifulSoup from discord.ext import commands from pytz import timezone -from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Roles, Tokens -from bot.decorators import with_role +from bot.constants import AdventOfCode as AocConfig, Colours, Emojis, Tokens log = logging.getLogger(__name__) -- cgit v1.2.3 From 00dbe8b2cb64991102be0e242d3e54175d207814 Mon Sep 17 00:00:00 2001 From: sco1 Date: Sat, 5 Jan 2019 14:09:12 -0500 Subject: Review-directed reformatting --- bot/seasons/christmas/adventofcode.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/seasons/christmas/adventofcode.py b/bot/seasons/christmas/adventofcode.py index e9853222..f0e4f0da 100644 --- a/bot/seasons/christmas/adventofcode.py +++ b/bot/seasons/christmas/adventofcode.py @@ -210,9 +210,7 @@ class AdventOfCode: await author.send(info_str) except discord.errors.Forbidden: log.debug(f"{author.name} ({author.id}) has disabled DMs from server members") - await ctx.send( - f':x: {author.mention}, please (temporarily) enable DMs to receive the join code' - ) + await ctx.send(f":x: {author.mention}, please (temporarily) enable DMs to receive the join code") @adventofcode_group.command( name="leaderboard", -- cgit v1.2.3 From 59b2546e85d33a31393d12ab3fcbe03a51b23b12 Mon Sep 17 00:00:00 2001 From: Darth Delay Date: Thu, 28 Feb 2019 12:26:38 +0100 Subject: Add .myvalenstate Closes #108 This pull request adds a beta version of the command myvalenstate. This command sends an embed containing a users valenstate to the channel it has been called in. The process used here is to first put the username into a spaceless, lower case form and than compare it to the countries listed under valenstates.json, put into the same form, using an implementation of the Levenshtein algorithm. This beta version already implements everything needed for the command to work properly. The follwing things are missing, not meant for the future full implementation or are subject to change if needed: - Short comments (25 missing) - name parameter in myvalenstate (not meant for staying/Debug) - Object names in valenstates.json (subject to change) (1) - Docstring for levenshtein (subject to change) - Docstring for myvalenstate (subject to change) (1) - The object names can be put into the right case to omit the operation operation on line 54 (lower_state = state.lower().replace(' ', '')) --- bot/resources/valentines/valenstates.json | 122 ++++++++++++++++++++++++++++++ bot/seasons/valentines/myvalenstate.py | 80 ++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 bot/resources/valentines/valenstates.json create mode 100644 bot/seasons/valentines/myvalenstate.py (limited to 'bot') diff --git a/bot/resources/valentines/valenstates.json b/bot/resources/valentines/valenstates.json new file mode 100644 index 00000000..06cbb2e5 --- /dev/null +++ b/bot/resources/valentines/valenstates.json @@ -0,0 +1,122 @@ +{ + "Australia": { + "text": "Australia is the oldest, flattest and driest inhabited continent on earth. It is one of the 18 megadiverse countries, featuring a wide variety of plants and animals, the most iconic ones being the koalas and kangaroos, as well as its deadly wildlife and trees falling under the Eucalyptus genus.", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Flag_of_Australia_%28converted%29.svg/1920px-Flag_of_Australia_%28converted%29.svg.png" + }, + "Austria": { + "text": "Austria is part of the european continent, lying in the alps. Due to its location, Austria possesses a variety of very tall mountains like the Großglockner (3798 m) or the Wildspitze (3772 m).", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/41/Flag_of_Austria.svg/1920px-Flag_of_Austria.svg.png" + }, + "Brazil": { + "text": "Being the largest and most populated country in South and Latin America, Brazil, as one of the 18 megadiverse countries, features a wide variety of plants and animals, especially in the Amazon rainforest, the most biodiverse rainforest in the world.", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/0/05/Flag_of_Brazil.svg/1280px-Flag_of_Brazil.svg.png" + }, + "Canada": { + "text": "Canada is the second-largest country in the world measured by total area, only surpassed by Russia. It's widely known for its astonishing national parks.", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Flag_of_Canada_%28Pantone%29.svg/1920px-Flag_of_Canada_%28Pantone%29.svg.png" + }, + "Croatia": { + "text": "Croatia is a country at the crossroads of Central and Southeast Europe, mostly known for its beautiful beaches and waters.", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Flag_of_Croatia.svg/1920px-Flag_of_Croatia.svg.png" + }, + "England": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/b/be/Flag_of_England.svg/1920px-Flag_of_England.svg.png" + }, + "Finland": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Flag_of_Finland.svg/1920px-Flag_of_Finland.svg.png" + }, + "France": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/c/c3/Flag_of_France.svg/1920px-Flag_of_France.svg.png" + }, + "Germany": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/Flag_of_Germany.svg/1920px-Flag_of_Germany.svg.png" + }, + "Greece": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Flag_of_Greece.svg/1920px-Flag_of_Greece.svg.png" + }, + "Iceland": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Flag_of_Iceland.svg/1280px-Flag_of_Iceland.svg.png" + }, + "India": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/4/41/Flag_of_India.svg/1920px-Flag_of_India.svg.png" + }, + "Indonesia": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/9/9f/Flag_of_Indonesia.svg/1920px-Flag_of_Indonesia.svg.png" + }, + "Ireland": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/45/Flag_of_Ireland.svg/1920px-Flag_of_Ireland.svg.png" + }, + "Italy": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/0/03/Flag_of_Italy.svg/1920px-Flag_of_Italy.svg.png" + }, + "Mexico": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Flag_of_Mexico.svg/1920px-Flag_of_Mexico.svg.png" + }, + "New Zealand": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Flag_of_New_Zealand.svg/1920px-Flag_of_New_Zealand.svg.png" + }, + "Norway": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Flag_of_Norway.svg/1280px-Flag_of_Norway.svg.png" + }, + "Peru": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/cf/Flag_of_Peru.svg/1920px-Flag_of_Peru.svg.png" + }, + "Portugal": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Flag_of_Portugal.svg/1920px-Flag_of_Portugal.svg.png" + }, + "Scotland": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/1/10/Flag_of_Scotland.svg/1920px-Flag_of_Scotland.svg.png" + }, + "Slovenia": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Flag_of_Slovenia.svg/1920px-Flag_of_Slovenia.svg.png" + }, + "South Africa": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Flag_of_South_Africa.svg/1920px-Flag_of_South_Africa.svg.png" + }, + "Spain": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/9/9a/Flag_of_Spain.svg/1920px-Flag_of_Spain.svg.png" + }, + "Sweden": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Flag_of_Sweden.svg/1920px-Flag_of_Sweden.svg.png" + }, + "Switzerland": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Flag_of_Switzerland_%28Pantone%29.svg/1024px-Flag_of_Switzerland_%28Pantone%29.svg.png" + }, + "Turkey": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/b4/Flag_of_Turkey.svg/1920px-Flag_of_Turkey.svg.png" + }, + "United States": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/en/thumb/a/a4/Flag_of_the_United_States.svg/1920px-Flag_of_the_United_States.svg.png" + }, + "Vietnam": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/21/Flag_of_Vietnam.svg/1920px-Flag_of_Vietnam.svg.png" + }, + "Wales": { + "text": "", + "flag": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Flag_of_Wales_%281959%E2%80%93present%29.svg/1920px-Flag_of_Wales_%281959%E2%80%93present%29.svg.png" + } +} \ No newline at end of file diff --git a/bot/seasons/valentines/myvalenstate.py b/bot/seasons/valentines/myvalenstate.py new file mode 100644 index 00000000..f646cbe4 --- /dev/null +++ b/bot/seasons/valentines/myvalenstate.py @@ -0,0 +1,80 @@ +import collections +import json +import logging +from pathlib import Path +from random import choice + +import discord +from discord.ext import commands + +from bot.constants import Colours + +log = logging.getLogger(__name__) + +with open(Path('bot', 'resources', 'valentines', 'valenstates.json'), 'r') as file: + STATES = json.load(file) + # STATES.sort() + + +class MyValenstate: + def __init__(self, bot): + self.bot = bot + + def levenshtein(self, source, goal): + """ + Calculates the Levenshtein Distance between source and goal. + """ + if len(source) < len(goal): + return self.levenshtein(goal, source) + if len(source) == 0: + return len(goal) + if len(goal) == 0: + return len(source) + + pre_row = list(range(0, len(source) + 1)) + for i, source_c in enumerate(source): + cur_row = [i + 1] + for j, goal_c in enumerate(goal): + if source_c != goal_c: + cur_row.append(min(pre_row[j], pre_row[j + 1], cur_row[j]) + 1) + else: + cur_row.append(min(pre_row[j], pre_row[j + 1], cur_row[j])) + pre_row = cur_row + return pre_row[-1] + + @commands.command() + async def myvalenstate(self, ctx, *, name=None): + eq_chars = collections.defaultdict(int) + if name is None: + author = ctx.message.author.name.lower().replace(' ', '') + else: + author = name.lower().replace(' ', '') + + for state in STATES.keys(): + lower_state = state.lower().replace(' ', '') + eq_chars[state] = self.levenshtein(author, lower_state) + + 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 = 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"] + ) + await ctx.channel.send(embed=embed) + + +def setup(bot): + bot.add_cog(MyValenstate(bot)) -- cgit v1.2.3 From 3a05c93aa3f1244a9a8513bab22de04e8521f15e Mon Sep 17 00:00:00 2001 From: Darth Delay Date: Tue, 5 Mar 2019 17:12:52 +0100 Subject: Update myvalenstate.py to address requested changes A few things have been changed: - The comment under STATES = json.load(file) was useless and has been removed - A logging statement has been put under the setup function: log.debug("MyValenstate cog loaded") --- bot/seasons/valentines/myvalenstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/valentines/myvalenstate.py b/bot/seasons/valentines/myvalenstate.py index f646cbe4..1fd6916a 100644 --- a/bot/seasons/valentines/myvalenstate.py +++ b/bot/seasons/valentines/myvalenstate.py @@ -13,7 +13,6 @@ log = logging.getLogger(__name__) with open(Path('bot', 'resources', 'valentines', 'valenstates.json'), 'r') as file: STATES = json.load(file) - # STATES.sort() class MyValenstate: @@ -78,3 +77,4 @@ class MyValenstate: def setup(bot): bot.add_cog(MyValenstate(bot)) + log.debug("MyValenstate cog loaded") -- cgit v1.2.3 From 61346933195f96a5e13ef147fb85f8fa4a1182ef Mon Sep 17 00:00:00 2001 From: Darth Delay Date: Tue, 5 Mar 2019 18:05:45 +0100 Subject: 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. --- bot/seasons/valentines/myvalenstate.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'bot') 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) -- cgit v1.2.3