Skip to content

Commit bb8fc7b

Browse files
committed
added whimsy
1 parent 2bd9df8 commit bb8fc7b

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

src/calculator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ def get_disable_calculation(self):
290290
# If boolean is true, result was successful and str contains result.
291291
# If boolean is false, result was unsuccessful and str contains error message
292292
def general_kill_handler(weapon_fuzzy_name, target_fuzzy_name):
293+
if (result := easter_egg_check(weapon_fuzzy_name,target_fuzzy_name)) is not None:
294+
return result
295+
293296
args = None
294297
if weapon_fuzzy_name in parse.weapons_dictionary:
295298
weapon_name = parse.weapons_dictionary[weapon_fuzzy_name]
@@ -446,3 +449,40 @@ def statsheet_handler(entity_name):
446449
return "I could not process a request because the entity is not a valid weapon, structure or vehicle."
447450
except:
448451
return bot.EntityNotFoundError(entity_name)
452+
453+
# whimsy
454+
def easter_egg_check(weapon_fuzzy_name, target_fuzzy_name):
455+
easter_eggs = [
456+
("Watch Tower", "Scout Plane", 1, 95)
457+
]
458+
for weapon, target, hits, threshold in easter_eggs:
459+
if fuzz.normalized_ratio_equal(weapon_fuzzy_name,weapon,threshold) and fuzz.normalized_partial_ratio_equal(target_fuzzy_name,target,threshold):
460+
return f"It takes {hits} {weapon} to kill a {target}"
461+
return None
462+
463+
# .--.
464+
# `. \
465+
# \ \
466+
# . \
467+
# : .
468+
# | .
469+
# | :
470+
# | |
471+
# ..._ ___ | |
472+
# `."".`''''""--..___ | |
473+
# ,-\ \ ""-...__ _____________/ |
474+
# / ` " ' `"""""""" .
475+
# \ L
476+
# (> \
477+
# / \
478+
# \_ ___..---. L
479+
# `--' '. \
480+
# . \_
481+
# _/`. `.._
482+
# .' -. `.
483+
# / __.-Y /''''''-...___,...--------.._ |
484+
# / _." | / ' . \ '---..._ |
485+
# / / / / _,. ' ,/ | |
486+
# \_,' _.' / /'' _,-' _| |
487+
# ' / `-----'' / |
488+
# `...-' `...-'

src/fuzzy.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import utils
66
import bot
77
from fuzzywuzzy import process
8+
import re
89

910

1011

@@ -156,4 +157,27 @@ def fuzzy_match_weapon_name_command(name):
156157
if score > 60:
157158
good_score_list.append(key)
158159
return good_score_list
159-
160+
161+
# no space, all lowercase, singular only
162+
def normalize(text: str) -> str:
163+
text = re.sub(r"\s+", " ", text.lower().strip())
164+
words = text.split()
165+
words = [singularize(w) for w in words]
166+
return "".join(words)
167+
168+
def singularize(word: str) -> str:
169+
if word.endswith("ies"):
170+
return word[:-3] + "y"
171+
if word.endswith("ses"):
172+
return word[:-2] # e.g. classes -> class
173+
if word.endswith("s") and not word.endswith("ss"):
174+
return word[:-1]
175+
return word
176+
177+
def normalized_partial_ratio_equal(a: str, b: str, c: int = 98) -> bool:
178+
print(fuzz.partial_ratio(normalize(a), normalize(b)))
179+
return fuzz.partial_ratio(normalize(a), normalize(b)) >= c
180+
181+
def normalized_ratio_equal(a: str, b: str, c: int = 98) -> bool:
182+
print(fuzz.ratio(normalize(a), normalize(b)))
183+
return fuzz.ratio(normalize(a), normalize(b)) >= c

0 commit comments

Comments
 (0)