Skip to content

Commit 70f71d8

Browse files
authored
Merge branch 'sealdice:master' into JS
2 parents fed9e0a + abc9f4f commit 70f71d8

8 files changed

Lines changed: 221 additions & 82 deletions

File tree

.github/workflows/pr-title-checker.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
check:
13+
if: ${{ github.repository == 'sealdice/sealdice-core' }}
1314
permissions:
1415
checks: write
1516
contents: read
@@ -30,12 +31,12 @@ jobs:
3031
header: 'PR Title Check'
3132
recreate: true
3233
message: |
33-
### 🚨 PR Title Needs Formatting
34-
The title of this PR needs to be formatted correctly.
35-
Please update the title to match the format `type: description`. Examples:
36-
- `fix: fix typo in README.md
37-
- `chore: update dependencies`
38-
- `feat: add new feature`
39-
- `chore: fixing build pipeline`
40-
- etc.
41-
More information can be found [here](https://www.conventionalcommits.org/zh-hans/v1.0.0/).
34+
### 🚨 PR Title Needs Formatting
35+
The title of this PR needs to be formatted correctly.
36+
Please update the title to match the format `type: description`. Examples:
37+
- `fix: fix typo in README.md
38+
- `chore: update dependencies`
39+
- `feat: add new feature`
40+
- `chore: fixing build pipeline`
41+
- etc.
42+
More information can be found [here](https://www.conventionalcommits.org/zh-hans/v1.0.0/).

api/conn.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ func ImConnectionsSetData(c echo.Context) error {
111111
if i.ID != v.ID {
112112
continue
113113
}
114-
if i.ProtocolType == "walle-q" {
114+
switch i.ProtocolType {
115+
case "walle-q":
115116
ad := i.Adapter.(*dice.PlatformAdapterWalleQ)
116117
ad.SetQQProtocol(v.Protocol)
117118
ad.IgnoreFriendRequest = v.IgnoreFriendRequest
118-
} else {
119+
case "milky":
120+
ad := i.Adapter.(*dice.PlatformAdapterMilky)
121+
ad.IgnoreFriendRequest = v.IgnoreFriendRequest
122+
default:
119123
ad := i.Adapter.(*dice.PlatformAdapterGocq)
120124
if i.ProtocolType != "onebot" {
121125
i.ProtocolType = "onebot"

dice/im_helpers.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"golang.org/x/time/rate"
1111

1212
ds "github.com/sealdice/dicescript"
13+
14+
"sealdice-core/logger"
15+
"sealdice-core/utils/panicHandler"
1316
)
1417

1518
var (
@@ -166,13 +169,24 @@ func replyToSenderRawNoCheck(ctx *MsgContext, msg *Message, text string, flag st
166169
replyPersonRawNoCheck(ctx, msg, text, flag)
167170
}
168171
}
169-
170172
func ReplyToSender(ctx *MsgContext, msg *Message, text string) {
171-
go ReplyToSenderRaw(ctx, msg, text, "")
173+
if ctx == nil || msg == nil || ctx.Dice == nil {
174+
logger.M().Errorf("ReplyToSender 被调用,但没有正确传递参数!请检查您的参数!: ctx=%v, msg=%v", ctx, msg)
175+
return
176+
}
177+
panicHandler.Once(logger.M(), func() {
178+
ReplyToSenderRaw(ctx, msg, text, "")
179+
})
172180
}
173181

174182
func ReplyToSenderNoCheck(ctx *MsgContext, msg *Message, text string) {
175-
go replyToSenderRawNoCheck(ctx, msg, text, "")
183+
if ctx == nil || msg == nil || ctx.Dice == nil {
184+
logger.M().Errorf("ReplyToSenderNoCheck 被调用,但没有正确传递参数!请检查您的参数!: ctx=%v, msg=%v", ctx, msg)
185+
return
186+
}
187+
panicHandler.Once(logger.M(), func() {
188+
replyToSenderRawNoCheck(ctx, msg, text, "")
189+
})
176190
}
177191

178192
func ReplyGroupRaw(ctx *MsgContext, msg *Message, text string, flag string) {

dice/platform_adapter_milky.go

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package dice
22

33
import (
44
"fmt"
5+
"math/rand/v2"
56
"path/filepath"
7+
"regexp"
68
"strconv"
79
"strings"
810
"time"
@@ -16,12 +18,13 @@ import (
1618
)
1719

1820
type PlatformAdapterMilky struct {
19-
Session *IMSession `json:"-" yaml:"-"`
20-
EndPoint *EndPointInfo `json:"-" yaml:"-"`
21-
WsGateway string `json:"ws_gateway" yaml:"ws_gateway"`
22-
RestGateway string `json:"rest_gateway" yaml:"rest_gateway"`
23-
Token string `json:"token" yaml:"token"`
24-
IntentSession *milky.Session `json:"-" yaml:"-"`
21+
Session *IMSession `json:"-" yaml:"-"`
22+
EndPoint *EndPointInfo `json:"-" yaml:"-"`
23+
IntentSession *milky.Session `json:"-" yaml:"-"`
24+
WsGateway string `json:"ws_gateway" yaml:"ws_gateway"`
25+
RestGateway string `json:"rest_gateway" yaml:"rest_gateway"`
26+
Token string `json:"token" yaml:"token"`
27+
IgnoreFriendRequest bool `json:"ignore_friend_request" yaml:"ignore_friend_request"`
2528
}
2629

2730
func (pa *PlatformAdapterMilky) SendSegmentToGroup(ctx *MsgContext, groupID string, msg []message.IMessageElement, flag string) {
@@ -238,6 +241,12 @@ func (pa *PlatformAdapterMilky) Serve() int {
238241
}
239242
}
240243
})
244+
session.AddHandler(func(session2 *milky.Session, m *milky.FriendRequest) {
245+
if m == nil {
246+
ctx := &MsgContext{MessageType: "private", EndPoint: pa.EndPoint, Session: pa.Session, Dice: pa.Session.Parent}
247+
pa.handelFriendRequest(ctx, m)
248+
}
249+
})
241250
d := pa.Session.Parent
242251
err = pa.IntentSession.Open()
243252
if err != nil {
@@ -270,6 +279,101 @@ func (pa *PlatformAdapterMilky) Serve() int {
270279
return 0
271280
}
272281

282+
func (pa *PlatformAdapterMilky) handelFriendRequest(ctx *MsgContext, event *milky.FriendRequest) {
283+
log := zap.S().Named(logger.LogKeyAdapter)
284+
var comment string
285+
if event.Comment != "" {
286+
comment = strings.TrimSpace(event.Comment)
287+
comment = strings.ReplaceAll(comment, "\u00a0", "")
288+
}
289+
290+
toMatch := strings.TrimSpace(pa.Session.Parent.Config.FriendAddComment)
291+
willAccept := comment == DiceFormat(ctx, toMatch)
292+
if toMatch == "" {
293+
willAccept = true
294+
}
295+
296+
if !willAccept {
297+
// 如果是问题校验,只填写回答即可
298+
re := regexp.MustCompile(`\n回答:([^\n]+)`)
299+
m := re.FindAllStringSubmatch(comment, -1)
300+
301+
var items []string
302+
for _, i := range m {
303+
items = append(items, i[1])
304+
}
305+
306+
re2 := regexp.MustCompile(`\s+`)
307+
m2 := re2.Split(toMatch, -1)
308+
309+
if len(m2) == len(items) {
310+
ok := true
311+
for i := range m2 {
312+
if m2[i] != items[i] {
313+
ok = false
314+
break
315+
}
316+
}
317+
willAccept = ok
318+
}
319+
}
320+
321+
if comment == "" {
322+
comment = "(无)"
323+
} else {
324+
comment = strconv.Quote(comment)
325+
}
326+
327+
// 检查黑名单
328+
extra := ""
329+
uid := FormatDiceIDQQ(strconv.FormatInt(event.InitiatorID, 10))
330+
banInfo, ok := ctx.Dice.Config.BanList.GetByID(uid)
331+
if ok {
332+
if banInfo.Rank == BanRankBanned && ctx.Dice.Config.BanList.BanBehaviorRefuseInvite {
333+
if willAccept {
334+
extra = "。回答正确,但为被禁止用户,准备自动拒绝"
335+
} else {
336+
extra = "。回答错误,且为被禁止用户,准备自动拒绝"
337+
}
338+
willAccept = false
339+
}
340+
}
341+
342+
if pa.IgnoreFriendRequest {
343+
extra += "。由于设置了忽略邀请,此信息仅为通报"
344+
}
345+
346+
txt := fmt.Sprintf("收到QQ好友邀请: 邀请人:%s, 验证信息: %s, 是否自动同意: %t%s", strconv.FormatInt(event.InitiatorID, 10), comment, willAccept, extra)
347+
log.Info(txt)
348+
ctx.Notice(txt)
349+
350+
// 忽略邀请
351+
if pa.IgnoreFriendRequest {
352+
return
353+
}
354+
355+
time.Sleep(time.Duration((0.8 + rand.Float64()) * float64(time.Second)))
356+
357+
if willAccept {
358+
pa.SetFriendAddRequest(event.InitiatorUID, true, "")
359+
} else {
360+
pa.SetFriendAddRequest(event.InitiatorUID, false, "验证信息不符")
361+
}
362+
}
363+
364+
func (pa *PlatformAdapterMilky) SetFriendAddRequest(initiatorUid string, approve bool, reason string) {
365+
log := zap.S().Named(logger.LogKeyAdapter)
366+
if approve {
367+
// 同意好友请求,目前都是 unfiltered 的
368+
err := pa.IntentSession.AcceptFriendRequest(initiatorUid, false)
369+
if err != nil {
370+
log.Errorf("Failed to accept friend request: %v", err)
371+
return
372+
}
373+
}
374+
// 拒绝好友请求,目前直接忽略
375+
}
376+
273377
func (pa *PlatformAdapterMilky) DoRelogin() bool {
274378
log := zap.S().Named(logger.LogKeyAdapter)
275379
if pa.IntentSession == nil {

go.mod

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/Milly/go-base2048 v0.1.0
88
github.com/ShiraazMoollatjie/goluhn v0.0.0-20211017190329-0d86158c056a
99
github.com/Szzrain/DingTalk-go v0.0.8-alpha
10-
github.com/Szzrain/Milky-go-sdk v0.3.9
10+
github.com/Szzrain/Milky-go-sdk v0.4.0
1111
github.com/Szzrain/dodo-open-go v0.2.8
1212
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
1313
github.com/alexmullins/zip v0.0.0-20180717182244-4affb64b04d0
@@ -53,6 +53,7 @@ require (
5353
github.com/ncruces/go-sqlite3/gormlite v0.24.0
5454
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.9.1
5555
github.com/otiai10/copy v1.14.1
56+
github.com/panjf2000/ants/v2 v2.11.3
5657
github.com/parquet-go/parquet-go v0.25.1
5758
github.com/pelletier/go-toml/v2 v2.2.4
5859
github.com/phuslu/log v1.0.119
@@ -80,7 +81,7 @@ require (
8081
golang.org/x/crypto v0.42.0
8182
golang.org/x/exp v0.0.0-20250911091902-df9299821621
8283
golang.org/x/sys v0.36.0
83-
golang.org/x/text v0.29.0
84+
golang.org/x/text v0.30.0
8485
golang.org/x/time v0.13.0
8586
gopkg.in/elazarl/goproxy.v1 v1.0.0-20180725130230-947c36da3153
8687
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
@@ -117,10 +118,6 @@ require (
117118
github.com/blevesearch/zapx/v14 v14.4.2 // indirect
118119
github.com/blevesearch/zapx/v15 v15.4.2 // indirect
119120
github.com/blevesearch/zapx/v16 v16.2.4 // indirect
120-
github.com/cilium/ebpf v0.19.0 // indirect
121-
github.com/cosiner/argv v0.1.0 // indirect
122-
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
123-
github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d // indirect
124121
github.com/dlclark/regexp2 v1.11.5 // indirect
125122
github.com/dolthub/maphash v0.1.0 // indirect
126123
github.com/elazarl/goproxy v0.0.0-20230808193330-2592e75ae04a // indirect
@@ -133,8 +130,6 @@ require (
133130
github.com/getlantern/hex v0.0.0-20220104173244-ad7e4b9194dc // indirect
134131
github.com/getlantern/hidden v0.0.0-20220104173330-f221c5a24770 // indirect
135132
github.com/getlantern/ops v0.0.0-20231025133620-f368ab734534 // indirect
136-
github.com/go-delve/delve v1.25.2 // indirect
137-
github.com/go-delve/liner v1.2.3-0.20231231155935-4726ab1d7f62 // indirect
138133
github.com/go-logr/logr v1.4.3 // indirect
139134
github.com/go-logr/stdr v1.2.2 // indirect
140135
github.com/go-ole/go-ole v1.3.0 // indirect
@@ -148,13 +143,10 @@ require (
148143
github.com/godbus/dbus/v5 v5.1.0 // indirect
149144
github.com/golang/protobuf v1.5.4 // indirect
150145
github.com/golang/snappy v1.0.0 // indirect
151-
github.com/google/go-dap v0.12.0 // indirect
152146
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
153-
github.com/hashicorp/golang-lru v1.0.2 // indirect
154147
github.com/hhrutter/lzw v1.0.0 // indirect
155148
github.com/hhrutter/pkcs7 v0.2.0 // indirect
156149
github.com/hhrutter/tiff v1.0.2 // indirect
157-
github.com/inconshreveable/mousetrap v1.1.0 // indirect
158150
github.com/jackc/pgpassfile v1.0.0 // indirect
159151
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
160152
github.com/jackc/pgx/v5 v5.7.5 // indirect
@@ -177,19 +169,15 @@ require (
177169
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 // indirect
178170
github.com/otiai10/mint v1.6.3 // indirect
179171
github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect
180-
github.com/panjf2000/ants/v2 v2.11.3 // indirect
181172
github.com/pdfcpu/pdfcpu v0.11.0 // indirect
182173
github.com/pierrec/lz4/v4 v4.1.22 // indirect
183174
github.com/richardlehane/mscfb v1.0.4 // indirect
184175
github.com/richardlehane/msoleps v1.0.4 // indirect
185176
github.com/rivo/uniseg v0.4.7 // indirect
186177
github.com/rogpeppe/go-internal v1.14.1 // indirect
187-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
188178
github.com/sacOO7/go-logger v0.0.0-20180719173527-9ac9add5a50d // indirect
189179
github.com/sergeymakinen/go-bmp v1.0.0 // indirect
190180
github.com/sergeymakinen/go-ico v1.0.0-beta.0 // indirect
191-
github.com/spf13/cobra v1.10.1 // indirect
192-
github.com/spf13/pflag v1.0.10 // indirect
193181
github.com/sunshineplan/pdf v1.0.8 // indirect
194182
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
195183
github.com/tdewolff/parse/v2 v2.8.3 // indirect
@@ -209,14 +197,11 @@ require (
209197
go.opentelemetry.io/otel v1.37.0 // indirect
210198
go.opentelemetry.io/otel/metric v1.37.0 // indirect
211199
go.opentelemetry.io/otel/trace v1.37.0 // indirect
212-
go.starlark.net v0.0.0-20250906160240-bf296ed553ea // indirect
213200
go.uber.org/multierr v1.11.0 // indirect
214-
golang.org/x/arch v0.21.0 // indirect
215201
golang.org/x/image v0.29.0 // indirect
216202
golang.org/x/mod v0.28.0 // indirect
217203
golang.org/x/net v0.43.0 // indirect
218204
golang.org/x/sync v0.17.0 // indirect
219-
golang.org/x/telemetry v0.0.0-20250908211612-aef8a434d053 // indirect
220205
golang.org/x/term v0.35.0 // indirect
221206
google.golang.org/appengine v1.6.8 // indirect
222207
google.golang.org/protobuf v1.36.6 // indirect

0 commit comments

Comments
 (0)