This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
forked from osuripple/ripple-cron-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hanayo.go
77 lines (67 loc) · 1.66 KB
/
hanayo.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"io/ioutil"
"os"
"github.com/fatih/color"
)
func opClearExpiredProfileBackgrounds() {
defer wg.Done()
if c.HanayoFolder == "" {
color.Red("> ClearExpiredProfileBackgrounds: HanayoFolder is empty. ignoring")
return
}
// get all the backgrounds
elementsRaw, err := ioutil.ReadDir(c.HanayoFolder + "/static/profbackgrounds")
if err != nil {
color.Red("> ClearExpiredProfileBackgrounds: failed to get profile backgrounds: %v", err)
return
}
// convert to []string
elements := make([]string, len(elementsRaw))
for i, v := range elementsRaw {
if v.Name() == ".keep" {
continue
}
elements[i] = v.Name()
}
// get profile backgrounds in db
const q = "SELECT uid FROM profile_backgrounds WHERE type = 1"
inDB, err := db.Query(q)
if err != nil {
queryError(err, q)
}
// remove from elements every background that does actually exist in the database
for inDB.Next() {
var i string
err := inDB.Scan(&i)
if err != nil {
queryError(err, q)
return
}
for pos, e := range elements {
if e == i+".jpg" {
// remove from elements if exists
elements[pos] = elements[len(elements)-1]
elements = elements[:len(elements)-1]
break
}
}
}
// remove all elements still left
for _, e := range elements {
if e == "" {
continue
}
err := os.Remove(c.HanayoFolder + "/static/profbackgrounds/" + e)
if err != nil {
color.Red("> ClearExpiredProfileBackgrounds: failed to delete a background: %v", err)
}
}
}
func opSetOnlineUsers() {
defer wg.Done()
var users int
db.QueryRow("SELECT COUNT(*) FROM users").Scan(&users)
r.Set("ripple:registered_users", users, 0)
color.Green("> SetOnlineUsers: done!")
}