Added Penalty System
This commit is contained in:
6
bot.py
6
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())
|
||||
|
||||
45
commands.py
45
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
|
||||
|
||||
25
constants.py
25
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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user