-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.go
148 lines (135 loc) · 4.39 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Package main NanoBot-Plugin main file
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"runtime"
"strconv"
"strings"
"time"
"github.com/FloatTech/NanoBot-Plugin/kanban" // 打印 banner
_ "github.com/FloatTech/NanoBot-Plugin/plugin/autowithdraw"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/b14"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/base64gua"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/baseamasiro"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/chrev"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/dish"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/emojimix"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/fortune"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/genshin"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/hyaku"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/manager"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/qqwife"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/qunyou"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/runcode"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/score"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/status"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/tarot"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/wife"
_ "github.com/FloatTech/NanoBot-Plugin/plugin/wordle"
// -----------------------以下为内置依赖,勿动------------------------ //
nano "github.com/fumiama/NanoBot"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"github.com/FloatTech/floatbox/process"
"github.com/FloatTech/NanoBot-Plugin/kanban/banner"
// -----------------------以上为内置依赖,勿动------------------------ //
)
func main() {
if !strings.Contains(runtime.Version(), "go1.2") { // go1.20之前版本需要全局 seed,其他插件无需再 seed
rand.Seed(time.Now().UnixNano()) //nolint: staticcheck
}
token := flag.String("t", "", "qq api token")
appid := flag.String("a", "", "qq appid")
secret := flag.String("s", "", "qq secret")
debug := flag.Bool("D", false, "enable debug-level log output")
timeout := flag.Int("T", 60, "api timeout (s)")
help := flag.Bool("h", false, "print this help")
loadconfig := flag.String("c", "", "load from config")
sandbox := flag.Bool("sandbox", false, "run in sandbox api")
onlypublic := flag.Bool("public", false, "only listen to public intent")
addqqintent := flag.Bool("qq", false, "also listen QQ intent")
shardindex := flag.Uint("shardindex", 0, "shard index")
shardcount := flag.Uint("shardcount", 0, "shard count")
savecfg := flag.String("save", "", "save bot config to filename (eg. config.yaml)")
superallqqusers := flag.Bool("superallqq", false, "make all QQ users to be SuperUser")
flag.Parse()
if *help {
fmt.Println("Usage:")
flag.PrintDefaults()
os.Exit(0)
}
if *debug {
logrus.SetLevel(logrus.DebugLevel)
}
intent := uint32(nano.IntentGuildPrivate)
if *onlypublic {
intent = nano.IntentGuildPublic
}
if *addqqintent {
intent |= nano.IntentQQ
}
sus := make([]string, 0, 16)
if *superallqqusers {
sus = append(sus, nano.SuperUserAllQQUsers)
}
for _, s := range flag.Args() {
_, err := strconv.ParseInt(s, 10, 64)
if err != nil {
continue
}
sus = append(sus, s)
}
if *sandbox {
nano.OpenAPI = nano.SandboxAPI
}
bot := []*nano.Bot{}
if *loadconfig == "" {
bot = append(bot, &nano.Bot{
AppID: *appid,
Token: *token,
Secret: *secret,
SuperUsers: sus,
Timeout: time.Duration(*timeout) * time.Second,
Intents: intent,
ShardIndex: uint8(*shardindex),
ShardCount: uint8(*shardcount),
})
} else {
f, err := os.Open(*loadconfig)
if err != nil {
logrus.Fatal(err)
}
dec := yaml.NewDecoder(f)
dec.KnownFields(true)
err = dec.Decode(&bot)
_ = f.Close()
if err != nil {
logrus.Fatal(err)
}
}
if *savecfg != "" {
f, err := os.Create(*savecfg)
if err != nil {
logrus.Fatal(err)
}
defer f.Close()
err = yaml.NewEncoder(f).Encode(bot)
if err != nil {
logrus.Fatal(err)
}
logrus.Infoln("已将当前配置保存到", *savecfg)
return
}
nano.OnMessageCommandGroup([]string{"help", "帮助", "menu", "菜单"}, nano.OnlyToMe).SetBlock(true).
Handle(func(ctx *nano.Ctx) {
_, _ = ctx.SendChain(nano.Text(banner.Banner))
})
nano.OnMessageFullMatch("查看nbp公告", nano.OnlyToMe, nano.AdminPermission).SetBlock(true).
Handle(func(ctx *nano.Ctx) {
_, _ = ctx.SendChain(nano.Text(strings.ReplaceAll(kanban.Kanban(), "\t", "")))
})
_ = nano.Run(process.GlobalInitMutex.Unlock, bot...)
}