This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
81 lines (77 loc) · 1.76 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
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"io/fs"
"math/rand"
"os"
"regexp"
"time"
nvai "github.com/FloatTech/AnimeAPI/novelai"
"github.com/FloatTech/floatbox/binary"
"github.com/FloatTech/zbputils/process"
)
var (
regre = regexp.MustCompile(`.Register\(\n?\t*"(.+)",`)
regsv = regexp.MustCompile(`[sS]ervice[nN]ame = "(.+)"`)
)
func main() {
rand.Seed(time.Now().UnixNano())
key := os.Getenv("NOVELAI_API_KEY")
if key == "" {
panic("nil api key")
}
p := nvai.NewDefaultPayload()
p.Parameters.Width = 768
p.Parameters.Height = 512
n := nvai.NewNovalAI(key, p)
err := n.Login()
if err != nil {
panic(err)
}
plugins := []string{}
err = fs.WalkDir(os.DirFS(os.Args[1]), ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
data, err := os.ReadFile(os.Args[1] + "/" + path)
if err != nil {
return err
}
for _, m := range regre.FindAllStringSubmatch(binary.BytesToString(data), -1) {
plugins = append(plugins, m[1:]...)
}
for _, m := range regsv.FindAllStringSubmatch(binary.BytesToString(data), -1) {
plugins = append(plugins, m[1:]...)
}
return nil
})
if err != nil {
panic(err)
}
target := os.Args[2]
err = os.MkdirAll(target, 0755)
if err != nil {
panic(err)
}
for _, nm := range plugins {
fmt.Println("生成:", nm)
for i := 0; i < 8; i++ {
_, _, im, err := n.Draw(nm + ",1girl,looking_at_viewer,half_body,cute,bule_archive,extremely_detailed_CG_unity_8k_wallpaper,illustration,high_quality,lan")
if err != nil {
fmt.Println("ERROR:", err)
process.SleepAbout1sTo2s()
continue
}
err = os.WriteFile(target+"/"+nm+".png", im, 0644)
if err != nil {
panic(err)
}
fmt.Println("成功")
process.SleepAbout1sTo2s()
break
}
}
}