mirror of
https://github.com/tucnak/telebot
synced 2024-11-15 06:13:01 +00:00
media: implement SetCaption in Album
This commit is contained in:
parent
cb88a11861
commit
260a67b811
18
media.go
18
media.go
@ -45,6 +45,24 @@ type Inputtable interface {
|
||||
// Album lets you group multiple media into a single message.
|
||||
type Album []Inputtable
|
||||
|
||||
func (a Album) SetCaption(caption string) {
|
||||
if len(a) < 1 {
|
||||
return
|
||||
}
|
||||
switch a[0].MediaType() {
|
||||
case "audio":
|
||||
a[0].(*Audio).Caption = caption
|
||||
case "video":
|
||||
a[0].(*Video).Caption = caption
|
||||
case "document":
|
||||
a[0].(*Document).Caption = caption
|
||||
case "photo":
|
||||
a[0].(*Photo).Caption = caption
|
||||
case "animation":
|
||||
a[0].(*Animation).Caption = caption
|
||||
}
|
||||
}
|
||||
|
||||
// Photo object represents a single photo file.
|
||||
type Photo struct {
|
||||
File
|
||||
|
43
media_test.go
Normal file
43
media_test.go
Normal file
@ -0,0 +1,43 @@
|
||||
package telebot
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAlbumSetCaption(t *testing.T) {
|
||||
var a Album
|
||||
a = append(a, &Photo{Caption: "wrong_caption"})
|
||||
a = append(a, &Photo{Caption: "t"})
|
||||
a.SetCaption("correct_caption")
|
||||
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
|
||||
assert.Equal(t, "t", a[1].InputMedia().Caption)
|
||||
|
||||
a = Album{}
|
||||
a = append(a, &Animation{Caption: "wrong_caption"})
|
||||
a = append(a, &Photo{Caption: "t"})
|
||||
a.SetCaption("correct_caption")
|
||||
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
|
||||
assert.Equal(t, "t", a[1].InputMedia().Caption)
|
||||
|
||||
a = Album{}
|
||||
a = append(a, &Audio{Caption: "wrong_caption"})
|
||||
a = append(a, &Photo{Caption: "t"})
|
||||
a.SetCaption("correct_caption")
|
||||
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
|
||||
assert.Equal(t, "t", a[1].InputMedia().Caption)
|
||||
|
||||
a = Album{}
|
||||
a = append(a, &Document{Caption: "wrong_caption"})
|
||||
a = append(a, &Photo{Caption: "t"})
|
||||
a.SetCaption("correct_caption")
|
||||
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
|
||||
assert.Equal(t, "t", a[1].InputMedia().Caption)
|
||||
|
||||
a = Album{}
|
||||
a = append(a, &Video{Caption: "wrong_caption"})
|
||||
a = append(a, &Photo{Caption: "t"})
|
||||
a.SetCaption("correct_caption")
|
||||
assert.Equal(t, "correct_caption", a[0].InputMedia().Caption)
|
||||
assert.Equal(t, "t", a[1].InputMedia().Caption)
|
||||
}
|
Loading…
Reference in New Issue
Block a user