aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/valentines/myvalenstate.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/valentines/myvalenstate.py')
-rw-r--r--bot/exts/valentines/myvalenstate.py24
1 files changed, 11 insertions, 13 deletions
diff --git a/bot/exts/valentines/myvalenstate.py b/bot/exts/valentines/myvalenstate.py
index 01801847..1c67984b 100644
--- a/bot/exts/valentines/myvalenstate.py
+++ b/bot/exts/valentines/myvalenstate.py
@@ -7,6 +7,7 @@ from random import choice
import discord
from discord.ext import commands
+from bot.bot import Bot
from bot.constants import Colours
log = logging.getLogger(__name__)
@@ -18,9 +19,6 @@ with open(Path("bot/resources/valentines/valenstates.json"), "r", encoding="utf8
class MyValenstate(commands.Cog):
"""A Cog to find your most likely Valentine's vacation destination."""
- def __init__(self, bot: commands.Bot):
- self.bot = bot
-
def levenshtein(self, source: str, goal: str) -> int:
"""Calculates the Levenshtein Distance between source and goal."""
if len(source) < len(goal):
@@ -46,12 +44,12 @@ class MyValenstate(commands.Cog):
"""Find the vacation spot(s) with the most matching characters to the invoking user."""
eq_chars = collections.defaultdict(int)
if name is None:
- author = ctx.message.author.name.lower().replace(' ', '')
+ author = ctx.author.name.lower().replace(" ", "")
else:
- author = name.lower().replace(' ', '')
+ author = name.lower().replace(" ", "")
for state in STATES.keys():
- lower_state = state.lower().replace(' ', '')
+ 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())]
@@ -60,7 +58,7 @@ class MyValenstate(commands.Cog):
embed_title = "But there are more!"
if len(matches) > 1:
- leftovers = f"{', '.join(matches[:len(matches)-2])}, and {matches[len(matches)-1]}"
+ leftovers = f"{', '.join(matches[:-2])}, and {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!"
@@ -72,15 +70,15 @@ class MyValenstate(commands.Cog):
" you better"
embed = discord.Embed(
- title=f'Your Valenstate is {valenstate} \u2764',
- description=f'{STATES[valenstate]["text"]}',
+ title=f"Your Valenstate is {valenstate} \u2764",
+ description=f"{STATES[valenstate]['text']}",
colour=Colours.pink
)
embed.add_field(name=embed_title, value=embed_text)
embed.set_image(url=STATES[valenstate]["flag"])
- await ctx.channel.send(embed=embed)
+ await ctx.send(embed=embed)
-def setup(bot: commands.Bot) -> None:
- """Valenstate Cog load."""
- bot.add_cog(MyValenstate(bot))
+def setup(bot: Bot) -> None:
+ """Load the Valenstate Cog."""
+ bot.add_cog(MyValenstate())