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
|
import discord
|
||||||
from discord import app_commands
|
from discord import app_commands
|
||||||
from dotenv import load_dotenv
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from db import init_db
|
from db import init_db
|
||||||
from commands import register
|
from commands import register
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
|
|
||||||
class Momentum(discord.Client):
|
class Momentum(discord.Client):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(intents=discord.Intents.default())
|
super().__init__(intents=discord.Intents.default())
|
||||||
|
|||||||
43
commands.py
43
commands.py
@@ -45,13 +45,14 @@ def register(tree: app_commands.CommandTree):
|
|||||||
# -------------------
|
# -------------------
|
||||||
# /match
|
# /match
|
||||||
# -------------------
|
# -------------------
|
||||||
|
from constants import ENABLED_WORKOUTS
|
||||||
|
|
||||||
enabled_workouts = [
|
enabled_workouts = [
|
||||||
app_commands.Choice(name=name, value=name)
|
app_commands.Choice(name=name, value=name)
|
||||||
for name, value in WORKOUTS.items()
|
for name in ENABLED_WORKOUTS.keys()
|
||||||
if value > 0
|
|
||||||
]
|
]
|
||||||
|
|
||||||
@tree.command(name="match", description="Log a Valorant match")
|
@tree.command(name="match_temp", description="Log a Valorant match")
|
||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
result="Match result",
|
result="Match result",
|
||||||
rr_change="RR gained or lost",
|
rr_change="RR gained or lost",
|
||||||
@@ -97,11 +98,43 @@ def register(tree: app_commands.CommandTree):
|
|||||||
)
|
)
|
||||||
return
|
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
|
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("""
|
cur.execute("""
|
||||||
UPDATE users
|
UPDATE users
|
||||||
SET
|
SET
|
||||||
|
|||||||
25
constants.py
25
constants.py
@@ -12,12 +12,23 @@ VALORANT_RANKS = [
|
|||||||
"Radiant"
|
"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 = {
|
WORKOUTS = {
|
||||||
"Sit Ups": int(os.getenv("SITUPS", 0)),
|
"Sit Ups": env_int("SITUPS"),
|
||||||
"Bicep Curls": int(os.getenv("BICEP_CURLS", 0)),
|
"Bicep Curls": env_int("BICEP_CURLS"),
|
||||||
"Pushups": int(os.getenv("PUSHUPS", 0)),
|
"Pushups": env_int("PUSHUPS"),
|
||||||
"Squats": int(os.getenv("SQUATS", 0)),
|
"Squats": env_int("SQUATS"),
|
||||||
"Lunges": int(os.getenv("LUNGES", 0)),
|
"Lunges": env_int("LUNGES"),
|
||||||
"Russian Twists": int(os.getenv("RUSSIAN_TWISTS", 0)),
|
"Russian Twists": env_int("RUSSIAN_TWISTS"),
|
||||||
"Wall Pushups": int(os.getenv("WALL_PUSHUPS", 0)),
|
"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
|
rr += change
|
||||||
idx = VALORANT_RANKS.index(rank)
|
idx = VALORANT_RANKS.index(rank)
|
||||||
|
|
||||||
|
# Prevent negative RR
|
||||||
|
if rr < 0:
|
||||||
|
rr = 0
|
||||||
|
|
||||||
while rr >= 100 and idx < len(VALORANT_RANKS) - 1:
|
while rr >= 100 and idx < len(VALORANT_RANKS) - 1:
|
||||||
rr -= 100
|
rr -= 100
|
||||||
idx += 1
|
idx += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user