fix: issues

This commit is contained in:
Rogee
2024-09-02 23:39:22 +08:00
parent d3806983a4
commit e953d41e7a
10 changed files with 123 additions and 39 deletions

View File

@@ -3,7 +3,10 @@ package internal
import (
"encoding/json"
"fmt"
"strings"
"time"
"github.com/samber/lo"
)
type ChannelMessage struct {
@@ -15,10 +18,23 @@ type ChannelMessage struct {
}
type ChannelMessageMedia struct {
Photo string
Video string
Document string
WebPage ChannelMessageMediaWebPage
Photo *string
Video *string
Document *ChannelMessageDocument
WebPage *ChannelMessageMediaWebPage
}
type ChannelMessageDocument struct {
Ext string
Filename string
MimeType string
Size int64
Video *ChannelMessageDocumentVideo
}
type ChannelMessageDocumentVideo struct {
Duration float64
Width int
Height int
}
type ChannelMessageMediaWebPage struct {
@@ -41,22 +57,28 @@ func (c *ChannelMessage) WithMessage(message string) *ChannelMessage {
}
func (c *ChannelMessage) WithPhoto(assetID int64, ext string) *ChannelMessage {
c.Medias = append(c.Medias, ChannelMessageMedia{Photo: fmt.Sprintf("%d.%s", assetID, ext)})
c.Medias = append(c.Medias, ChannelMessageMedia{
Photo: lo.ToPtr(fmt.Sprintf("%d.%s", assetID, strings.Trim(ext, "."))),
})
return c
}
func (c *ChannelMessage) WithVideo(video string) *ChannelMessage {
c.Medias = append(c.Medias, ChannelMessageMedia{Video: video})
c.Medias = append(c.Medias, ChannelMessageMedia{Video: lo.ToPtr(video)})
return c
}
func (c *ChannelMessage) WithDoc(docID int64, ext string) *ChannelMessage {
c.Medias = append(c.Medias, ChannelMessageMedia{Document: fmt.Sprintf("%d.%s", docID, ext)})
func (c *ChannelMessage) WithDocument(d ChannelMessageDocument) *ChannelMessage {
c.Medias = append(c.Medias, ChannelMessageMedia{
Document: lo.ToPtr(d),
})
return c
}
func (c *ChannelMessage) WithWebPage(title, url string) *ChannelMessage {
c.Medias = append(c.Medias, ChannelMessageMedia{WebPage: ChannelMessageMediaWebPage{Title: title, URL: url}})
c.Medias = append(c.Medias, ChannelMessageMedia{
WebPage: lo.ToPtr(ChannelMessageMediaWebPage{Title: title, URL: url}),
})
return c
}