Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 69 additions & 1 deletion src/api/dashboard/user_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
from src.api.dashboard.auth_routes import get_current_user
from mx_devtools import SettingsDB, StatsDB
import discord
import sqlite3
import os
from pathlib import Path

# Paths to databases
BASE_DIR = Path(__file__).resolve().parent.parent.parent.parent
DATA_DIR = BASE_DIR / "data"
MOD_DIR = BASE_DIR / "src" / "bot" / "cogs" / "moderation"


router = APIRouter(
prefix="/user",
Expand All @@ -23,13 +32,72 @@
stats_db = StatsDB()
global_info = await stats_db.get_global_user_info(user_id)

# 1. Moderation Stats (Global Warnings)
warns_count = 0
warns_db_path = MOD_DIR / "Datenbanken" / "warns.db"
if warns_db_path.exists():
try:
conn = sqlite3.connect(warns_db_path)
cursor = conn.cursor()
cursor.execute("SELECT COUNT(*) FROM warns WHERE user_id = ?", (user_id,))
warns_count = cursor.fetchone()[0]
conn.close()
except Exception:
pass

Check notice on line 46 in src/api/dashboard/user_routes.py

View check run for this annotation

codefactor.io / CodeFactor

src/api/dashboard/user_routes.py#L45-L46

Try, Except, Pass detected. (B110)

# 2. Global Chat Stats
global_chat_messages = 0
gc_db_path = DATA_DIR / "globalchat.db"
if gc_db_path.exists():
try:
conn = sqlite3.connect(gc_db_path)
cursor = conn.cursor()
cursor.execute("SELECT COUNT(*) FROM message_log WHERE user_id = ?", (user_id,))
global_chat_messages = cursor.fetchone()[0]
conn.close()
except Exception:
pass

Check notice on line 59 in src/api/dashboard/user_routes.py

View check run for this annotation

codefactor.io / CodeFactor

src/api/dashboard/user_routes.py#L58-L59

Try, Except, Pass detected. (B110)

# 3. Top Servers (from LevelSystem)
top_servers = []
ls_db_path = DATA_DIR / "levelsystem.db"
if ls_db_path.exists():
try:
conn = sqlite3.connect(ls_db_path)
cursor = conn.cursor()
# Get top 3 guilds by XP for this user
cursor.execute("""
SELECT guild_id, level, xp
FROM user_levels
WHERE user_id = ?
ORDER BY xp DESC
LIMIT 3
""", (user_id,))
rows = cursor.fetchall()
for row in rows:
top_servers.append({
"guild_id": str(row[0]),
"level": row[1],
"xp": row[2]
})
conn.close()
except Exception:
pass

Check notice on line 85 in src/api/dashboard/user_routes.py

View check run for this annotation

codefactor.io / CodeFactor

src/api/dashboard/user_routes.py#L84-L85

Try, Except, Pass detected. (B110)

return {
"success": True,
"data": {
"user_id": str(user_id),
"language": language,
"username": user.get("username", "Unknown"),
"global_stats": global_info
"global_stats": global_info,
"moderation": {
"total_warnings": warns_count
},
"global_chat": {
"total_messages": global_chat_messages
},
"top_servers": top_servers
}
}
except Exception as e:
Expand Down
9 changes: 9 additions & 0 deletions src/bot/ui/standards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class config:
version = "2.0.0-beta"
topgg = "https://top.gg/bot/1368201272624287754"
website = "https://managerx-bot.de"
github = "https://github.com/ManagerX-Development/ManagerX"

class texts:
footer = "Powered by ManagerX"
author = "ManagerX Development"
123 changes: 120 additions & 3 deletions src/web/dashboard/UserSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import {
Trophy,
Mic,
Server,
Flame
Flame,
Calendar,
Award,
Activity,
History
} from "lucide-react";
import { useAuth } from "../components/AuthProvider";
import { Button } from "../components/ui/button";
Expand All @@ -42,7 +46,10 @@ export default function UserSettingsPage() {
const [settings, setSettings] = useState({
username: "",
language: "de",
globalStats: null as any
globalStats: null as any,
moderation: null as any,
globalChat: null as any,
topServers: [] as any[]
});

useEffect(() => {
Expand All @@ -61,7 +68,10 @@ export default function UserSettingsPage() {
setSettings({
username: data.data.username || "",
language: data.data.language || "de",
globalStats: data.data.global_stats
globalStats: data.data.global_stats,
moderation: data.data.moderation,
globalChat: data.data.global_chat,
topServers: data.data.top_servers || []
});
}
}
Expand Down Expand Up @@ -261,6 +271,31 @@ export default function UserSettingsPage() {
</div>
</div>

{/* Advanced Global Stats */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="p-4 rounded-2xl bg-white/5 border border-white/10 flex items-center gap-4">
<div className="w-10 h-10 rounded-xl bg-primary/10 flex items-center justify-center">
<Calendar className="w-5 h-5 text-primary" />
</div>
<div>
<p className="text-[10px] font-bold uppercase tracking-widest text-slate-500">Mitglied seit</p>
<p className="text-sm font-bold text-white">
{settings.globalStats.first_seen ? new Date(settings.globalStats.first_seen).toLocaleDateString('de-DE', { day: '2-digit', month: 'long', year: 'numeric' }) : 'Unbekannt'}
</p>
</div>
</div>
<div className="p-4 rounded-2xl bg-white/5 border border-white/10 flex items-center gap-4">
<div className="w-10 h-10 rounded-xl bg-accent/10 flex items-center justify-center">
<Award className="w-5 h-5 text-accent" />
</div>
<div>
<p className="text-[10px] font-bold uppercase tracking-widest text-slate-500">Beste Streak</p>
<p className="text-sm font-bold text-white">{settings.globalStats.best_streak || settings.globalStats.daily_streak} Tage</p>
</div>
</div>
</div>


{/* Achievements Preview */}
{settings.globalStats.achievements && settings.globalStats.achievements.length > 0 && (
<div className="space-y-4">
Expand All @@ -282,6 +317,88 @@ export default function UserSettingsPage() {
</Card>
)}

{/* Moderation & Community */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-10">
{/* Moderation Card */}
<Card className="glass border-white/10 shadow-2xl rounded-[2.5rem] overflow-hidden">
<CardHeader className="p-10 pb-4">
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-red-500/10 flex items-center justify-center border border-red-500/20">
<Shield className="w-6 h-6 text-red-500" />
</div>
<div>
<CardTitle className="text-2xl font-bold">Moderation</CardTitle>
<CardDescription>Deine globale History.</CardDescription>
</div>
</div>
</CardHeader>
<CardContent className="p-10 pt-4 space-y-6">
<div className="flex items-center justify-between p-6 rounded-3xl bg-white/5 border border-white/10">
<div className="space-y-1">
<p className="text-[10px] font-bold uppercase tracking-widest text-slate-500">Gesamt Verwarnungen</p>
<h3 className={cn("text-4xl font-black", (settings.moderation?.total_warnings || 0) > 0 ? "text-red-500" : "text-green-500")}>
{settings.moderation?.total_warnings || 0}
</h3>
</div>
<div className="px-4 py-2 rounded-xl bg-white/5 text-[10px] font-bold uppercase tracking-widest text-slate-400">
{(settings.moderation?.total_warnings || 0) === 0 ? "Clean Record ✓" : "Achtung"}
</div>
</div>

<div className="flex items-center gap-4 p-4 rounded-2xl bg-white/5 border border-white/10">
<div className="w-10 h-10 rounded-xl bg-blue-500/10 flex items-center justify-center">
<MessageSquare className="w-5 h-5 text-blue-500" />
</div>
<div>
<p className="text-[10px] font-bold uppercase tracking-widest text-slate-500">Global-Chat Nachrichten</p>
<p className="text-lg font-bold text-white">{settings.globalChat?.total_messages?.toLocaleString() || 0}</p>
</div>
</div>
</CardContent>
</Card>

{/* Top Servers Card */}
<Card className="glass border-white/10 shadow-2xl rounded-[2.5rem] overflow-hidden">
<CardHeader className="p-10 pb-4">
<div className="flex items-center gap-4">
<div className="w-12 h-12 rounded-2xl bg-yellow-500/10 flex items-center justify-center border border-yellow-500/20">
<History className="w-6 h-6 text-yellow-500" />
</div>
<div>
<CardTitle className="text-2xl font-bold">Top Server</CardTitle>
<CardDescription>Deine aktivsten Communities.</CardDescription>
</div>
</div>
</CardHeader>
<CardContent className="p-10 pt-4 space-y-4">
{settings.topServers && settings.topServers.length > 0 ? (
settings.topServers.map((srv: any, i: number) => (
<div key={i} className="flex items-center justify-between p-4 rounded-2xl bg-white/5 border border-white/10 group hover:border-yellow-500/30 transition-colors">
<div className="flex items-center gap-4">
<div className="w-10 h-10 rounded-xl bg-white/5 flex items-center justify-center font-bold text-yellow-500">
#{i + 1}
</div>
<div>
<p className="text-xs font-bold text-white">Server ID: {srv.guild_id}</p>
<p className="text-[10px] font-bold uppercase tracking-widest text-slate-500">Level {srv.level}</p>
</div>
</div>
<div className="text-right">
<p className="text-xs font-bold text-yellow-500">{srv.xp.toLocaleString()} XP</p>
</div>
</div>
))
) : (
<div className="p-10 text-center space-y-2 opacity-50">
<Activity className="w-8 h-8 mx-auto text-slate-500" />
<p className="text-xs font-bold uppercase tracking-widest">Noch keine Level-Daten</p>
</div>
)}
</CardContent>
</Card>
</div>


{/* Preferences */}
<Card className="glass border-white/10 shadow-2xl rounded-[2.5rem] overflow-hidden">
<CardHeader className="p-10 pb-4">
Expand Down
Loading