From e94a42c6dc304ac380a9752d9286bc247f466c49 Mon Sep 17 00:00:00 2001 From: Pengu Date: Mon, 9 Feb 2026 17:08:27 -0600 Subject: [PATCH] Added Penalty System --- bot.py | 6 +++--- commands.py | 45 +++++++++++++++++++++++++++++++++++++++------ constants.py | 25 ++++++++++++++++++------- helpers.py | 4 ++++ 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/bot.py b/bot.py index eaab7b8..dad7f3a 100644 --- a/bot.py +++ b/bot.py @@ -1,13 +1,13 @@ +from dotenv import load_dotenv +load_dotenv() # MUST be first + import discord from discord import app_commands -from dotenv import load_dotenv import os from db import init_db from commands import register -load_dotenv() - class Momentum(discord.Client): def __init__(self): super().__init__(intents=discord.Intents.default()) diff --git a/commands.py b/commands.py index fca5e48..d4fa8db 100644 --- a/commands.py +++ b/commands.py @@ -45,13 +45,14 @@ def register(tree: app_commands.CommandTree): # ------------------- # /match # ------------------- + from constants import ENABLED_WORKOUTS + enabled_workouts = [ - app_commands.Choice(name=name, value=name) - for name, value in WORKOUTS.items() - if value > 0 + app_commands.Choice(name=name, value=name) + for name in ENABLED_WORKOUTS.keys() ] - @tree.command(name="match", description="Log a Valorant match") + @tree.command(name="match_temp", description="Log a Valorant match") @app_commands.describe( result="Match result", rr_change="RR gained or lost", @@ -97,11 +98,43 @@ def register(tree: app_commands.CommandTree): ) return - new_rank, new_rr = apply_rr(user["rank"], user["rr"], rr_change) + # Enforce RR direction based on result + rr_delta = abs(rr_change) - per_death = WORKOUTS[workout] + if result == "LOSS": + rr_delta *= -1 + + new_rank, new_rr = apply_rr( + user["rank"], + user["rr"], + rr_delta + ) + + per_death = ENABLED_WORKOUTS.get(workout, 0) + + if per_death == 0: + await interaction.response.send_message( + "❌ That workout is currently disabled.", + ephemeral=True + ) + return + + # Base workout calculation workout_total = deaths * per_death + # Loss penalty + if result == "LOSS": + workout_total += 10 + + bonus_text = " (+10 loss penalty)" if result == "LOSS" else "" + + await interaction.response.send_message( + f"🏆 Match logged\n" + f"**Result:** {result}\n" + f"**Rank:** {new_rank} ({new_rr} RR)\n" + f"**Workout:** {workout} × {workout_total}{bonus_text}" + ) + cur.execute(""" UPDATE users SET diff --git a/constants.py b/constants.py index 3f17a2b..1bd56c5 100644 --- a/constants.py +++ b/constants.py @@ -12,12 +12,23 @@ VALORANT_RANKS = [ "Radiant" ] +def env_int(key: str) -> int: + value = os.getenv(key) + if value is None: + print(f"⚠️ ENV {key} not set, defaulting to 0") + return 0 + return int(value) + WORKOUTS = { - "Sit Ups": int(os.getenv("SITUPS", 0)), - "Bicep Curls": int(os.getenv("BICEP_CURLS", 0)), - "Pushups": int(os.getenv("PUSHUPS", 0)), - "Squats": int(os.getenv("SQUATS", 0)), - "Lunges": int(os.getenv("LUNGES", 0)), - "Russian Twists": int(os.getenv("RUSSIAN_TWISTS", 0)), - "Wall Pushups": int(os.getenv("WALL_PUSHUPS", 0)), + "Sit Ups": env_int("SITUPS"), + "Bicep Curls": env_int("BICEP_CURLS"), + "Pushups": env_int("PUSHUPS"), + "Squats": env_int("SQUATS"), + "Lunges": env_int("LUNGES"), + "Russian Twists": env_int("RUSSIAN_TWISTS"), + "Wall Pushups": env_int("WALL_PUSHUPS"), +} + +ENABLED_WORKOUTS = { + k: v for k, v in WORKOUTS.items() if v > 0 } diff --git a/helpers.py b/helpers.py index a8c2c52..4b241ca 100644 --- a/helpers.py +++ b/helpers.py @@ -4,6 +4,10 @@ def apply_rr(rank: str, rr: int, change: int): rr += change idx = VALORANT_RANKS.index(rank) + # Prevent negative RR + if rr < 0: + rr = 0 + while rr >= 100 and idx < len(VALORANT_RANKS) - 1: rr -= 100 idx += 1