forked from carrydela/mygoTgChanBot
修复反斜杠转;代码格式
This commit is contained in:
@@ -453,56 +453,10 @@ func (b *Bot) handleConfirmCallback(c tele.Context, userID int64, action string)
|
||||
return c.Respond(&tele.CallbackResponse{Text: "添加成功"})
|
||||
}
|
||||
|
||||
// sendMessageCopy 复制消息内容发送(非转发,可编辑)
|
||||
// sendMessageCopy 复制消息内容发送(使用 copyMessage API 保留原格式)
|
||||
func (b *Bot) sendMessageCopy(to *tele.Chat, msg *tele.Message) (*tele.Message, error) {
|
||||
// 图片
|
||||
if msg.Photo != nil {
|
||||
photo := &tele.Photo{File: msg.Photo.File, Caption: msg.Caption}
|
||||
return b.bot.Send(to, photo, tele.ModeHTML)
|
||||
}
|
||||
|
||||
// 视频
|
||||
if msg.Video != nil {
|
||||
video := &tele.Video{File: msg.Video.File, Caption: msg.Caption}
|
||||
return b.bot.Send(to, video, tele.ModeHTML)
|
||||
}
|
||||
|
||||
// 文档
|
||||
if msg.Document != nil {
|
||||
doc := &tele.Document{File: msg.Document.File, Caption: msg.Caption}
|
||||
return b.bot.Send(to, doc, tele.ModeHTML)
|
||||
}
|
||||
|
||||
// 音频
|
||||
if msg.Audio != nil {
|
||||
audio := &tele.Audio{File: msg.Audio.File, Caption: msg.Caption}
|
||||
return b.bot.Send(to, audio, tele.ModeHTML)
|
||||
}
|
||||
|
||||
// 语音
|
||||
if msg.Voice != nil {
|
||||
voice := &tele.Voice{File: msg.Voice.File}
|
||||
return b.bot.Send(to, voice)
|
||||
}
|
||||
|
||||
// 贴纸
|
||||
if msg.Sticker != nil {
|
||||
sticker := &tele.Sticker{File: msg.Sticker.File}
|
||||
return b.bot.Send(to, sticker)
|
||||
}
|
||||
|
||||
// 动图
|
||||
if msg.Animation != nil {
|
||||
anim := &tele.Animation{File: msg.Animation.File, Caption: msg.Caption}
|
||||
return b.bot.Send(to, anim, tele.ModeHTML)
|
||||
}
|
||||
|
||||
// 纯文本
|
||||
if msg.Text != "" {
|
||||
return b.bot.Send(to, msg.Text, tele.ModeHTML, tele.NoPreview)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("不支持的消息类型")
|
||||
// 使用 Copy 方法,完整保留原消息的 entities(代码块、粗体、斜体等格式)
|
||||
return b.bot.Copy(to, msg)
|
||||
}
|
||||
|
||||
// sendAlbumCopy 复制相册发送到频道,返回第一条消息
|
||||
@@ -511,30 +465,14 @@ func (b *Bot) sendAlbumCopy(to *tele.Chat, msgs []*tele.Message) (*tele.Message,
|
||||
return nil, fmt.Errorf("相册为空")
|
||||
}
|
||||
|
||||
var album tele.Album
|
||||
// 转换为 Editable 接口切片
|
||||
editables := make([]tele.Editable, len(msgs))
|
||||
for i, msg := range msgs {
|
||||
var caption string
|
||||
if i == 0 {
|
||||
// 只有第一条消息带 caption
|
||||
caption = msg.Caption
|
||||
}
|
||||
|
||||
if msg.Photo != nil {
|
||||
album = append(album, &tele.Photo{File: msg.Photo.File, Caption: caption})
|
||||
} else if msg.Video != nil {
|
||||
album = append(album, &tele.Video{File: msg.Video.File, Caption: caption})
|
||||
} else if msg.Document != nil {
|
||||
album = append(album, &tele.Document{File: msg.Document.File, Caption: caption})
|
||||
} else if msg.Audio != nil {
|
||||
album = append(album, &tele.Audio{File: msg.Audio.File, Caption: caption})
|
||||
}
|
||||
editables[i] = msg
|
||||
}
|
||||
|
||||
if len(album) == 0 {
|
||||
return nil, fmt.Errorf("相册中没有支持的媒体类型")
|
||||
}
|
||||
|
||||
sentMsgs, err := b.bot.SendAlbum(to, album, tele.ModeHTML)
|
||||
// 使用 CopyMany 保留原格式(代码块、粗体等 entities)
|
||||
sentMsgs, err := b.bot.CopyMany(to, editables)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user