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

fix(qq): 修复强转gocq的adapter导致的panic #422

Merged
merged 2 commits into from
Nov 20, 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
3 changes: 1 addition & 2 deletions dice/dice_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ func (dm *DiceManager) Backup(cfg AllBackupConfig, bakFilename string) (string,
if cfg2.Accounts {
for _, i := range d.ImSession.EndPoints {
if i.Platform == "QQ" {
pa := i.Adapter.(*PlatformAdapterGocq)
if pa.UseInPackGoCqhttp {
if pa, ok := i.Adapter.(*PlatformAdapterGocq); ok && pa.UseInPackGoCqhttp {
backup(d, filepath.Join(d.BaseConfig.DataDir, i.RelWorkDir, "config.yml"))
backup(d, filepath.Join(d.BaseConfig.DataDir, i.RelWorkDir, "device.json"))
backup(d, filepath.Join(d.BaseConfig.DataDir, i.RelWorkDir, "session.token"))
Expand Down
12 changes: 11 additions & 1 deletion dice/dice_ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (i *BanListInfo) AfterLoads() {
// AddScoreBase
// 这一份ctx有endpoint就行
func (i *BanListInfo) AddScoreBase(uid string, score int64, place string, reason string, ctx *MsgContext) *BanListInfoItem {
log := i.Parent.Logger
v, _ := i.Map.Load(uid)
if v == nil {
v = &BanListInfoItem{
Expand Down Expand Up @@ -161,7 +162,16 @@ func (i *BanListInfo) AddScoreBase(uid string, score int64, place string, reason
v.BanTime = time.Now().Unix()

if ctx.EndPoint.Platform == "QQ" {
ctx.EndPoint.Adapter.(*PlatformAdapterGocq).DeleteFriend(ctx, place)
switch adapter := ctx.EndPoint.Adapter.(type) {
case *PlatformAdapterGocq:
adapter.DeleteFriend(ctx, place)
case *PlatformAdapterWalleQ:
adapter.DeleteFriend(ctx, place)
case *PlatformAdapterRed:
log.Warn("qq red 适配器不支持删除好友")
default:
JustAnotherID marked this conversation as resolved.
Show resolved Hide resolved
log.Error("unknown qq adapter")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions dice/platform_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ type PlatformAdapter interface {
MemberKick(groupID string, userID string)

GetGroupInfoAsync(groupID string)

// DeleteFriend 删除好友,目前只有 QQ 平台下的 gocq 和 walleq 实现有这个方法
// DeleteFriend(ctx *MsgContext, id string)
}
Loading