-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (62 loc) · 1.49 KB
/
main.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
package main
import (
"log"
"os"
"os/signal"
"regexp"
"github.com/robfig/cron/v3"
"github.com/tpc3/Noa/lib/config"
"github.com/tpc3/Noa/lib/markov"
misskeyapi "github.com/tpc3/Noa/lib/misskeyApi"
)
func main() {
botID := misskeyapi.MisskeyGetuserID(config.Loadconfig.Misskey.Token)
c := cron.New()
c.AddFunc("@hourly", func() { runMarkov(botID) })
c.AddFunc("@weekly", func() { config.GetTlds() })
c.Start()
log.Print("Noa is now running!")
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop
}
func runMarkov(botID string) {
var text string
markovBlock := [][]string{}
notes, err := misskeyapi.MisskeyGetnotesRequest(config.Loadconfig.Misskey.Token, botID)
if err != nil {
return
}
// Create text
var okBlacklist bool
var okTld bool
for i := 0; i < 100; i++ {
for _, note := range notes {
data := markov.ParseToNode(note)
elems := markov.GetMarkovBlocks(data)
markovBlock = append(markovBlock, elems...)
}
noteElemset := markov.MarkovChainExec(markovBlock)
text = markov.TextGenerate(noteElemset)
okBlacklist = true
for _, v := range config.Loadconfig.TextBlacklist {
check := regexp.MustCompile(v)
if check.MatchString(text) {
okBlacklist = false
}
}
okTld = true
okTld = config.CheckTld(text)
if !okBlacklist || !okTld {
continue
}
}
if okBlacklist && okTld {
err = misskeyapi.MisskeySendnotesRequest(config.Loadconfig.Misskey.Token, text)
if err != nil {
return
}
} else {
log.Println("err")
}
}