Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新依赖并修复zerobot更新所带来的问题 #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"github.com/RicheyJang/PaimengBot/manager"
"github.com/RicheyJang/PaimengBot/utils"
"github.com/RicheyJang/PaimengBot/utils/consts"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
Expand Down Expand Up @@ -67,9 +68,9 @@ func main() {
zero.RunAndBlock(zero.Config{
NickName: []string{viper.GetString("nickname")},
CommandPrefix: "",
SuperUsers: viper.GetStringSlice("superuser"),
SuperUsers: utils.StringSlice2int64Slice(viper.GetStringSlice("superuser")),
Driver: []zero.Driver{
driver.NewWebSocketClient(viper.GetString("server.address"), viper.GetString("server.token")),
},
})
}, nil)
}
92 changes: 47 additions & 45 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,85 +1,87 @@
module github.com/RicheyJang/PaimengBot

go 1.17
go 1.18

require (
github.com/PuerkitoBio/goquery v1.8.0
github.com/chromedp/chromedp v0.7.6
github.com/chromedp/chromedp v0.8.5
github.com/fogleman/gg v1.3.0
github.com/fsnotify/fsnotify v1.5.1
github.com/glebarez/sqlite v1.3.5
github.com/fsnotify/fsnotify v1.5.4
github.com/glebarez/sqlite v1.4.7
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible
github.com/robfig/cron/v3 v3.0.1
github.com/satori/go.uuid v1.2.0
github.com/shirou/gopsutil/v3 v3.21.10
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cast v1.4.1
github.com/shirou/gopsutil/v3 v3.22.8
github.com/sirupsen/logrus v1.9.0
github.com/spf13/cast v1.5.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.10.1
github.com/spf13/viper v1.13.0
github.com/syndtr/goleveldb v1.0.0
github.com/tidwall/gjson v1.11.0
github.com/tidwall/gjson v1.14.3
github.com/wcharczuk/go-chart/v2 v2.1.0
github.com/wdvxdr1123/ZeroBot v1.4.1
gorm.io/driver/mysql v1.3.2
gorm.io/driver/postgres v1.3.1
gorm.io/gorm v1.23.1
github.com/wdvxdr1123/ZeroBot v1.5.1
gorm.io/driver/mysql v1.3.6
gorm.io/driver/postgres v1.3.10
gorm.io/gorm v1.23.10
)

require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/RomiChan/websocket v1.4.3-0.20220123145318-307a86b127bc // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/chromedp/cdproto v0.0.0-20211126220118-81fa0469ad77 // indirect
github.com/chromedp/cdproto v0.0.0-20220924210414-0e3390be1777 // indirect
github.com/chromedp/sysutil v1.0.0 // indirect
github.com/glebarez/go-sqlite v1.14.7 // indirect
github.com/glebarez/go-sqlite v1.18.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gobwas/httphead v0.1.0 // indirect
github.com/gobwas/pool v0.2.1 // indirect
github.com/gobwas/ws v1.1.0 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.10.1 // indirect
github.com/jackc/pgconn v1.13.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.2.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.9.1 // indirect
github.com/jackc/pgx/v4 v4.14.1 // indirect
github.com/jackc/pgtype v1.12.0 // indirect
github.com/jackc/pgx/v4 v4.17.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/lestrrat-go/strftime v1.0.5 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/lestrrat-go/strftime v1.0.6 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pkg/errors v0.8.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/remyoudompheng/bigfft v0.0.0-20220927061507-ef77025ab5aa // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 // indirect
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8 // indirect
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.5.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect
golang.org/x/image v0.0.0-20220902085622-e7cb96979f69 // indirect
golang.org/x/net v0.0.0-20220926192436-02166a98028e // indirect
golang.org/x/sys v0.0.0-20220926163933-8cfa568d3c25 // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
modernc.org/libc v1.14.3 // indirect
modernc.org/mathutil v1.4.1 // indirect
modernc.org/memory v1.0.5 // indirect
modernc.org/sqlite v1.14.5 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.20.0 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.4.0 // indirect
modernc.org/sqlite v1.19.1 // indirect
)
3 changes: 2 additions & 1 deletion plugins/admin/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

