diff --git a/dice/ext_log.go b/dice/ext_log.go index 35132012..a55abd71 100644 --- a/dice/ext_log.go +++ b/dice/ext_log.go @@ -46,7 +46,7 @@ func SetPlayerGroupCardByTemplate(ctx *MsgContext, tmpl string) (string, error) return text, ErrGroupCardOverlong } - ctx.EndPoint.Adapter.SetGroupCardName(ctx.Group.GroupID, ctx.Player.UserID, text) + ctx.EndPoint.Adapter.SetGroupCardName(ctx, text) return text, nil } @@ -563,7 +563,7 @@ func RegisterBuiltinExtLog(self *Dice) { ctx.Player.Name = ctx.Player.Name[len("ob"):] ctx.Player.UpdatedAtTime = time.Now().Unix() } - ctx.EndPoint.Adapter.SetGroupCardName(ctx.Group.GroupID, ctx.Player.UserID, ctx.Player.Name) + ctx.EndPoint.Adapter.SetGroupCardName(ctx, ctx.Player.Name) text := DiceFormatTmpl(ctx, "日志:OB_关闭") ReplyToSender(ctx, msg, text) default: @@ -571,7 +571,7 @@ func RegisterBuiltinExtLog(self *Dice) { ctx.Player.Name = "ob" + ctx.Player.Name ctx.Player.UpdatedAtTime = time.Now().Unix() } - ctx.EndPoint.Adapter.SetGroupCardName(ctx.Group.GroupID, ctx.Player.UserID, ctx.Player.Name) + ctx.EndPoint.Adapter.SetGroupCardName(ctx, ctx.Player.Name) text := DiceFormatTmpl(ctx, "日志:OB_开启") ReplyToSender(ctx, msg, text) } diff --git a/dice/platform_adapter.go b/dice/platform_adapter.go index 61dc5c74..4e523839 100644 --- a/dice/platform_adapter.go +++ b/dice/platform_adapter.go @@ -8,7 +8,7 @@ type PlatformAdapter interface { SendToPerson(ctx *MsgContext, uid string, text string, flag string) SendToGroup(ctx *MsgContext, uid string, text string, flag string) - SetGroupCardName(groupID string, userID string, name string) + SetGroupCardName(ctx *MsgContext, name string) SendFileToPerson(ctx *MsgContext, uid string, path string, flag string) SendFileToGroup(ctx *MsgContext, uid string, path string, flag string) diff --git a/dice/platform_adapter_dingtalk.go b/dice/platform_adapter_dingtalk.go index cc8ba76f..39f1626f 100644 --- a/dice/platform_adapter_dingtalk.go +++ b/dice/platform_adapter_dingtalk.go @@ -108,7 +108,7 @@ func (pa *PlatformAdapterDingTalk) SendToGroup(ctx *MsgContext, uid string, text }, flag) } -func (pa *PlatformAdapterDingTalk) SetGroupCardName(groupID string, userID string, name string) { +func (pa *PlatformAdapterDingTalk) SetGroupCardName(ctx *MsgContext, name string) { } func (pa *PlatformAdapterDingTalk) SendFileToPerson(ctx *MsgContext, uid string, path string, flag string) { diff --git a/dice/platform_adapter_discord.go b/dice/platform_adapter_discord.go index 8db719a1..44e3da77 100644 --- a/dice/platform_adapter_discord.go +++ b/dice/platform_adapter_discord.go @@ -440,16 +440,11 @@ func (pa *PlatformAdapterDiscord) QuitGroup(_ *MsgContext, id string) { } // SetGroupCardName 没有改变用户在某个频道中昵称的功能,一旦更改就是整个服务器范围内都改 -func (pa *PlatformAdapterDiscord) SetGroupCardName(groupID string, userID string, name string) { - ch, err := pa.IntentSession.Channel(ExtractDiscordChannelID(groupID)) +func (pa *PlatformAdapterDiscord) SetGroupCardName(ctx *MsgContext, name string) { + guildID := ctx.Group.GuildID + err := pa.IntentSession.GuildMemberNickname(guildID, ExtractDiscordUserID(ctx.Player.UserID), name) if err != nil { - pa.Session.Parent.Logger.Errorf("获取Discord频道#%s信息时出错:%s", groupID, err.Error()) - return - } - guildID := ch.GuildID - err = pa.IntentSession.GuildMemberNickname(guildID, ExtractDiscordUserID(userID), name) - if err != nil { - pa.Session.Parent.Logger.Errorf("修改用户#%s在Discord服务器%s(来源频道#%s)的昵称时出错:%s", userID, guildID, groupID, err.Error()) + pa.Session.Parent.Logger.Errorf("修改用户#%s在Discord服务器%s(来源频道#%s)的昵称时出错:%s", ctx.Player.UserID, guildID, ctx.Group.GroupID, err.Error()) } } diff --git a/dice/platform_adapter_dodo.go b/dice/platform_adapter_dodo.go index 287d2c32..09cdb987 100644 --- a/dice/platform_adapter_dodo.go +++ b/dice/platform_adapter_dodo.go @@ -345,6 +345,22 @@ func ExtractDodoGroupID(id string) string { } return id } -func (pa *PlatformAdapterDodo) QuitGroup(_ *MsgContext, _ string) {} +func (pa *PlatformAdapterDodo) QuitGroup(ctx *MsgContext, groupId string) { + _, err := pa.Client.SetBotIslandLeave(context.Background(), &model.SetBotLeaveIslandReq{ + IslandSourceId: ctx.Group.GuildID, + }) + if err != nil { + pa.Session.Parent.Logger.Errorf("Dodo退群失败:%v", err) + } +} -func (pa *PlatformAdapterDodo) SetGroupCardName(_ string, _ string, _ string) {} +func (pa *PlatformAdapterDodo) SetGroupCardName(ctx *MsgContext, name string) { + _, err := pa.Client.SetMemberNick(context.Background(), &model.SetMemberNickReq{ + IslandSourceId: ctx.Group.GuildID, + DodoSourceId: ExtractDodoUserID(ctx.Player.UserID), + NickName: name, + }) + if err != nil { + pa.Session.Parent.Logger.Errorf("Dodo设置群名片失败:%v", err) + } +} diff --git a/dice/platform_adapter_gocq_actions.go b/dice/platform_adapter_gocq_actions.go index 8006dac1..6e92d6fd 100644 --- a/dice/platform_adapter_gocq_actions.go +++ b/dice/platform_adapter_gocq_actions.go @@ -458,12 +458,12 @@ func (pa *PlatformAdapterGocq) GetStrangerInfo(userID int64) *OnebotUserInfo { } } -func (pa *PlatformAdapterGocq) SetGroupCardName(groupID string, userID string, name string) { - groupIDRaw, idType := pa.mustExtractID(groupID) +func (pa *PlatformAdapterGocq) SetGroupCardName(ctx *MsgContext, name string) { + groupIDRaw, idType := pa.mustExtractID(ctx.Group.GroupID) if idType != QQUidGroup { return } - userIDRaw, idType := pa.mustExtractID(userID) + userIDRaw, idType := pa.mustExtractID(ctx.Player.UserID) if idType != QQUidPerson { return } diff --git a/dice/platform_adapter_http.go b/dice/platform_adapter_http.go index 2acedcef..d8990057 100644 --- a/dice/platform_adapter_http.go +++ b/dice/platform_adapter_http.go @@ -44,7 +44,7 @@ func (pa *PlatformAdapterHTTP) SendFileToGroup(ctx *MsgContext, uid string, path func (pa *PlatformAdapterHTTP) QuitGroup(_ *MsgContext, _ string) {} -func (pa *PlatformAdapterHTTP) SetGroupCardName(_ string, _ string, _ string) {} +func (pa *PlatformAdapterHTTP) SetGroupCardName(_ *MsgContext, _ string) {} func (pa *PlatformAdapterHTTP) MemberBan(_ string, _ string, _ int64) {} diff --git a/dice/platform_adapter_kook.go b/dice/platform_adapter_kook.go index 217c353f..742a359c 100644 --- a/dice/platform_adapter_kook.go +++ b/dice/platform_adapter_kook.go @@ -640,6 +640,13 @@ func ExtractKookChannelID(id string) string { return id } +func ExtractKookGuildID(id string) string { + if strings.HasPrefix(id, "KOOK-Guild:") { + return id[len("KOOK-Guild:"):] + } + return id +} + func (pa *PlatformAdapterKook) QuitGroup(_ *MsgContext, groupID string) { channel, err := pa.IntentSession.ChannelView(ExtractKookChannelID(groupID)) if err != nil { @@ -653,19 +660,14 @@ func (pa *PlatformAdapterKook) QuitGroup(_ *MsgContext, groupID string) { } } -func (pa *PlatformAdapterKook) SetGroupCardName(groupID string, userID string, name string) { +func (pa *PlatformAdapterKook) SetGroupCardName(ctx *MsgContext, name string) { nick := &kook.GuildNickname{} - channel, err := pa.IntentSession.ChannelView(ExtractKookChannelID(groupID)) - if err != nil { - pa.Session.Parent.Logger.Errorf("获取Kook频道信息#%s时出错:%s", groupID, err.Error()) - return - } - nick.GuildID = channel.GuildID + nick.GuildID = ExtractKookGuildID(ctx.Group.GuildID) nick.Nickname = name - nick.UserID = ExtractKookUserID(userID) - err = pa.IntentSession.GuildNickname(nick) + nick.UserID = ExtractKookUserID(ctx.Player.UserID) + err := pa.IntentSession.GuildNickname(nick) if err != nil { - pa.Session.Parent.Logger.Errorf("修改Kook用户#%s在服务器#%s(来源频道#%s)的昵称时出错:%s", userID, channel.GuildID, groupID, err.Error()) + pa.Session.Parent.Logger.Errorf("修改Kook用户#%s在服务器#%s(来源频道#%s)的昵称时出错:%s", ctx.Player.UserID, ctx.Group.GuildID, ctx.Group.GroupID, err.Error()) return } } diff --git a/dice/platform_adapter_minecraft.go b/dice/platform_adapter_minecraft.go index 30c15801..bee24f7a 100644 --- a/dice/platform_adapter_minecraft.go +++ b/dice/platform_adapter_minecraft.go @@ -256,4 +256,4 @@ func (pa *PlatformAdapterMinecraft) MemberKick(_ string, _ string) {} func (pa *PlatformAdapterMinecraft) QuitGroup(_ *MsgContext, _ string) {} -func (pa *PlatformAdapterMinecraft) SetGroupCardName(_ string, _ string, _ string) {} +func (pa *PlatformAdapterMinecraft) SetGroupCardName(_ *MsgContext, _ string) {} diff --git a/dice/platform_adapter_red.go b/dice/platform_adapter_red.go index a9333f21..955d845d 100644 --- a/dice/platform_adapter_red.go +++ b/dice/platform_adapter_red.go @@ -627,7 +627,7 @@ func (pa *PlatformAdapterRed) mustExtractId(id string) (int64, RedChatType) { return 0, 0 } -func (pa *PlatformAdapterRed) SetGroupCardName(groupId string, userId string, name string) { +func (pa *PlatformAdapterRed) SetGroupCardName(ctx *MsgContext, name string) { log := pa.Session.Parent.Logger log.Warn("red: 尚未实现该功能") } diff --git a/dice/platform_adapter_telegram.go b/dice/platform_adapter_telegram.go index 8fa4175f..7393decf 100644 --- a/dice/platform_adapter_telegram.go +++ b/dice/platform_adapter_telegram.go @@ -496,4 +496,4 @@ func (pa *PlatformAdapterTelegram) QuitGroup(_ *MsgContext, id string) { } // SetGroupCardName 没有这个接口 不实现 -func (pa *PlatformAdapterTelegram) SetGroupCardName(_ string, _ string, _ string) {} +func (pa *PlatformAdapterTelegram) SetGroupCardName(_ *MsgContext, _ string) {} diff --git a/dice/platform_adapter_walleq.go b/dice/platform_adapter_walleq.go index f0baa7c9..028abf05 100644 --- a/dice/platform_adapter_walleq.go +++ b/dice/platform_adapter_walleq.go @@ -904,7 +904,7 @@ func (pa *PlatformAdapterWalleQ) QuitGroup(_ *MsgContext, id string) { socketSendText(pa.Socket, string(a)) } -func (pa *PlatformAdapterWalleQ) SetGroupCardName(_ string, _ string, _ string) { +func (pa *PlatformAdapterWalleQ) SetGroupCardName(_ *MsgContext, _ string) { // wq 暂无该扩展 api }