|
|
@ -17,6 +17,23 @@ func GetActiveLevel(discordID string) (int, error) {
|
|
|
|
return 0, ErrNotFound
|
|
|
|
return 0, ErrNotFound
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetTotalActiveLevel() (int, error) {
|
|
|
|
|
|
|
|
rows, err := db.Query("SELECT sum(level) FROM activeLevel")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer rows.Close()
|
|
|
|
|
|
|
|
if rows.Next() {
|
|
|
|
|
|
|
|
var totalActiveLevel int
|
|
|
|
|
|
|
|
err := rows.Scan(&totalActiveLevel)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return totalActiveLevel, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0, ErrNotFound
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func AddActiveLevel(discordID string, addedLevel int) error {
|
|
|
|
func AddActiveLevel(discordID string, addedLevel int) error {
|
|
|
|
_, err := db.Exec("INSERT INTO activeLevel(id, level) VALUES(?, ?) ON DUPLICATE KEY UPDATE level=level+?", discordID, addedLevel, addedLevel)
|
|
|
|
_, err := db.Exec("INSERT INTO activeLevel(id, level) VALUES(?, ?) ON DUPLICATE KEY UPDATE level=level+?", discordID, addedLevel, addedLevel)
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|