refactored the voice update function to exclude users if their muted or afk and remade the commands
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user