var info = manager.PluginInfo{
Expand Down Expand Up @@ -134,7 +135,7 @@ func getCancelWholeBanFunc(groupID int64) func() {
func muteReply(ctx *zero.Ctx) {
replyID := cast.ToInt64(ctx.State["reply_id"])
// 追溯消息
msg := ctx.GetMessage(replyID)
msg := ctx.GetMessage(message.NewMessageIDFromInteger(replyID))
if msg.Sender == nil {
ctx.Send("消息失效了")
return
Expand Down
8 changes: 4 additions & 4 deletions plugins/idioms/guess.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ func guessIdioms(ctx *zero.Ctx) {
if e == nil {
return
}
guess := strings.TrimSpace(e.Message.ExtractPlainText())
guess := strings.TrimSpace(e.Event.Message.ExtractPlainText())
if guess == key { // 猜对,结束游戏
ctx.SendChain(message.At(e.UserID), message.Text("猜对啦"))
addSuccess(e.GroupID, e.UserID)
ctx.SendChain(message.At(e.Event.UserID), message.Text("猜对啦"))
addSuccess(e.Event.GroupID, e.Event.UserID)
return
} else if utils.StringSliceContain(cancelMessage, guess) { // 取消,结束游戏
ctx.SendChain(message.At(e.UserID), message.Text(fmt.Sprintf("那算啦,其实正确答案是%v哦", key)))
ctx.SendChain(message.At(e.Event.UserID), message.Text(fmt.Sprintf("那算啦,其实正确答案是%v哦", key)))
return
} else { // 猜错,继续游戏
if ctx.Event.GroupID == 0 { // 只有私聊提示
Expand Down
4 changes: 3 additions & 1 deletion plugins/keyword/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import (

"github.com/RicheyJang/PaimengBot/manager"
"github.com/RicheyJang/PaimengBot/utils"
"github.com/spf13/cast"

"github.com/fsnotify/fsnotify"
log "github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

var info = manager.PluginInfo{
Expand Down Expand Up @@ -75,7 +77,7 @@ func msgHandler(ctx *zero.Ctx) {
log.Infof(`触发关键词"%v",撤回消息ID:%v`, ctx.State["keyword"], ctx.Event.MessageID)
ctx.Block()
ctx.Send("嘘!")
ctx.DeleteMessage(ctx.Event.MessageID)
ctx.DeleteMessage(message.NewMessageIDFromInteger(cast.ToInt64(ctx.Event.MessageID)))
}
// 其它处理
}
Expand Down
9 changes: 3 additions & 6 deletions plugins/pixiv/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (d *downloader) get() {
d.has = true
// 从getter获取图片信息
sum := 0
for k, _ := range getterMap {
for k := range getterMap {
sum += int(proxy.GetConfigInt64(fmt.Sprintf("scale.%s", k)))
}
for k, getter := range getterMap {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (d *downloader) send(ctx *zero.Ctx) {
}

// 处理图片消息的撤回
func dealWithdraw(msgID int64) {
func dealWithdraw(msgID message.MessageID) {
withdraw := proxy.GetConfigString("withdraw")
if len(withdraw) == 0 || withdraw == "0" {
return
Expand Down Expand Up @@ -325,8 +325,5 @@ func isCNOrEn(str string) bool {
return true
}
}
if asciiReg.MatchString(str) {
return true
}
return false
return asciiReg.MatchString(str)
}
5 changes: 3 additions & 2 deletions plugins/withdraw/withdraw.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)

var info = manager.PluginInfo{
Expand All @@ -33,12 +34,12 @@ func withDrawMsg(ctx *zero.Ctx) {
log.Warn("get reply id = 0")
return
}
msg := ctx.GetMessage(replyID)
msg := ctx.GetMessage(message.NewMessageIDFromInteger(cast.ToInt64(replyID)))
// 检查是否为机器人本人消息
//if msg.Sender != nil && msg.Sender.ID != 0 && msg.Sender.ID != ctx.Event.SelfID {
// ctx.Send(fmt.Sprintf("%v只能撤回%v自己发出的消息哦", utils.GetBotNickname(), utils.GetBotNickname()))
// return
//}
ctx.DeleteMessage(replyID)
ctx.DeleteMessage(message.NewMessageIDFromInteger(cast.ToInt64(replyID)))
log.Infof("撤回消息 %v (id=%v)", utils.JsonString(msg), replyID)
}
2 changes: 1 addition & 1 deletion pre_works.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func flushMainConfig(configPath string, configFileName string) error {
}
viper.WatchConfig()
viper.OnConfigChange(func(e fsnotify.Event) { // 配置文件发生变更之后会调用的回调函数
zero.BotConfig.SuperUsers = viper.GetStringSlice("superuser")
zero.BotConfig.SuperUsers = utils.StringSlice2int64Slice(viper.GetStringSlice("superuser"))
zero.BotConfig.NickName = []string{viper.GetString("nickname")}
_ = setupLogger()
log.Infof("reload main config from %v", e.Name)
Expand Down
19 changes: 18 additions & 1 deletion utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"unicode/utf8"

log "github.com/sirupsen/logrus"
"github.com/spf13/cast"
)

func GoAndWait(handlers ...func() error) (err error) {
Expand Down Expand Up @@ -59,7 +60,7 @@ func StringLimit(s string, limit int) string {
// MergeStringSlices 合并多个字符串切片并去重、去除空字符串
func MergeStringSlices(slices ...[]string) (res []string) {
mp := FormSetByStrings(slices...)
for s, _ := range mp {
for s := range mp {
if len(s) == 0 {
continue
}
Expand Down Expand Up @@ -154,3 +155,19 @@ func BytesToUInt32(b []byte) uint32 {
}
return binary.LittleEndian.Uint32(b)
}

//将int切片转换为int64切片
func IntSlice2int64Slice(slice []int) (newslice []int64) {
for i := 0; i < len(slice); i++ {
newslice = append(newslice, int64(slice[i]))
}
return
}

//将string切片转换为int64切片
func StringSlice2int64Slice(slice []string) (newslice []int64) {
for i := 0; i < len(slice); i++ {
newslice = append(newslice, cast.ToInt64(slice[i]))
}
return
}
18 changes: 6 additions & 12 deletions utils/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"fmt"
"io"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -83,7 +82,7 @@ func WaitNextMessage(ctx *zero.Ctx) *zero.Event {
defer cancel()
select {
case e := <-r:
return e
return e.Event
case <-t.C: // 超时取消
return nil
}
Expand All @@ -97,10 +96,10 @@ func GetConfirm(tip string, ctx *zero.Ctx) bool {
return false
}
confirm := strings.TrimSpace(event.Message.ExtractPlainText())
if !(confirm == "是" || confirm == "确定" || confirm == "确认") {
return false
if confirm == "是" || confirm == "确定" || confirm == "确认" {
return true
}
return true
return false
}

// GetImageURL 通过消息获取其中的图片URL
Expand Down Expand Up @@ -265,9 +264,8 @@ func GetBotID() int64 {

// IsSuperUser userID是否为超级用户
func IsSuperUser(userID int64) bool {
uid := strconv.FormatInt(userID, 10)
for _, su := range GetBotConfig().SuperUsers {
if su == uid {
if su == userID {
return true
}
}
Expand All @@ -279,11 +277,7 @@ func SendToSuper(message ...message.MessageSegment) {
supers := GetBotConfig().SuperUsers
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
for _, user := range supers {
userID, err := strconv.ParseInt(user, 10, 64)
if err != nil {
continue
}
ctx.SendPrivateMessage(userID, message)
ctx.SendPrivateMessage(user, message)
}
return true
})
Expand Down