aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Darth Delay <[email protected]>2019-02-12 09:52:46 +0100
committerGravatar Darth Delay <[email protected]>2019-02-12 09:52:46 +0100
commit911a9f512b7efdc589f2f6656d0b84c15b4b9dc9 (patch)
tree4ac5305c19b13b6e830b5fb5511c8a318db67491
parentUpdate LoveCalculator as in #100 (diff)
Update LoveCalculator to address requested changes
This commit is addressing the new change requests on #100 Here's a list of what has been changed: -> Moved `LOVE_DATA` and `LOVE_LEVELS` out of the LoveCalculator class: This change has been made, so that the **love_matches.json** file does not have to be loaded every time someone uses `.love`. Now the file is loaded once when the cog is loaded. Requested by: Scragly -> Moved the Member converter to the function parameters: I didn't know that this works. It's good to learn something new. This also removes the `else` block, as it is no longer needed. Requested by: Scragly -> Removed the Roles instance: Before these changes, an instance of `Roles` has been created inside the if block: `ctx.guild.get_role(Roles().helpers).members`. This instance has now been removed as it is unnecessary Requested by: Scragly -> Adjusted the embed's description's string length: This project is aimed at 100 character lines in the future. The descrip- tion is way longer, so its string has been split up to fit that specifi- cation. Requested by: Scragly
-rw-r--r--bot/seasons/valentines/lovecalculator.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/bot/seasons/valentines/lovecalculator.py b/bot/seasons/valentines/lovecalculator.py
index ec607b6f..9342f0fa 100644
--- a/bot/seasons/valentines/lovecalculator.py
+++ b/bot/seasons/valentines/lovecalculator.py
@@ -10,6 +10,10 @@ from bot.constants import Roles
log = logging.getLogger(__name__)
+with open(Path("bot", "resources", "valentines", "love_matches.json"), "r") as file:
+ LOVE_DATA = json.load(file)
+LOVE_LEVELS = [int(x) for x in LOVE_DATA]
+
class LoveCalculator:
"""
@@ -20,7 +24,7 @@ class LoveCalculator:
@commands.command(aliases=('love_calculator', 'love_calc'))
@commands.cooldown(rate=1, per=5.0, type=commands.BucketType.user)
- async def love(self, ctx, name_one: discord.Member, name_two=None):
+ async def love(self, ctx, name_one: discord.Member, name_two: discord.Member = None):
"""
Calculates the love between two given names
@@ -40,15 +44,8 @@ class LoveCalculator:
"""
if name_two is None:
- staff = ctx.guild.get_role(Roles().helpers).members
+ staff = ctx.guild.get_role(Roles.helpers).members
name_two = choice(staff)
- else:
- name_two = await commands.MemberConverter().convert(ctx, name_two)
- print(name_two)
-
- with open(Path("bot", "resources", "valentines", "love_matches.json"), "r") as file:
- LOVE_DATA = json.load(file)
- LOVE_LEVELS = [int(x) for x in LOVE_DATA]
love_meter = (name_one.id + name_two.id) % 100
love_idx = str(sorted(x for x in LOVE_LEVELS if x <= love_meter)[-1])
@@ -56,7 +53,10 @@ class LoveCalculator:
embed = discord.Embed(
title=love_status,
- description=f'{name_one.display_name} \u2764 {name_two.display_name} scored {love_meter}%!\n\u200b',
+ description=(
+ f'{name_one.display_name} \u2764 {name_two.display_name}'
+ f' scored {love_meter}%!\n\u200b'
+ ),
color=discord.Color.dark_magenta()
)
embed.add_field(