Skip to content

Commit

Permalink
Beta90 (#241)
Browse files Browse the repository at this point in the history
* beta88

* beta89

* bugfix

* beta90
  • Loading branch information
Hoshinonyaruko authored Dec 14, 2023
1 parent ab26fcb commit 0cdb914
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
}
//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//储存原来的(获取群列表需要)
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//转换at和图片
messageText := handlers.RevertTransformedText(data, "guild", p.Api, p.Apiv2, ChannelID64)
if messageText == "" {
Expand Down
2 changes: 2 additions & 0 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
}
//转成int再互转
idmap.WriteConfigv2(fmt.Sprint(ChannelID64), "guild_id", data.GuildID)
//储存原来的(获取群列表需要)
idmap.WriteConfigv2(data.ChannelID, "guild_id", data.GuildID)
//转换at
messageText := handlers.RevertTransformedText(data, "guild", p.Api, p.Apiv2, ChannelID64)
if messageText == "" {
Expand Down
35 changes: 33 additions & 2 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,12 @@ func HandleSendGuildChannelPrivateMsg(client callapi.Client, api openapi.OpenAPI
//频道私信 转 私信 通过userid(author_id)来还原频道私信需要的guildid channelID
guildID, channelID, err = getGuildIDFromMessage(message)
if err != nil {
mylog.Printf("获取 guild_id 和 channel_id 出错: %v", err)
return "", nil
mylog.Printf("获取 guild_id 和 channel_id 出错,进行重试: %v", err)
guildID, channelID, err = getGuildIDFromMessagev2(message)
if err != nil {
mylog.Printf("获取 guild_id 和 channel_id 出错,重试失败: %v", err)
return "", nil
}
}
//频道私信 转 私信
if GroupID != "" && config.GetIdmapPro() {
Expand Down Expand Up @@ -538,6 +542,33 @@ func getGuildIDFromMessage(message callapi.ActionMessage) (string, string, error
return guildID, channelID, nil
}

// 这个函数可以通过int类型的虚拟groupid反推真实的guild_id和channel_id
func getGuildIDFromMessagev2(message callapi.ActionMessage) (string, string, error) {
var GroupID string
//groupID此时是转换后的channelid

// 判断UserID的类型,并将其转换为string
switch v := message.Params.GroupID.(type) {
case int:
GroupID = strconv.Itoa(v)
case float64:
GroupID = strconv.FormatInt(int64(v), 10) // 将float64先转为int64,然后再转为string
case string:
GroupID = v
default:
return "", "", fmt.Errorf("unexpected type for UserID: %T", v) // 使用%T来打印具体的类型
}

var err error
//使用channelID作为sectionName从数据库中获取guild_id
guildID, err := idmap.ReadConfigv2(GroupID, "guild_id")
if err != nil {
return "", "", fmt.Errorf("error reading guild_id: %v", err)
}

return guildID, GroupID, nil
}

// uploadMedia 上传媒体并返回FileInfo
func uploadMediaPrivate(ctx context.Context, UserID string, richMediaMessage *dto.RichMediaMessage, apiv2 openapi.OpenAPI) (string, error) {
// 调用API来上传媒体
Expand Down

0 comments on commit 0cdb914

Please sign in to comment.