Skip to content

Commit ca637b7

Browse files
author
RikaCelery
committed
fix: use StringSlice instead of IntSlice as superuser
1 parent 773bbc4 commit ca637b7

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

cmd/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/spf13/viper"
88
zero "github.com/wdvxdr1123/ZeroBot"
99
"github.com/wdvxdr1123/ZeroBot/driver"
10+
"strconv"
1011

1112
// 可选插件,若要启用,去除注释即可
1213
// _ "github.com/RicheyJang/PaimengBot/plugins/HiOSU"
@@ -63,16 +64,20 @@ func main() {
6364
log.Fatal("FlushConfig err: ", err)
6465
}
6566
// 启动服务
66-
log.Infof("读取超级管理员列表:%v", viper.GetIntSlice("superuser"))
67+
log.Infof("读取超级管理员列表:%v", viper.GetStringSlice("superuser"))
6768
config := zero.Config{
6869
NickName: []string{viper.GetString("nickname")},
6970
CommandPrefix: viper.GetString("command_prefix"),
7071
Driver: []zero.Driver{
7172
driver.NewWebSocketClient(viper.GetString("server.address"), viper.GetString("server.token")),
7273
},
7374
}
74-
for _, id := range viper.GetIntSlice("superuser") {
75-
config.SuperUsers = append(config.SuperUsers, int64(id))
75+
for _, sid := range viper.GetStringSlice("superuser") {
76+
id, err := strconv.ParseInt(sid, 10, 64)
77+
if err != nil {
78+
panic(err)
79+
}
80+
config.SuperUsers = append(config.SuperUsers, id)
7681
}
7782
zero.RunAndBlock(&config, func() {
7883
log.Infoln(zero.BotConfig.NickName[0], "启动成功~")

pre_works.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"os/exec"
1010
"path/filepath"
1111
"runtime"
12+
"strconv"
1213
"strings"
1314
"time"
1415

@@ -173,8 +174,12 @@ func flushMainConfig(configPath string, configFileName string) error {
173174
viper.WatchConfig()
174175
viper.OnConfigChange(func(e fsnotify.Event) { // 配置文件发生变更之后会调用的回调函数
175176
zero.BotConfig.SuperUsers = []int64{}
176-
for _, id := range viper.GetIntSlice("superuser") {
177-
zero.BotConfig.SuperUsers = append(zero.BotConfig.SuperUsers, int64(id))
177+
for _, sid := range viper.GetStringSlice("superuser") {
178+
id, err := strconv.ParseInt(sid, 10, 64)
179+
if err != nil {
180+
panic(err)
181+
}
182+
zero.BotConfig.SuperUsers = append(zero.BotConfig.SuperUsers, id)
178183
}
179184
zero.BotConfig.CommandPrefix = viper.GetString("command_prefix")
180185
zero.BotConfig.NickName = []string{viper.GetString("nickname")}

0 commit comments

Comments
 (0)