fixed xp bug and updated welcome message

This commit is contained in:
Lilac-Rose 2026-01-09 15:55:49 +01:00
parent 8639b35233
commit 416c2b16da
3 changed files with 18 additions and 19 deletions

View File

@ -15,10 +15,16 @@ class Welcome(commands.Cog):
# Welcome channel
welcome_channel = self.bot.get_channel(876772600704020533)
# Create DM embed
# Create DM embed with updated message
dm_embed = discord.Embed(
title="Welcome!",
description="If you have any questions just ask. However if there are questions related to the game (either be Project Kat or Paper Lily) please refer to <#893371132596588544>, but preferably <#1066672893959884860> if they contain any kind of in-game information that could be considered a spoiler for those who haven't played it.\n\nAnd please enjoy your stay!",
title="Welcome to the server!",
description=(
"Please read <#1241579091597987880> and <#1238234316396429312> if you haven't already. "
"Apart from that, any Paper Lily related discussion should go into the dedicated channel for it - "
"and make sure to claim the spoiler chat role if that's what you want to talk about.\n\n"
"Don't hesitate to ask the mods any questions using <@575252669443211264>, "
"and we hope you enjoy your stay!"
),
color=discord.Color.blurple()
)
dm_embed.set_footer(text=f"Joined {member.guild.name}")

View File

@ -5,7 +5,7 @@ import traceback
from discord.ext import commands
from discord import app_commands
from .database import get_db
from .utils import xp_for_level, get_multiplier, load_config
from .utils import xp_for_level, get_multiplier, MULTIPLIERS, COOLDOWN
class Rank(commands.Cog):
def __init__(self, bot):
@ -34,12 +34,7 @@ class Rank(commands.Cog):
board_type_value = board_type.value if board_type else "lifetime"
lifetime = board_type_value == "lifetime"
# Load config fresh every time
config = load_config()
MULTIPLIERS = config["MULTIPLIERS"]
COOLDOWN = config["COOLDOWN"]
conn, cur = get_db(lifetime)
conn, cur = get_db(board_type_value)
# Fetch XP data for the requested user
cur.execute("SELECT xp, level, last_message FROM xp WHERE user_id = ?", (str(user.id),))
@ -52,14 +47,15 @@ class Rank(commands.Cog):
xp, level, last_msg = row
# Determine the user's leaderboard rank
# Determine the user's leaderboard rank (filtering absent users like in leaderboard.py)
cur.execute("SELECT user_id FROM xp ORDER BY xp DESC")
all_users = [r[0] for r in cur.fetchall()]
conn.close()
all_rows = [
row for row in all_rows
if interaction.guild.get_member(int(row[0])) is not None
# Filter out users who are no longer in the guild
all_users = [
uid for uid in all_users
if interaction.guild.get_member(int(uid)) is not None
]
try:
@ -86,7 +82,7 @@ class Rank(commands.Cog):
multiplier = get_multiplier(user, apply_multiplier=True)
role_name = None
for role in user.roles:
if str(role.id) in MULTIPLIERS and MULTIPLIERS[str(role.id)] == multiplier:
if role.id in MULTIPLIERS and MULTIPLIERS[role.id] == multiplier:
role_name = role.mention
break
multipliers_text.append(f"{role_name} {multiplier}x XP" if role_name else "None")

View File

@ -54,24 +54,21 @@ def get_multiplier(member, apply_multiplier=True):
return highest
def xp_for_level(level: int) -> int:
"""Calculate total XP required to reach a given level"""
xp = (level ** 3 * XP_CURVE["base"]) + (level ** 2 * XP_CURVE["square"]) + (level * XP_CURVE["linear"])
xp = xp / XP_CURVE["divisor"]
return int(math.floor(xp / 100) * 100)
def random_xp() -> int:
"""Generate random XP amount within configured range"""
return random.randint(RANDOM_XP["min"], RANDOM_XP["max"])
def can_get_xp(last_message_time: int) -> bool:
"""Check if enough time has passed since last XP gain"""
# FIXED: This function should ONLY check cooldown, not access member.roles
return (time.time() - last_message_time) >= COOLDOWN
async def check_level_up(member, cur, conn, lifetime=True):
"""Check if member leveled up and grant role rewards"""
# Ensure we have a Member object