Skip to content

Commit 2fd394c

Browse files
committed
✨ adapt to qq
1 parent 49b7293 commit 2fd394c

9 files changed

Lines changed: 52 additions & 41 deletions

File tree

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/FloatTech/zbpctrl v1.6.0
1313
github.com/FloatTech/zbputils v1.7.1-0.20231017135158-7e6c839764eb
1414
github.com/disintegration/imaging v1.6.2
15-
github.com/fumiama/NanoBot v0.0.0-20231116150429-c9ba2f735069
15+
github.com/fumiama/NanoBot v0.0.0-20231117050254-594c9fddfe7c
1616
github.com/fumiama/go-base16384 v1.7.0
1717
github.com/fumiama/go-registry v0.2.6
1818
github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430
@@ -37,6 +37,7 @@ require (
3737
github.com/fumiama/go-simple-protobuf v0.1.0 // indirect
3838
github.com/fumiama/gofastTEA v0.0.10 // indirect
3939
github.com/fumiama/imgsz v0.0.2 // indirect
40+
github.com/fumiama/imoto v0.1.3 // indirect
4041
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 // indirect
4142
github.com/go-ole/go-ole v1.2.6 // indirect
4243
github.com/google/uuid v1.3.0 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 h1:BBade+Jl
3636
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM=
3737
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
3838
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
39-
github.com/fumiama/NanoBot v0.0.0-20231116150429-c9ba2f735069 h1:uwCFQhF24TEYh3h3rWc++vZBAYbl9+hwJ/Q6MOYXbdQ=
40-
github.com/fumiama/NanoBot v0.0.0-20231116150429-c9ba2f735069/go.mod h1:kpkfUjFBbYdjiYyaNMZjSM3i4Gy4BTlbSSocRIoSSXQ=
39+
github.com/fumiama/NanoBot v0.0.0-20231117050254-594c9fddfe7c h1:V27WwUqocpnwRejN+tyVjlZgARm04LQ+TBsd6mbp640=
40+
github.com/fumiama/NanoBot v0.0.0-20231117050254-594c9fddfe7c/go.mod h1:z9IDRRwntGIrnnxcwgjVge7lUa2GkGWFT7F1uYZbvh8=
4141
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE=
4242
github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
4343
github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo=
@@ -52,6 +52,8 @@ github.com/fumiama/gofastTEA v0.0.10 h1:JJJ+brWD4kie+mmK2TkspDXKzqq0IjXm89aGYfoG
5252
github.com/fumiama/gofastTEA v0.0.10/go.mod h1:RIdbYZyB4MbH6ZBlPymRaXn3cD6SedlCu5W/HHfMPBk=
5353
github.com/fumiama/imgsz v0.0.2 h1:fAkC0FnIscdKOXwAxlyw3EUba5NzxZdSxGaq3Uyfxak=
5454
github.com/fumiama/imgsz v0.0.2/go.mod h1:dR71mI3I2O5u6+PCpd47M9TZptzP+39tRBcbdIkoqM4=
55+
github.com/fumiama/imoto v0.1.3 h1:7KNVUIVaLWerdZZ6i83dAvcLoeqzlGhrY2MSjqWTxlY=
56+
github.com/fumiama/imoto v0.1.3/go.mod h1:1MLP+qfEbhZOn+ETXd6k0xkjMyNGuqnaiblcQuWu9NQ=
5557
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565 h1:sQuR2+N5HurnvsZhiKdEg+Ig354TaqgCQRxd/0KgIOQ=
5658
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565/go.mod h1:UUEvyLTJ7yoOA/viKG4wEis4ERydM7+Ny6gZUWgkS80=
5759
github.com/fumiama/sqlite3 v1.20.0-with-win386 h1:ZR1AXGBEtkfq9GAXehOVcwn+aaCG8itrkgEsz4ggx5k=

plugin/fortune/fortune.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func init() {
5656
PublicDataFolder: "Fortune",
5757
}).ApplySingle(nano.NewSingle(
5858
nano.WithKeyFn(func(ctx *nano.Ctx) int64 {
59-
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64)
59+
gid := ctx.GroupID()
6060
return int64(gid)
6161
}),
6262
nano.WithPostFn[int64](func(ctx *nano.Ctx) {
@@ -72,7 +72,7 @@ func init() {
7272
}
7373
en.OnMessageRegex(`^设置底图\s?(.*)`).SetBlock(true).
7474
Handle(func(ctx *nano.Ctx) {
75-
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64)
75+
gid := ctx.GroupID()
7676
i, ok := index[ctx.State["regex_matched"].([]string)[1]]
7777
if ok {
7878
c, ok := ctx.State["manager"].(*ctrl.Control[*nano.Ctx])
@@ -113,7 +113,7 @@ func init() {
113113
Handle(func(ctx *nano.Ctx) {
114114
// 获取该群背景类型,默认车万
115115
kind := "车万"
116-
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64)
116+
gid := ctx.GroupID()
117117
logrus.Debugln("[fortune]gid:", ctx.Message.ChannelID, "uid:", ctx.Message.Author.ID)
118118
c, ok := ctx.State["manager"].(*ctrl.Control[*nano.Ctx])
119119
if ok {
@@ -130,7 +130,7 @@ func init() {
130130
return
131131
}
132132

133-
uid, _ := strconv.ParseUint(ctx.Message.Author.ID, 10, 64)
133+
uid := ctx.UserID()
134134

135135
// 随机获取背景
136136
background, index, err := randimage(zipfile, int64(uid))

plugin/genshin/ys.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"image/png"
1111
"math/rand"
1212
"regexp"
13-
"strconv"
1413
"strings"
1514
"sync/atomic"
1615

@@ -50,7 +49,7 @@ func init() {
5049
_, _ = ctx.SendPlainMessage(false, "找不到服务!")
5150
return
5251
}
53-
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64)
52+
gid := ctx.GroupID()
5453
store := (storage)(c.GetData(int64(gid)))
5554
if store.setmode(!store.is5starsmode()) {
5655
process.SleepAbout1sTo2s()
@@ -88,7 +87,7 @@ func init() {
8887
_, _ = ctx.SendPlainMessage(false, "找不到服务!")
8988
return
9089
}
91-
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64)
90+
gid := ctx.GroupID()
9291
store := (storage)(c.GetData(int64(gid)))
9392
img, str, mode, err := randnums(10, store)
9493
if err != nil {

plugin/qqwife/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package qqwife
33

44
import (
55
"math/rand"
6-
"strconv"
76
"strings"
87

98
"github.com/FloatTech/NanoBot-Plugin/utils/ctxext"
@@ -37,8 +36,7 @@ var (
3736
PrivateDataFolder: "qqwife",
3837
}).ApplySingle(nano.NewSingle(
3938
nano.WithKeyFn(func(ctx *nano.Ctx) int64 {
40-
gid, _ := strconv.ParseUint(ctx.Message.GuildID, 10, 64)
41-
return int64(gid)
39+
return int64(ctx.GroupID())
4240
}),
4341
nano.WithPostFn[int64](func(ctx *nano.Ctx) {
4442
_, _ = ctx.SendPlainMessage(true, "别着急,民政局门口排长队了!")

plugin/score/sign_in.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"math"
66
"math/rand"
77
"os"
8-
"strconv"
98
"strings"
109
"time"
1110

@@ -68,7 +67,7 @@ func init() {
6867
_, _ = ctx.SendPlainMessage(false, "ERROR: 未获取到用户uid")
6968
return
7069
}
71-
uidint, _ := strconv.ParseUint(uid, 10, 64)
70+
uidint := ctx.UserID()
7271
today := time.Now().Format("20060102")
7372
// 签到图片
7473
drawedFile := cachePath + uid + today + "signin.png"

plugin/wife/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package wife
44
import (
55
"encoding/json"
66
"os"
7-
"strconv"
87
"strings"
98

109
"github.com/FloatTech/NanoBot-Plugin/utils/ctxext"
@@ -45,7 +44,7 @@ func init() {
4544
_, _ = ctx.SendPlainMessage(false, "ERROR: 未获取到用户")
4645
return
4746
}
48-
uidint, _ := strconv.ParseInt(uid, 10, 64)
47+
uidint := int64(ctx.UserID())
4948
card := cards[fcext.RandSenderPerDayN(uidint, len(cards))]
5049
data, err := engine.GetLazyData("wives/"+card, true)
5150
card, _, _ = strings.Cut(card, ".")

plugin/wordle/main.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"image/color"
88
"math/rand"
99
"sort"
10-
"strconv"
1110
"strings"
1211
"sync"
1312
"sync/atomic"
@@ -68,8 +67,7 @@ func init() {
6867
PublicDataFolder: "Wordle",
6968
}).ApplySingle(nano.NewSingle(
7069
nano.WithKeyFn(func(ctx *nano.Ctx) int64 {
71-
gid, _ := strconv.ParseUint(ctx.Message.ChannelID, 10, 64)
72-
return int64(gid)
70+
return int64(ctx.GroupID())
7371
}),
7472
nano.WithPostFn[int64](func(ctx *nano.Ctx) {
7573
_, _ = ctx.SendPlainMessage(true, "已经有正在进行的游戏了")
@@ -138,9 +136,9 @@ func init() {
138136
return
139137
}
140138
var next *nano.FutureEvent
141-
if ctx.State["regex_matched"].([]string)[1] == "团队" && !nano.OnlyDirect(ctx) {
139+
if ctx.State["regex_matched"].([]string)[1] == "团队" && !nano.OnlyPrivate(ctx) {
142140
next = nano.NewFutureEvent("Message", 999, false, nano.RegexRule(fmt.Sprintf(`^([A-Z]|[a-z]){%d}$`, class)),
143-
nano.OnlyChannel, nano.CheckChannel(ctx.Message.ChannelID))
141+
nano.OnlyPublic, nano.CheckChannel(ctx.Message.ChannelID))
144142
} else {
145143
next = nano.NewFutureEvent("Message", 999, false, nano.RegexRule(fmt.Sprintf(`^([A-Z]|[a-z]){%d}$`, class)),
146144
ctx.CheckSession())
@@ -167,7 +165,7 @@ func init() {
167165
case c := <-recv:
168166
tick.Reset(105 * time.Second)
169167
after.Reset(120 * time.Second)
170-
win, img, err = game(c.Message.Content)
168+
win, img, err = game(strings.TrimSpace(c.Message.Content))
171169
switch {
172170
case win:
173171
tick.Stop()

utils/ctxext/speed.go

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import (
1616
// 并发时返回 "您有操作正在执行, 请稍后再试!"
1717
var DefaultSingle = nano.NewSingle(
1818
nano.WithKeyFn(func(ctx *nano.Ctx) int64 {
19-
switch msg := ctx.Value.(type) {
19+
switch ctx.Value.(type) {
2020
case *nano.Message:
21-
id, _ := strconv.ParseUint(msg.Author.ID, 10, 64)
22-
return int64(id)
21+
return int64(ctx.UserID())
2322
}
2423
return 0
2524
}),
@@ -53,17 +52,26 @@ func SetDefaultLimiterManagerParam(interval time.Duration, burst int) {
5352
//
5453
// 按 发送者 限制
5554
func LimitByUser(ctx *nano.Ctx) *rate.Limiter {
56-
if msg, ok := ctx.Value.(*nano.Message); ok {
57-
id, _ := strconv.ParseUint(msg.Author.ID, 10, 64)
58-
return defaultLimiterManager.Load(int64(id))
55+
if _, ok := ctx.Value.(*nano.Message); ok {
56+
return defaultLimiterManager.Load(int64(ctx.UserID()))
5957
}
6058
return defaultLimiterManager.Load(0)
6159
}
6260

6361
// LimitByGroup 默认限速器 每 10s 5次触发
6462
//
65-
// 按 guild 限制
63+
// 按 group 限制
6664
func LimitByGroup(ctx *nano.Ctx) *rate.Limiter {
65+
if _, ok := ctx.Value.(*nano.Message); ok {
66+
return defaultLimiterManager.Load(int64(ctx.GroupID()))
67+
}
68+
return defaultLimiterManager.Load(0)
69+
}
70+
71+
// LimitByGuild 默认限速器 每 10s 5次触发
72+
//
73+
// 按 guild 限制
74+
func LimitByGuild(ctx *nano.Ctx) *rate.Limiter {
6775
if msg, ok := ctx.Value.(*nano.Message); ok {
6876
id, _ := strconv.ParseUint(msg.GuildID, 10, 64)
6977
return defaultLimiterManager.Load(int64(id))
@@ -75,9 +83,8 @@ func LimitByGroup(ctx *nano.Ctx) *rate.Limiter {
7583
//
7684
// 按 channel 限制
7785
func LimitByChannel(ctx *nano.Ctx) *rate.Limiter {
78-
if msg, ok := ctx.Value.(*nano.Message); ok {
79-
id, _ := strconv.ParseUint(msg.ChannelID, 10, 64)
80-
return defaultLimiterManager.Load(int64(id))
86+
if _, ok := ctx.Value.(*nano.Message); ok {
87+
return defaultLimiterManager.Load(int64(ctx.GroupID()))
8188
}
8289
return defaultLimiterManager.Load(0)
8390
}
@@ -97,31 +104,39 @@ func NewLimiterManager(interval time.Duration, burst int) (m LimiterManager) {
97104
//
98105
// 按 发送者 限制
99106
func (m LimiterManager) LimitByUser(ctx *nano.Ctx) *rate.Limiter {
100-
if msg, ok := ctx.Value.(*nano.Message); ok {
101-
id, _ := strconv.ParseUint(msg.Author.ID, 10, 64)
102-
return defaultLimiterManager.Load(int64(id))
107+
if _, ok := ctx.Value.(*nano.Message); ok {
108+
return defaultLimiterManager.Load(int64(ctx.UserID()))
103109
}
104110
return defaultLimiterManager.Load(0)
105111
}
106112

107-
// LimitByGroup 自定义限速器
113+
// LimitByGuild 自定义限速器
108114
//
109115
// 按 guild 限制
110-
func (m LimiterManager) LimitByGroup(ctx *nano.Ctx) *rate.Limiter {
116+
func (m LimiterManager) LimitByGuild(ctx *nano.Ctx) *rate.Limiter {
111117
if msg, ok := ctx.Value.(*nano.Message); ok {
112118
id, _ := strconv.ParseUint(msg.GuildID, 10, 64)
113119
return defaultLimiterManager.Load(int64(id))
114120
}
115121
return defaultLimiterManager.Load(0)
116122
}
117123

124+
// LimitByGroup 自定义限速器
125+
//
126+
// 按 group 限制
127+
func (m LimiterManager) LimitByGroup(ctx *nano.Ctx) *rate.Limiter {
128+
if _, ok := ctx.Value.(*nano.Message); ok {
129+
return defaultLimiterManager.Load(int64(ctx.GroupID()))
130+
}
131+
return defaultLimiterManager.Load(0)
132+
}
133+
118134
// LimitByChannel 自定义限速器
119135
//
120136
// 按 channel 限制
121137
func (m LimiterManager) LimitByChannel(ctx *nano.Ctx) *rate.Limiter {
122-
if msg, ok := ctx.Value.(*nano.Message); ok {
123-
id, _ := strconv.ParseUint(msg.ChannelID, 10, 64)
124-
return defaultLimiterManager.Load(int64(id))
138+
if _, ok := ctx.Value.(*nano.Message); ok {
139+
return defaultLimiterManager.Load(int64(ctx.GroupID()))
125140
}
126141
return defaultLimiterManager.Load(0)
127142
}

0 commit comments

Comments
 (0)