diff options
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index be48497..4de55c6 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -303,15 +303,17 @@ func (c *Client) formatContent(file *client.File, filename string) string { } return fmt.Sprintf( - "%s (%v kbytes) | %s/%s%s", + "%s (%v kbytes) | %s", filename, file.Size/1024, - c.content.Link, - fmt.Sprintf("%x", sha256.Sum256([]byte(file.Remote.Id))), - filepath.Ext(filename), + c.formatFilePath(c.content.Link, file.Remote.Id, filepath.Ext(file.Local.Path)), ) } +func (c *Client) formatFilePath(basedir string, id string, ext string) string { + return fmt.Sprintf("%s/%x%s", basedir, sha256.Sum256([]byte(id)), ext) +} + func (c *Client) formatRestrict(ban bool, hours int64) client.ChatMemberStatus { var until int32 if hours != 0 { @@ -453,13 +455,13 @@ func (c *Client) contentToFilename(content client.MessageContent) (*client.File, return nil, "" case client.TypeMessageAudio: audio, _ := content.(*client.MessageAudio) - return audio.Audio.Audio, audio.Audio.FileName + return audio.Audio.Audio, filepath.Base(audio.Audio.Audio.Local.Path) case client.TypeMessageVideo: video, _ := content.(*client.MessageVideo) - return video.Video.Video, video.Video.FileName + return video.Video.Video, filepath.Base(video.Video.Video.Local.Path) case client.TypeMessageDocument: document, _ := content.(*client.MessageDocument) - return document.Document.Document, document.Document.FileName + return document.Document.Document, filepath.Base(document.Document.Document.Local.Path) } return nil, "" |