CALORIE SYSTEM
This commit is contained in:
21
commands.py
21
commands.py
@@ -1,7 +1,7 @@
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from db import get_db
|
||||
from constants import VALORANT_RANKS, WORKOUTS
|
||||
from constants import VALORANT_RANKS, WORKOUTS, WORKOUT_CALORIES
|
||||
from helpers import apply_rr
|
||||
import random
|
||||
|
||||
@@ -52,7 +52,7 @@ def register(tree: app_commands.CommandTree):
|
||||
for name in ENABLED_WORKOUTS.keys()
|
||||
]
|
||||
|
||||
@tree.command(name="match_temp", description="Log a Valorant match")
|
||||
@tree.command(name="match", description="Log a Valorant match")
|
||||
@app_commands.describe(
|
||||
result="Match result",
|
||||
rr_change="RR gained or lost",
|
||||
@@ -128,11 +128,16 @@ def register(tree: app_commands.CommandTree):
|
||||
|
||||
bonus_text = " (+10 loss penalty)" if result == "LOSS" else ""
|
||||
|
||||
# Calculate calories burned
|
||||
cal_per_rep = WORKOUT_CALORIES.get(workout, 0)
|
||||
calories_burned = round(workout_total * cal_per_rep, 2)
|
||||
|
||||
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}"
|
||||
f"**Workout:** {workout} × {workout_total}{bonus_text}\n"
|
||||
f"**Calories:** {calories_burned:.1f} Cal"
|
||||
)
|
||||
|
||||
cur.execute("""
|
||||
@@ -141,9 +146,10 @@ def register(tree: app_commands.CommandTree):
|
||||
kills = kills + %s,
|
||||
deaths = deaths + %s,
|
||||
rank = %s,
|
||||
rr = %s
|
||||
rr = %s,
|
||||
calories_burned = calories_burned + %s
|
||||
WHERE discord_id = %s
|
||||
""", (kills, deaths, new_rank, new_rr, str(interaction.user.id)))
|
||||
""", (kills, deaths, new_rank, new_rr, float(calories_burned), str(interaction.user.id)))
|
||||
|
||||
cur.execute("""
|
||||
INSERT INTO workouts (discord_id, workout, amount)
|
||||
@@ -212,6 +218,11 @@ def register(tree: app_commands.CommandTree):
|
||||
value=f"{u['kills']} / {u['deaths']}",
|
||||
inline=False
|
||||
)
|
||||
embed.add_field(
|
||||
name="Calories Burned",
|
||||
value=f"{u.get('calories_burned', 0):.1f} Cal",
|
||||
inline=False
|
||||
)
|
||||
|
||||
workout_text = (
|
||||
"\n".join(f"{w['workout']}: {w['amount']}" for w in workout_rows)
|
||||
|
||||
11
constants.py
11
constants.py
@@ -19,6 +19,7 @@ def env_int(key: str) -> int:
|
||||
return 0
|
||||
return int(value)
|
||||
|
||||
# Workouts with reps per death and calories burned per rep
|
||||
WORKOUTS = {
|
||||
"Sit Ups": env_int("SITUPS"),
|
||||
"Bicep Curls": env_int("BICEP_CURLS"),
|
||||
@@ -29,6 +30,16 @@ WORKOUTS = {
|
||||
"Wall Pushups": env_int("WALL_PUSHUPS"),
|
||||
}
|
||||
|
||||
WORKOUT_CALORIES = {
|
||||
"Sit Ups": 0.2,
|
||||
"Bicep Curls": 0.2,
|
||||
"Pushups": 0.35,
|
||||
"Squats": 0.6,
|
||||
"Lunges": 0.2,
|
||||
"Russian Twists": 0.2,
|
||||
"Wall Pushups": 0.1,
|
||||
}
|
||||
|
||||
ENABLED_WORKOUTS = {
|
||||
k: v for k, v in WORKOUTS.items() if v > 0
|
||||
}
|
||||
|
||||
9
db.py
9
db.py
@@ -22,10 +22,19 @@ def init_db():
|
||||
rr INT DEFAULT 0,
|
||||
kills INT DEFAULT 0,
|
||||
deaths INT DEFAULT 0,
|
||||
calories_burned DECIMAL(10, 2) DEFAULT 0,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
""")
|
||||
|
||||
# Add calories_burned column if it doesn't exist
|
||||
try:
|
||||
cur.execute("""
|
||||
ALTER TABLE users ADD COLUMN calories_burned DECIMAL(10, 2) DEFAULT 0
|
||||
""")
|
||||
except:
|
||||
pass # Column already exists
|
||||
|
||||
cur.execute("""
|
||||
CREATE TABLE IF NOT EXISTS workouts (
|
||||
discord_id VARCHAR(32),
|
||||
|
||||
13
helpers.py
13
helpers.py
@@ -4,12 +4,17 @@ def apply_rr(rank: str, rr: int, change: int):
|
||||
rr += change
|
||||
idx = VALORANT_RANKS.index(rank)
|
||||
|
||||
# Prevent negative RR
|
||||
if rr < 0:
|
||||
rr = 0
|
||||
|
||||
# Rank up: 100 RR or more
|
||||
while rr >= 100 and idx < len(VALORANT_RANKS) - 1:
|
||||
rr -= 100
|
||||
idx += 1
|
||||
|
||||
# Rank down: negative RR
|
||||
while rr < 0 and idx > 0:
|
||||
rr += 100
|
||||
idx -= 1
|
||||
|
||||
# Clamp RR to 0-99 range
|
||||
rr = max(0, min(99, rr))
|
||||
|
||||
return VALORANT_RANKS[idx], rr
|
||||
|
||||
Reference in New Issue
Block a user