-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
103 lines (90 loc) · 1.99 KB
/
Copy pathmain.go
File metadata and controls
103 lines (90 loc) · 1.99 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package main
import (
"flag"
"log"
"os"
"path/filepath"
"time"
"github.com/omatztw/gomatalk/pkg/boltdb"
"github.com/omatztw/gomatalk/pkg/config"
"github.com/omatztw/gomatalk/pkg/db"
"github.com/omatztw/gomatalk/pkg/discord"
global "github.com/omatztw/gomatalk/pkg/global_vars"
)
func WavGC() {
go func() {
t := time.NewTicker(30 * time.Minute) // 30分おきに検索
defer t.Stop()
for {
select {
case <-t.C:
files, err := walkMatch("/tmp/voice-*.wav")
if err != nil {
log.Println("FATA: Error WavGC():", err)
return
}
for _, file := range files {
info, err := os.Stat(file)
if err != nil {
log.Println("FATA: Error WavGC():", err)
return
}
if info.ModTime().Before(time.Now().Add(-time.Minute * 10)) { // 10分前以前に作られたファイルは消去
log.Println("Garbage WAV found. Deleting...: " + file)
os.Remove(file)
}
}
}
}
}()
}
func walkMatch(pattern string) ([]string, error) {
files, err := filepath.Glob(pattern)
if err != nil {
return nil, err
}
return files, nil
}
func main() {
// runtime.GOMAXPROCS(1)
filename := flag.String("f", "bot.toml", "Set path for the config file.")
flag.Parse()
log.Println("INFO: Opening", *filename)
err := config.LoadConfig(*filename)
if err != nil {
log.Println("FATA:", err)
return
}
err = config.LoadVoiceConfig(*filename)
if err != nil {
log.Println("FATA:", err)
return
}
err = config.LoadVoiceVoxConfig(*filename)
if err != nil {
log.Println("FATA:", err)
return
}
err = config.LoadVoiceVoxApiConfig(*filename)
if err != nil {
log.Println("FATA:", err)
return
}
err = config.LoadAquestalkConfig(*filename)
if err != nil {
log.Println("FATA:", err)
return
}
// Hot reload
config.Watch()
global.DB = db.NewDatabase("data/gomatalk-sqlite.db")
// Connecto to Discord
err = discord.DiscordConnect()
if err != nil {
log.Println("FATA: Discord", err)
return
}
boltdb.Migrate()
WavGC()
<-make(chan struct{})
}