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

feat: 为 ExtInfo 添加入群和成为好友事件并适配 QQ #140

Merged
merged 4 commits into from
Jul 30, 2023
Merged
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
2 changes: 2 additions & 0 deletions dice/dice.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type ExtInfo struct {
OnMessageReceived func(ctx *MsgContext, msg *Message) `yaml:"-" json:"-" jsbind:"onMessageReceived"`
OnMessageSend func(ctx *MsgContext, msg *Message, flag string) `yaml:"-" json:"-" jsbind:"onMessageSend"`
OnMessageDeleted func(ctx *MsgContext, msg *Message) `yaml:"-" json:"-" jsbind:"onMessageDeleted"`
OnGroupJoined func(ctx *MsgContext, msg *Message) `yaml:"-" json:"-" jsbind:"onGroupJoined"`
OnBecomeFriend func(ctx *MsgContext, msg *Message) `yaml:"-" json:"-" jsbind:"onBecomeFriend"`
GetDescText func(i *ExtInfo) string `yaml:"-" json:"-" jsbind:"getDescText"`
IsLoaded bool `yaml:"-" json:"-" jsbind:"isLoaded"`
OnLoad func() `yaml:"-" json:"-" jsbind:"onLoad"`
Expand Down
17 changes: 17 additions & 0 deletions dice/im_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,18 @@ func (s *IMSession) Execute(ep *EndPointInfo, msg *Message, runInSync bool) {
ep.Adapter.GetGroupInfoAsync(msg.GroupId)
log.Info(txt)
mctx.Notice(txt)

if msg.Platform == "QQ" || msg.Platform == "TG" {
if mctx.Session.ServiceAtNew[msg.GroupId] != nil {
for _, i := range mctx.Session.ServiceAtNew[msg.GroupId].ActivatedExtList {
if i.OnGroupJoined != nil {
i.callWithJsCheck(mctx.Dice, func() {
i.OnGroupJoined(mctx, msg)
})
}
}
}
}
}

var mustLoadUser bool
Expand Down Expand Up @@ -1067,6 +1079,11 @@ func (ctx *MsgContext) Notice(txt string) {
}

for _, i := range ctx.Dice.NoticeIds {
seg := strings.Split(i, "-")[0]
if ctx.EndPoint.Platform != seg {
//ctx.Dice.Logger.Infof("Endpoint platform %s, ID platform %s", ctx.EndPoint.Platform, seg[0])
return
}
n := strings.Split(i, ":")
if len(n) >= 2 {
if strings.HasSuffix(n[0], "-Group") {
Expand Down
18 changes: 18 additions & 0 deletions dice/platform_adapter_qq.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,15 @@ func (pa *PlatformAdapterGocq) Serve() int {
doSleepQQ(ctx)
pa.SendToPerson(ctx, uid, strings.TrimSpace(i), "")
}
if ctx.Session.ServiceAtNew[msg.GroupId] != nil {
for _, i := range ctx.Session.ServiceAtNew[msg.GroupId].ActivatedExtList {
if i.OnBecomeFriend != nil {
i.callWithJsCheck(ctx.Dice, func() {
i.OnBecomeFriend(ctx, msg)
})
}
}
}
}()
return
}
Expand Down Expand Up @@ -620,6 +629,15 @@ func (pa *PlatformAdapterGocq) Serve() int {
txt := fmt.Sprintf("加入QQ群组: <%s>(%d)", groupName, msgQQ.GroupId)
log.Info(txt)
ctx.Notice(txt)
if ctx.Session.ServiceAtNew[msg.GroupId] != nil {
for _, i := range ctx.Session.ServiceAtNew[msg.GroupId].ActivatedExtList {
if i.OnGroupJoined != nil {
i.callWithJsCheck(ctx.Dice, func() {
i.OnGroupJoined(ctx, msg)
})
}
}
}
}

// 入群的另一种情况: 管理员审核
Expand Down
18 changes: 18 additions & 0 deletions dice/platform_adapter_telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ func (pa *PlatformAdapterTelegram) groupAdded(msg *Message, msgRaw *tgbotapi.Mes
for _, i := range strings.Split(text, "###SPLIT###") {
pa.SendToGroup(ctx, msg.GroupId, strings.TrimSpace(i), "")
}
if ctx.Session.ServiceAtNew[msg.GroupId] != nil {
for _, i := range ctx.Session.ServiceAtNew[msg.GroupId].ActivatedExtList {
if i.OnGroupJoined != nil {
i.callWithJsCheck(ctx.Dice, func() {
i.OnGroupJoined(ctx, msg)
})
}
}
}
}

func (pa *PlatformAdapterTelegram) friendAdded(msg *Message) {
Expand All @@ -157,6 +166,15 @@ func (pa *PlatformAdapterTelegram) friendAdded(msg *Message) {
for _, i := range strings.Split(welcome, "###SPLIT###") {
pa.SendToPerson(ctx, uid, strings.TrimSpace(i), "")
}
if ctx.Session.ServiceAtNew[msg.GroupId] != nil {
for _, i := range ctx.Session.ServiceAtNew[msg.GroupId].ActivatedExtList {
if i.OnBecomeFriend != nil {
i.callWithJsCheck(ctx.Dice, func() {
i.OnBecomeFriend(ctx, msg)
})
}
}
}
}

func (pa *PlatformAdapterTelegram) toStdMessage(m *tgbotapi.Message) *Message {
Expand Down
9 changes: 9 additions & 0 deletions dice/platform_adapter_walleq.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,15 @@ func (pa *PlatformAdapterWalleQ) Serve() int {
doSleepQQ(ctx)
pa.SendToGroup(ctx, msg.GroupId, strings.TrimSpace(i), "")
}
if ctx.Session.ServiceAtNew[msg.GroupId] != nil {
for _, i := range ctx.Session.ServiceAtNew[msg.GroupId].ActivatedExtList {
if i.OnGroupJoined != nil {
i.callWithJsCheck(ctx.Dice, func() {
i.OnGroupJoined(ctx, msg)
})
}
}
}
}()
txt := fmt.Sprintf("加入QQ群组: <%s>(%s)", groupName, event.GroupId)
log.Info(txt)
Expand Down
Loading