Skip to content

Commit

Permalink
Updated types to Telegram Bot API v6.6
Browse files Browse the repository at this point in the history
  • Loading branch information
mymmrac committed Mar 13, 2023
1 parent 56ca62a commit 5a47f5e
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 258 deletions.
6 changes: 4 additions & 2 deletions internal/generator/setters_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ import (
data.WriteString(fmt.Sprintf("\tassert.Equal(t, %s%s{\n", pointer, currentStruct))

for _, s := range currentSetters {
if s.value == " true" {
s.value = "ToPtr(true)"
if strings.HasPrefix(s.value, " ") {
s.value = "ToPtr(" + s.value + ")"
}

data.WriteString(fmt.Sprintf("\t\t%s: %s,\n", s.name, s.value))
Expand Down Expand Up @@ -101,6 +101,8 @@ func parseSetterType(setter tgSetter, counter *int) string {
return " true"
case "string":
return "\"" + setter.fieldName + "\""
case "*string":
return " \"" + setter.fieldName + "\""
case "int":
*counter++
return fmt.Sprintf("%d", *counter)
Expand Down
2 changes: 1 addition & 1 deletion internal/generator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func parseCurrentTypes(types string) map[string][]string {
break
}

if !strings.HasPrefix(lines[start], "// ") {
if !strings.HasPrefix(lines[start], "//") {
break
}
}
Expand Down
16 changes: 8 additions & 8 deletions methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2647,7 +2647,7 @@ func TestBot_DeleteStickerFromSet(t *testing.T) {
})
}

func TestBot_SetStickerSetThumb(t *testing.T) {
func TestBot_SetStickerSetThumbnail(t *testing.T) {
ctrl := gomock.NewController(t)
m := newMockedBot(ctrl)

Expand Down Expand Up @@ -3064,12 +3064,12 @@ func TestSendMediaGroupParams_fileParameters(t *testing.T) {
p := &SendMediaGroupParams{
Media: []InputMedia{
&InputMediaDocument{
Media: testInputFile,
Thumb: &testInputFile,
Media: testInputFile,
Thumbnail: &testInputFile,
},
&InputMediaVideo{
Media: testInputFile,
Thumb: &InputFile{File: nil},
Media: testInputFile,
Thumbnail: &InputFile{File: nil},
},
},
}
Expand All @@ -3092,8 +3092,8 @@ func TestSetChatPhotoParams_fileParameters(t *testing.T) {
func TestEditMessageMediaParams_fileParameters(t *testing.T) {
p := &EditMessageMediaParams{
Media: &InputMediaVideo{
Media: testInputFile,
Thumb: &InputFile{File: nil},
Media: testInputFile,
Thumbnail: &InputFile{File: nil},
},
}

Expand Down Expand Up @@ -3150,7 +3150,7 @@ func TestAddStickerToSetParams_fileParameters(t *testing.T) {
}, p.fileParameters())
}

func TestSetStickerSetThumbParams_fileParameters(t *testing.T) {
func TestSetStickerSetThumbnailParams_fileParameters(t *testing.T) {
p := &SetStickerSetThumbParams{
Thumb: &testInputFile,
}
Expand Down
44 changes: 22 additions & 22 deletions telegoutil/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,12 @@ func ResultDocument(id, title, documentURL, mimeType string) *telego.InlineQuery
}

// ResultGif creates telego.InlineQueryResultGif with required fields
func ResultGif(id, gifURL, thumbURL string) *telego.InlineQueryResultGif {
func ResultGif(id, gifURL, thumbnailURL string) *telego.InlineQueryResultGif {
return &telego.InlineQueryResultGif{
Type: telego.ResultTypeGif,
ID: id,
GifURL: gifURL,
ThumbURL: thumbURL,
Type: telego.ResultTypeGif,
ID: id,
GifURL: gifURL,
ThumbnailURL: thumbnailURL,
}
}

Expand All @@ -259,22 +259,22 @@ func ResultLocation(id string, latitude, longitude float64, title string) *teleg
}

// ResultMpeg4Gif creates telego.InlineQueryResultMpeg4Gif with required fields
func ResultMpeg4Gif(id, mpeg4URL, thumbURL string) *telego.InlineQueryResultMpeg4Gif {
func ResultMpeg4Gif(id, mpeg4URL, thumbnailURL string) *telego.InlineQueryResultMpeg4Gif {
return &telego.InlineQueryResultMpeg4Gif{
Type: telego.ResultTypeMpeg4Gif,
ID: id,
Mpeg4URL: mpeg4URL,
ThumbURL: thumbURL,
Type: telego.ResultTypeMpeg4Gif,
ID: id,
Mpeg4URL: mpeg4URL,
ThumbnailURL: thumbnailURL,
}
}

// ResultPhoto creates telego.InlineQueryResultPhoto with required fields
func ResultPhoto(id, photoURL, thumbURL string) *telego.InlineQueryResultPhoto {
func ResultPhoto(id, photoURL, thumbnailURL string) *telego.InlineQueryResultPhoto {
return &telego.InlineQueryResultPhoto{
Type: telego.ResultTypePhoto,
ID: id,
PhotoURL: photoURL,
ThumbURL: thumbURL,
Type: telego.ResultTypePhoto,
ID: id,
PhotoURL: photoURL,
ThumbnailURL: thumbnailURL,
}
}

Expand All @@ -292,14 +292,14 @@ func ResultVenue(id string, latitude, longitude float64, title, address string,
}

// ResultVideo creates telego.InlineQueryResultVideo with required fields
func ResultVideo(id, videoURL, mimeType, thumbURL, title string) *telego.InlineQueryResultVideo {
func ResultVideo(id, videoURL, mimeType, thumbnailURL, title string) *telego.InlineQueryResultVideo {
return &telego.InlineQueryResultVideo{
Type: telego.ResultTypeVideo,
ID: id,
VideoURL: videoURL,
MimeType: mimeType,
ThumbURL: thumbURL,
Title: title,
Type: telego.ResultTypeVideo,
ID: id,
VideoURL: videoURL,
MimeType: mimeType,
ThumbnailURL: thumbnailURL,
Title: title,
}
}

Expand Down
8 changes: 4 additions & 4 deletions telegoutil/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func TestResultGif(t *testing.T) {
assert.Equal(t, telego.ResultTypeGif, r.Type)
assert.Equal(t, text1, r.ID)
assert.Equal(t, text2, r.GifURL)
assert.Equal(t, text3, r.ThumbURL)
assert.Equal(t, text3, r.ThumbnailURL)
}

func TestResultLocation(t *testing.T) {
Expand All @@ -324,15 +324,15 @@ func TestResultMpeg4Gif(t *testing.T) {
assert.Equal(t, telego.ResultTypeMpeg4Gif, r.Type)
assert.Equal(t, text1, r.ID)
assert.Equal(t, text2, r.Mpeg4URL)
assert.Equal(t, text3, r.ThumbURL)
assert.Equal(t, text3, r.ThumbnailURL)
}

func TestResultPhoto(t *testing.T) {
r := ResultPhoto(text1, text2, text3)
assert.Equal(t, telego.ResultTypePhoto, r.Type)
assert.Equal(t, text1, r.ID)
assert.Equal(t, text2, r.PhotoURL)
assert.Equal(t, text3, r.ThumbURL)
assert.Equal(t, text3, r.ThumbnailURL)
}

func TestResultVenue(t *testing.T) {
Expand All @@ -351,7 +351,7 @@ func TestResultVideo(t *testing.T) {
assert.Equal(t, text1, r.ID)
assert.Equal(t, text2, r.VideoURL)
assert.Equal(t, text3, r.MimeType)
assert.Equal(t, text4, r.ThumbURL)
assert.Equal(t, text4, r.ThumbnailURL)
assert.Equal(t, text5, r.Title)
}

Expand Down
Loading

0 comments on commit 5a47f5e

Please sign in to comment.