aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Chris Lovering <[email protected]>2021-08-10 14:24:57 +0100
committerGravatar Chris Lovering <[email protected]>2021-08-10 14:24:57 +0100
commit0a2e18423a8042f6ab7e96e3d0775402a5cddac8 (patch)
tree865cc5f3fd52706738670704e9d0dd9924498a76
parentUpdate love calculator docstring to reflect new behaviour (diff)
Remove unneeded checks in love calculator command
Now that we don't allow arbitrary strings, we can simplify the input validation/modification we do.
-rw-r--r--bot/exts/valentines/lovecalculator.py16
1 files changed, 3 insertions, 13 deletions
diff --git a/bot/exts/valentines/lovecalculator.py b/bot/exts/valentines/lovecalculator.py
index d80f2adf..46bcc6fd 100644
--- a/bot/exts/valentines/lovecalculator.py
+++ b/bot/exts/valentines/lovecalculator.py
@@ -4,7 +4,7 @@ import json
import logging
import random
from pathlib import Path
-from typing import Coroutine, Optional, Union
+from typing import Coroutine, Optional
import discord
from discord import Member
@@ -53,23 +53,13 @@ class LoveCalculator(Cog):
)):
raise BadArgument("Both members must have the love fest role!")
- def normalize(arg: Union[Member, str]) -> Coroutine:
- if isinstance(arg, Member):
- # If we are given a member, return name#discrim without any extra changes
- arg = str(arg)
- else:
- # Otherwise normalise case and remove any leading/trailing whitespace
- arg = arg.strip().title()
+ def normalize(arg: Member) -> Coroutine:
# This has to be done manually to be applied to usernames
- return clean_content(escape_markdown=True).convert(ctx, arg)
+ return clean_content(escape_markdown=True).convert(ctx, str(arg))
# Sort to ensure same result for same input, regardless of order
who, whom = sorted([await normalize(arg) for arg in (who, whom)])
- # Make sure user didn't provide something silly such as 10 spaces
- if not (who and whom):
- raise BadArgument("Arguments must be non-empty strings.")
-
# Hash inputs to guarantee consistent results (hashing algorithm choice arbitrary)
#
# hashlib is used over the builtin hash() to guarantee same result over multiple runtimes