refactored the voice update function to exclude users if their muted or afk and remade the commands
Some checks failed
Bot Unit Tests / test (push) Has been cancelled
Bot Unit Tests / test (pull_request) Has been cancelled

This commit is contained in:
2026-04-01 22:50:03 +02:00
parent 493c093fdb
commit 6b0dc24721
2 changed files with 261 additions and 30 deletions

View File

@@ -31,14 +31,18 @@ func InitDB() {
}
func SaveSession(userID string, seconds int) {
query := `INSERT INTO voice_sessions (user_id, seconds, created_at) VALUES (?, ?, ?)`
query := `
INSERT INTO voice_sessions (user_id, seconds, created_at)
VALUES (?, ?, ?)
`
DB.Exec(query, userID, seconds, time.Now())
}
func GetUserStats(userID string) int {
var total sql.NullInt64 // NullInt64 fängt NULL-Ergebnisse ab
query := `SELECT SUM(seconds) FROM voice_sessions
WHERE user_id = ? AND created_at > date('now', '-30 days')`
WHERE user_id = ? AND created_at > datetime('now', '-30 days')`
err := DB.QueryRow(query, userID).Scan(&total)
if err != nil || !total.Valid {
@@ -46,3 +50,38 @@ func GetUserStats(userID string) int {
}
return int(total.Int64)
}
type UserStats struct {
UserID string
Seconds int
}
func GetTopUsers(limit int) []UserStats {
query := `
SELECT user_id, SUM(seconds) as total
FROM voice_sessions
WHERE created_at > datetime('now', '-30 days')
GROUP BY user_id
ORDER BY total DESC
LIMIT ?
`
rows, err := DB.Query(query, limit)
if err != nil {
return nil
}
defer rows.Close()
var result []UserStats
for rows.Next() {
var u UserStats
err := rows.Scan(&u.UserID, &u.Seconds)
if err != nil {
continue
}
result = append(result, u)
}
return result
}